metrics: add a NewSet and Set.NewLabelMap helpers

Updates tailscale/corp#31174

Signed-off-by: Anton Tolchanov <anton@tailscale.com>
This commit is contained in:
Anton Tolchanov
2026-01-13 11:43:03 -05:00
committed by Anton Tolchanov
parent 17b0c7bfb3
commit 58042e2de3
2 changed files with 18 additions and 10 deletions
+15
View File
@@ -29,6 +29,21 @@ type Set struct {
expvar.Map
}
// NewSet creates and publishes a new Set with the given name.
func NewSet(name string) *Set {
s := &Set{}
expvar.Publish(name, s)
return s
}
// NewLabelMap creates a new LabelMap metric with the given
// metric name and label name, and adds it to the Set.
func (s *Set) NewLabelMap(metric, label string) *LabelMap {
m := &LabelMap{Label: label}
s.Set(metric, m)
return m
}
// LabelMap is a string-to-Var map variable that satisfies the
// expvar.Var interface.
//