diff --git a/api/metrics/multi_gatherer.go b/api/metrics/multi_gatherer.go index eb3576680f3..bbb8a9c9c65 100644 --- a/api/metrics/multi_gatherer.go +++ b/api/metrics/multi_gatherer.go @@ -16,9 +16,9 @@ import ( ) var ( - errDuplicatedPrefix = errors.New("duplicated prefix") - _ MultiGatherer = (*multiGatherer)(nil) + + errReregisterGatherer = errors.New("attempt to register existing gatherer") ) // MultiGatherer extends the Gatherer interface by allowing additional gatherers @@ -77,8 +77,8 @@ func (g *multiGatherer) Register(namespace string, gatherer prometheus.Gatherer) g.lock.Lock() defer g.lock.Unlock() - if _, exists := g.gatherers[namespace]; exists { - return errDuplicatedPrefix + if existingGatherer, exists := g.gatherers[namespace]; exists { + return fmt.Errorf("%w for namespace %q failed; existing: %#v", errReregisterGatherer, namespace, existingGatherer) } g.gatherers[namespace] = gatherer diff --git a/api/metrics/multi_gatherer_test.go b/api/metrics/multi_gatherer_test.go index 07c6c4391c3..a2e59a90d51 100644 --- a/api/metrics/multi_gatherer_test.go +++ b/api/metrics/multi_gatherer_test.go @@ -30,7 +30,7 @@ func TestMultiGathererDuplicatedPrefix(t *testing.T) { require.NoError(g.Register("", og)) err := g.Register("", og) - require.ErrorIs(err, errDuplicatedPrefix) + require.ErrorIs(err, errReregisterGatherer) require.NoError(g.Register("lol", og)) } diff --git a/api/metrics/optional_gatherer.go b/api/metrics/optional_gatherer.go index 4d917dfbb9a..1a8e8e0f8a1 100644 --- a/api/metrics/optional_gatherer.go +++ b/api/metrics/optional_gatherer.go @@ -4,7 +4,7 @@ package metrics import ( - "errors" + "fmt" "sync" "github.com/prometheus/client_golang/prometheus" @@ -12,11 +12,7 @@ import ( dto "github.com/prometheus/client_model/go" ) -var ( - errDuplicatedRegister = errors.New("duplicated register") - - _ OptionalGatherer = (*optionalGatherer)(nil) -) +var _ OptionalGatherer = (*optionalGatherer)(nil) // OptionalGatherer extends the Gatherer interface by allowing the optional // registration of a single gatherer. If no gatherer is registered, Gather will @@ -54,7 +50,7 @@ func (g *optionalGatherer) Register(gatherer prometheus.Gatherer) error { defer g.lock.Unlock() if g.gatherer != nil { - return errDuplicatedRegister + return fmt.Errorf("%w; %#v", errReregisterGatherer, g.gatherer) } g.gatherer = gatherer return nil diff --git a/api/metrics/optional_gatherer_test.go b/api/metrics/optional_gatherer_test.go index 45edfaca9a8..887029a3572 100644 --- a/api/metrics/optional_gatherer_test.go +++ b/api/metrics/optional_gatherer_test.go @@ -32,7 +32,7 @@ func TestOptionalGathererDuplicated(t *testing.T) { require.NoError(g.Register(og)) err := g.Register(og) - require.ErrorIs(err, errDuplicatedRegister) + require.ErrorIs(err, errReregisterGatherer) } func TestOptionalGathererAddedError(t *testing.T) {