Skip to content

Commit

Permalink
[OTEL-2361] Fix metric origin mappings from OTel collector receiver i…
Browse files Browse the repository at this point in the history
…nstrumentation scope (#466)

* [OTEL-2361] Fix metric origin mappings from OTel collector receiver instrumentation scope

* Update .chloggen/fix-metric-origin.yaml
  • Loading branch information
songy23 authored Jan 17, 2025
1 parent 36ce209 commit 3aaff86
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
16 changes: 16 additions & 0 deletions .chloggen/fix-metric-origin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'bug_fix'

# The name of the component (e.g. pkg/quantile)
component: pkg/otlp/metrics

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Fix metric origin mappings from OTel collector receiver instrumentation scope"

# The PR related to this change
issues: [466]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
8 changes: 4 additions & 4 deletions pkg/otlp/metrics/origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ const (
)

func originProductDetailFromScopeName(scopeName string) OriginProductDetail {
const collectorPrefix = "otelcol/"
const collectorPrefix = "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/"
if !strings.HasPrefix(scopeName, collectorPrefix) {
return OriginProductDetailUnknown
}

// otelcol/kubeletstatsreceiver -> kubeletstatsreceiver
// otelcol/hostmetricsreceiver/disk -> hostmetricsreceiver
receiverName := strings.Split(scopeName, "/")[1]
// github.com/open-telemetry/opentelemetry-collector-contrib/receiver/kubeletstatsreceiver -> kubeletstatsreceiver
// github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/disk -> hostmetricsreceiver
receiverName := strings.Split(scopeName, "/")[4]

// otelcol
switch receiverName {
Expand Down
8 changes: 6 additions & 2 deletions pkg/otlp/metrics/origin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ func TestOriginProductDetailFromScopeName(t *testing.T) {
expected OriginProductDetail
}{
{
scopeName: "otelcol/notsupportedreceiver",
scopeName: "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/notsupportedreceiver",
expected: OriginProductDetailUnknown,
},
{
scopeName: "otelcol/kubeletstatsreceiver",
expected: OriginProductDetailUnknown,
},
{
scopeName: "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/kubeletstatsreceiver",
expected: OriginProductDetailKubeletStatsReceiver,
},
{
scopeName: "otelcol/hostmetricsreceiver/memory",
scopeName: "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/memory",
expected: OriginProductDetailHostMetricsReceiver,
},
{
Expand Down
6 changes: 3 additions & 3 deletions pkg/otlp/metrics/testdata/otlpdata/origin/origin.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"scopeMetrics": [
{
"scope": {
"name": "otelcol/unknownreceiver",
"name": "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/unknownreceiver",
"version": "0.91.0"
},
"metrics": [
Expand All @@ -34,7 +34,7 @@
},
{
"scope": {
"name": "otelcol/hostmetricsreceiver/memory",
"name": "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/memory",
"version": "1.0.0"
},
"metrics": [
Expand All @@ -54,7 +54,7 @@
},
{
"scope": {
"name": "otelcol/prometheusreceiver",
"name": "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver",
"version": "0.91.0"
},
"metrics": [
Expand Down

0 comments on commit 3aaff86

Please sign in to comment.