Repository navigation
[receiver/prometheusremotewrite] Align job label mapping with prometheusreceiver #52626
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
Merged
songy23
merged 4 commits into
open-telemetry:main
from
dashpole:fix-prometheusremotewrite-job
Nov 9, 2026
+272
−7
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7bbe356
receiver/prometheusremotewrite: conditionally preserve job label
dashpole eefe915
Fix failing unit tests
dashpole 683e733
Update receiver.prometheus_remote_write.disableJobSplit metadata and …
dashpole d9e8777
Address review comment: document job label mapping and migration guide
dashpole File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| change_type: enhancement | ||
| component: receiver/prometheus_remote_write | ||
| note: "Adds an alpha feature gate `receiver.prometheus_remote_write.disableJobSplit` to map the `job` label directly to `service.name` without splitting, aligning with the `prometheusreceiver`." | ||
| issues: [52626] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
receiver/prometheusremotewritereceiver/internal/metadata/generated_feature_gates.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 196 additions & 0 deletions
196
receiver/prometheusremotewritereceiver/receiver_feature_gate_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package prometheusremotewritereceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusremotewritereceiver" | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| writev2 "github.com/prometheus/prometheus/prompb/io/prometheus/write/v2" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "go.opentelemetry.io/collector/featuregate" | ||
| "go.opentelemetry.io/collector/pdata/pcommon" | ||
|
|
||
| "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusremotewritereceiver/internal/metadata" | ||
| ) | ||
|
|
||
| func setDisableJobSplitFeatureGate(t *testing.T, enabled bool) { | ||
| t.Helper() | ||
| t.Cleanup(func() { | ||
| assert.NoError(t, featuregate.GlobalRegistry().Set(metadata.ReceiverPrometheusRemoteWriteDisableJobSplitFeatureGate.ID(), false)) | ||
| }) | ||
| require.NoError(t, featuregate.GlobalRegistry().Set(metadata.ReceiverPrometheusRemoteWriteDisableJobSplitFeatureGate.ID(), enabled)) | ||
| } | ||
|
|
||
| func TestParseJobAndInstanceFeatureGate(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| gate bool | ||
| job string | ||
| instance string | ||
| expected map[string]any | ||
| }{ | ||
| { | ||
| name: "gate=false splits namespace/service", | ||
| gate: false, | ||
| job: "namespace/service", | ||
| instance: "instance-1", | ||
| expected: map[string]any{ | ||
| "service.instance.id": "instance-1", | ||
| "service.namespace": "namespace", | ||
| "service.name": "service", | ||
| }, | ||
| }, | ||
| { | ||
| name: "gate=true preserves namespace/service in service.name", | ||
| gate: true, | ||
| job: "namespace/service", | ||
| instance: "instance-1", | ||
| expected: map[string]any{ | ||
| "service.instance.id": "instance-1", | ||
| "service.name": "namespace/service", | ||
| }, | ||
| }, | ||
| { | ||
| name: "gate=false my-job", | ||
| gate: false, | ||
| job: "my-job", | ||
| instance: "instance-1", | ||
| expected: map[string]any{ | ||
| "service.instance.id": "instance-1", | ||
| "service.name": "my-job", | ||
| }, | ||
| }, | ||
| { | ||
| name: "gate=true my-job", | ||
| gate: true, | ||
| job: "my-job", | ||
| instance: "instance-1", | ||
| expected: map[string]any{ | ||
| "service.instance.id": "instance-1", | ||
| "service.name": "my-job", | ||
| }, | ||
| }, | ||
| { | ||
| name: "gate=false multiple slashes a/b/c", | ||
| gate: false, | ||
| job: "a/b/c", | ||
| instance: "instance-1", | ||
| expected: map[string]any{ | ||
| "service.instance.id": "instance-1", | ||
| "service.name": "a/b/c", | ||
| }, | ||
| }, | ||
| { | ||
| name: "gate=true multiple slashes a/b/c", | ||
| gate: true, | ||
| job: "a/b/c", | ||
| instance: "instance-1", | ||
| expected: map[string]any{ | ||
| "service.instance.id": "instance-1", | ||
| "service.name": "a/b/c", | ||
| }, | ||
| }, | ||
| { | ||
| name: "gate=false empty job", | ||
| gate: false, | ||
| job: "", | ||
| instance: "instance-1", | ||
| expected: map[string]any{ | ||
| "service.instance.id": "instance-1", | ||
| }, | ||
| }, | ||
| { | ||
| name: "gate=true empty job", | ||
| gate: true, | ||
| job: "", | ||
| instance: "instance-1", | ||
| expected: map[string]any{ | ||
| "service.instance.id": "instance-1", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| setDisableJobSplitFeatureGate(t, tc.gate) | ||
|
|
||
| dest := pcommon.NewMap() | ||
| parseJobAndInstance(dest, tc.job, tc.instance) | ||
| assert.Equal(t, tc.expected, dest.AsRaw()) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestTranslateV2DisableJobSplitFeatureGate(t *testing.T) { | ||
| setDisableJobSplitFeatureGate(t, true) | ||
|
|
||
| t.Run("without target_info keeps namespace/service in service.name", func(t *testing.T) { | ||
| prwReceiver := setupMetricsReceiver(t) | ||
| req := &writev2.Request{ | ||
| Symbols: []string{ | ||
| "", | ||
| "__name__", "test_metric", // 1, 2 | ||
| "instance", "host-1", // 3, 4 | ||
| "job", "namespace/service", // 5, 6 | ||
| }, | ||
| Timeseries: []writev2.TimeSeries{ | ||
| { | ||
| Metadata: writev2.Metadata{Type: writev2.Metadata_METRIC_TYPE_GAUGE}, | ||
| LabelsRefs: []uint32{1, 2, 3, 4, 5, 6}, | ||
| Samples: []writev2.Sample{{Value: 1, Timestamp: 1000}}, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| m, _, err := prwReceiver.translateV2(t.Context(), req) | ||
| require.NoError(t, err) | ||
| require.Equal(t, 1, m.ResourceMetrics().Len()) | ||
|
|
||
| resAttrs := m.ResourceMetrics().At(0).Resource().Attributes() | ||
| assert.Equal(t, map[string]any{ | ||
| "service.name": "namespace/service", | ||
| "service.instance.id": "host-1", | ||
| }, resAttrs.AsRaw()) | ||
| _, hasNamespace := resAttrs.Get("service.namespace") | ||
| assert.False(t, hasNamespace) | ||
| }) | ||
|
|
||
| t.Run("target_info service.name and service.namespace take precedence", func(t *testing.T) { | ||
| prwReceiver := setupMetricsReceiver(t) | ||
| req := &writev2.Request{ | ||
| Symbols: []string{ | ||
| "", | ||
| "__name__", "target_info", "test_metric", // 1, 2, 3 | ||
| "instance", "host-1", // 4, 5 | ||
| "job", "namespace/service", // 6, 7 | ||
| "service.name", "explicit-service", // 8, 9 | ||
| "service.namespace", "explicit-namespace", // 10, 11 | ||
| }, | ||
| Timeseries: []writev2.TimeSeries{ | ||
| { | ||
| Metadata: writev2.Metadata{Type: writev2.Metadata_METRIC_TYPE_GAUGE}, | ||
| LabelsRefs: []uint32{1, 2, 4, 5, 6, 7, 8, 9, 10, 11}, | ||
| Samples: []writev2.Sample{{Value: 1, Timestamp: 1000}}, | ||
| }, | ||
| { | ||
| Metadata: writev2.Metadata{Type: writev2.Metadata_METRIC_TYPE_GAUGE}, | ||
| LabelsRefs: []uint32{1, 3, 4, 5, 6, 7}, | ||
| Samples: []writev2.Sample{{Value: 42, Timestamp: 1000}}, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| m, _, err := prwReceiver.translateV2(t.Context(), req) | ||
| require.NoError(t, err) | ||
| require.Equal(t, 1, m.ResourceMetrics().Len()) | ||
|
|
||
| resAttrs := m.ResourceMetrics().At(0).Resource().Attributes() | ||
| assert.Equal(t, map[string]any{ | ||
| "service.name": "explicit-service", | ||
| "service.namespace": "explicit-namespace", | ||
| "service.instance.id": "host-1", | ||
| }, resAttrs.AsRaw()) | ||
| }) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.