Chore: Ignore duplicate process_* metrics in MultiRegistry (#97857)
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user