Skip to content

Commit

Permalink
Chore: Ignore duplicate process_* metrics in MultiRegistry (grafana#9…
Browse files Browse the repository at this point in the history
  • Loading branch information
toddtreece authored Dec 12, 2024
1 parent 63d3cf9 commit 6c8c0ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/infra/metrics/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ func (r *multiRegistry) Gather() (mfs []*dto.MetricFamily, err error) {
_, exists := names[*m.Name]
// prevent duplicate metric names
if exists {
// we can skip go_ metrics without returning an error
// we can skip go_ and process_ metrics without returning an error
// because they are known to be duplicates in both
// the k8s and prometheus gatherers.
if strings.HasPrefix(*m.Name, "go_") {
if strings.HasPrefix(*m.Name, "go_") || strings.HasPrefix(*m.Name, "process_") {
continue
}
errs = append(errs, fmt.Errorf("duplicate metric name: %s", *m.Name))
Expand Down
5 changes: 4 additions & 1 deletion pkg/infra/metrics/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ func TestMultiRegistry_Gather(t *testing.T) {
require.Error(t, err)
})

t.Run("duplicate go_ prefixed metrics do not result in an error", func(t *testing.T) {
t.Run("duplicate go_ or process_ prefixed metrics do not result in an error", func(t *testing.T) {
one.GatherFunc = func() ([]*dto.MetricFamily, error) {
return []*dto.MetricFamily{
{Name: strptr("b")},
{Name: strptr("a")},
{Name: strptr("go_a")},
{Name: strptr("process_a")},
}, nil
}

Expand All @@ -113,6 +114,7 @@ func TestMultiRegistry_Gather(t *testing.T) {
{Name: strptr("d")},
{Name: strptr("c")},
{Name: strptr("go_a")},
{Name: strptr("process_a")},
}, nil
}

Expand All @@ -122,6 +124,7 @@ func TestMultiRegistry_Gather(t *testing.T) {
{Name: strptr("c")},
{Name: strptr("d")},
{Name: strptr("go_a")},
{Name: strptr("process_a")},
}

mf, err := g.Gather()
Expand Down

0 comments on commit 6c8c0ab

Please sign in to comment.