metrics: add a NewLabelMap helper to create and register label maps

Updates tailscale/corp#31174

Signed-off-by: Anton Tolchanov <anton@tailscale.com>
This commit is contained in:
Anton Tolchanov
2026-01-12 15:09:04 -05:00
committed by Anton Tolchanov
parent 76fb09c6bd
commit 17b0c7bfb3
2 changed files with 10 additions and 7 deletions
+8
View File
@@ -43,6 +43,14 @@ type LabelMap struct {
shardedIntMu syncs.Mutex
}
// NewLabelMap creates and publishes a new LabelMap metric with the given
// metric name and label name.
func NewLabelMap(metric, label string) *LabelMap {
m := &LabelMap{Label: label}
expvar.Publish(metric, m)
return m
}
// SetInt64 sets the *Int value stored under the given map key.
func (m *LabelMap) SetInt64(key string, v int64) {
m.Get(key).Set(v)