Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmd/mdatagen] Add unit test for metric collisions. #24229

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions cmd/mdatagen/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
package main

import (
"fmt"
"io/fs"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -101,3 +105,34 @@ func TestValidate(t *testing.T) {
})
}
}

func TestMetricCollision(t *testing.T) {
allMetrics := map[string][]string{}
err := filepath.Walk("../../receiver", func(path string, info fs.FileInfo, err error) error {
if info.Name() == "metadata.yaml" {
md, err := loadMetadata(path)
assert.NoError(t, err)
if len(md.Metrics) > 0 {
for metricName := range md.Metrics {
allMetrics[md.Type] = append(allMetrics[md.Type], string(metricName))
}
}
}
return nil
})
assert.NoError(t, err)

seen := make(map[string]string)
for receiver, metrics := range allMetrics {
for _, metricName := range metrics {
// TODO: Remove one https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/24009 and
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/24008 have been addressed.
if metricName == "container.cpu.utilization" || metricName == "container.memory.rss" {
continue
}
val, exists := seen[metricName]
assert.False(t, exists, fmt.Sprintf("Collision for metric %v in receivers %v and %v \n", metricName, receiver, val))
seen[metricName] = receiver
}
}
Comment on lines +125 to +137
Copy link
Member

@dmitryax dmitryax Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we ever decided that each receiver must emit unique metric names. I'd say we should remove this section until this decision is made.

}