util/usermetric: add empty label helper

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
Kristoffer Dalby 2024-08-14 15:54:01 +02:00
parent 55d29a9c6d
commit fffc6a65b2
No known key found for this signature in database

View File

@ -33,6 +33,21 @@ func NewMultiLabelMap[T comparable](name string, promType, helpText string) *met
return m
}
// NewMap creates and register a new
// Map variable with the given name and returns it.
//
// Note that usermetric are not protected against duplicate
// metrics name. It is the caller's responsibility to ensure that
// the name is unique.
func NewMap(name string, promType, helpText string) *metrics.MultiLabelMap[struct{}] {
m := &metrics.MultiLabelMap[struct{}]{
Type: promType,
Help: helpText,
}
vars.Set(name, m)
return m
}
// Handler returns a varz.Handler that serves the userfacing expvar contained
// in this package.
func Handler(w http.ResponseWriter, r *http.Request) {