[pkg/translator/prometheusremotewrite] preserve multiple underscores when permissive sanitization is enabled - #49565
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aligns pkg/translator/prometheusremotewrite label-name handling with the intended behavior of the pkg.translator.prometheus.PermissiveLabelSanitization (DropSanitizationGate) feature gate by preserving consecutive underscores (e.g., a__b) when permissive sanitization is enabled.
Changes:
- Configure
otlptranslator.LabelNamerto setPreserveMultipleUnderscoreswhenDropSanitizationGateis enabled. - Add a unit test covering multiple-underscore behavior for gate enabled/disabled and reserved labels.
- Add module dependency needed for the new test helper and include a changelog entry.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/translator/prometheusremotewrite/metrics_to_prw.go | Updates the converter’s LabelNamer configuration to preserve consecutive underscores when the feature gate is enabled. |
| pkg/translator/prometheusremotewrite/labelnamer_underscore_test.go | Adds test coverage for multiple-underscore label behavior under the feature gate. |
| pkg/translator/prometheusremotewrite/go.mod | Adds the internal/common module dependency used by the new test helper. |
| .chloggen/prw-preserve-multiple-underscores.yaml | Adds a changelog entry for the bug fix in label sanitization behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Pull request dashboard statusMerged · refreshed 2026-08-05 08:32 UTC Status above doesn't look right?
|
38c7a23 to
c94750d
Compare
|
@s3onghyun, |
…when permissive sanitization is enabled The converter built its LabelNamer with only UnderscoreLabelSanitization set, so label names with consecutive underscores (e.g. a__b) were still collapsed to a single underscore even when the pkg.translator.prometheus.PermissiveLabelSanitization feature gate was enabled. Set PreserveMultipleUnderscores from the same gate so the gate actually preserves them, and add tests covering the gate on/off behavior and the reserved __-prefixed label. Signed-off-by: s3onghyun <s3onghyun@users.noreply.github.com>
Review follow-up: - newPrometheusConverterV2 built its own LabelNamer without PreserveMultipleUnderscores, so FromMetricsV2 kept collapsing consecutive underscores even with the permissive sanitization gate on. Same field, same gate, now set there too, with a test covering both gate states. - The reserved __name__ subtest claimed it held 'regardless of gate' but only ran the gate-disabled case; it is now table-driven over both. - Cached DropSanitizationGate.IsEnabled() in a local instead of evaluating it twice per struct literal. Signed-off-by: s3onghyun <s3onghyun@users.noreply.github.com>
c94750d to
f9bf8ec
Compare
|
Thanks @singhvibhanshu — rebased on latest main, conflicts resolved ( |
|
Thank you for your contribution @s3onghyun! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey. |
Description
newPrometheusConverterbuilds itsLabelNamerwith onlyUnderscoreLabelSanitizationset:Because
PreserveMultipleUnderscoresis never set, label names with consecutive underscores (e.g.a__b) are collapsed to a single underscore (a_b) even when thepkg.translator.prometheus.PermissiveLabelSanitizationfeature gate is enabled — so enabling the gate does not fully drop sanitization as documented.This sets
PreserveMultipleUnderscoresfrom the same feature gate, so when the gate is on, consecutive underscores are preserved.otlptranslator.LabelNameralready exposes this field (v1.0.0), and reserved__-prefixed labels remain untouched.Link to tracking issue
Fixes #48991
Testing
Added
TestNewPrometheusConverterLabelNamerMultipleUnderscorescovering:a__bis preserveda__bis collapsed toa_b(unchanged behavior)__name__is preserved regardless of the gateThe gate-enabled case fails before this change and passes after; the full package test suite still passes.
Documentation
No user-facing docs change; the feature gate behavior now matches its documented intent.