From fffc6a65b2c1ef744f2a8bb81f091d6d0702b01a Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Wed, 14 Aug 2024 15:54:01 +0200 Subject: [PATCH] util/usermetric: add empty label helper Signed-off-by: Kristoffer Dalby --- util/usermetric/usermetric.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/util/usermetric/usermetric.go b/util/usermetric/usermetric.go index 208826186..75b7b900e 100644 --- a/util/usermetric/usermetric.go +++ b/util/usermetric/usermetric.go @@ -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) {