mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-18 02:48:40 +00:00
metrics: fix outdated docs on MultiLabelMap
And make NewMultiLabelMap panic earlier (at construction time) if the comparable struct type T violates the documented rules, rather than panicking at Add time. Updates #cleanup Change-Id: Ib1a03babdd501b8d699c4f18b1097a56c916c6d5 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
fe0cfec4ad
commit
9699bb0a20
@ -17,7 +17,7 @@ import (
|
||||
// [expvar.Var] interface but also allows for multiple Prometheus labels to be
|
||||
// associated with each value.
|
||||
//
|
||||
// T must be a struct type with only string fields. The struct field names
|
||||
// T must be a struct type with scalar fields. The struct field names
|
||||
// (lowercased) are used as the labels, unless a "prom" struct tag is present.
|
||||
// The struct fields must all be strings, and the string values must be valid
|
||||
// Prometheus label values without requiring quoting.
|
||||
@ -38,6 +38,8 @@ func NewMultiLabelMap[T comparable](name string, promType, helpText string) *Mul
|
||||
Type: promType,
|
||||
Help: helpText,
|
||||
}
|
||||
var zero T
|
||||
_ = labelString(zero) // panic early if T is invalid
|
||||
expvar.Publish(name, m)
|
||||
return m
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user