Skip to content

prometheusexporter: Expose new otlptranslator options#43050

Closed
ywwg wants to merge 5 commits into
open-telemetry:mainfrom
ywwg:owilliams/newconfig
Closed

prometheusexporter: Expose new otlptranslator options#43050
ywwg wants to merge 5 commits into
open-telemetry:mainfrom
ywwg:owilliams/newconfig

Conversation

@ywwg
Copy link
Copy Markdown
Contributor

@ywwg ywwg commented Sep 29, 2025

Description

Adds underscore_label_sanitization and preserve_multiple_underscores to config options. This allows users who were relying on previous default translation behavior to maintain metric name continuity.

"underscore_label_sanitization", when true, prepends "key" to labels starting with an underscore. This behavior is not required by Prometheus nor is it done by Prometheus' own otel endpoint. Therefore we have disabled this behavior by default. Users who rely on this can set this option to true.

"preserve_multiple_underscores", when true, does not collapse multiple underscores when translating metric and label names. For instance "my.silly$%^&.metric" would become "my_silly_____metric" instead of "my_silly_metric". This is another inconsistency between different otel translation libraries that have been rectified, but since some users rely on the preservation of multiple underscores, they can set this option to true.

Link to tracking issue

Fixes #43077

Testing

New unit tests

Documentation

explanatory comments added to new options in code

Adds underscore_label_sanitization and preserve_multiple_underscores to config options.
This allows users who were relying on previous default translation behavior to maintain metric name continuity.

Signed-off-by: Owen Williams <owen.williams@grafana.com>
Signed-off-by: Owen Williams <owen.williams@grafana.com>
Signed-off-by: Owen Williams <owen.williams@grafana.com>
Signed-off-by: Owen Williams <owen.williams@grafana.com>
Signed-off-by: Owen Williams <owen.williams@grafana.com>
Comment on lines +48 to +60
// UnderscoreLabelSanitization, if true, enables prepending 'key' to labels
// starting with '_'. Reserved labels starting with `__` are not modified.
// Included for compatibility with default previous behavior.
//
// Deprecated: This will be removed in a future version.
UnderscoreLabelSanitization bool `mapstructure:"underscore_label_sanitization"`

// PreserveMultipleUnderscores enables preserving of multiple
// consecutive underscores in label names when UTF8Allowed is false.
// This option is discouraged as it violates the OpenTelemetry to Prometheus
// specification https://github.com/open-telemetry/opentelemetry-specification/blob/v1.38.0/specification/compatibility/prometheus_and_openmetrics.md#otlp-metric-points-to-prometheus),
// but may be needed for compatibility with legacy systems that rely on the old behavior.
PreserveMultipleUnderscores bool `mapstructure:"preserve_multiple_underscores"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is already controlled by a feature flag, see #40604

We shouldn't have two ways of doing the same thing 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh, hm, I forgot we'd already made it a flag -- we still need to expose the underscores setting though, right?

Copy link
Copy Markdown
Member

@ArthurSens ArthurSens Sep 30, 2025

Choose a reason for hiding this comment

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

Well, the OTel collector never exposed multiple underscores, so I don't see why make that possible now 🤔

This multiple-underscore option was created because Mimir needed it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok, then would you say nobody should get broken by this upgrade in a way that they can't work around? if so, yay! But we still need to make sure we are loud about the possibility of breakage so that people can debug it quickly

Copy link
Copy Markdown
Member

@ArthurSens ArthurSens Sep 30, 2025

Choose a reason for hiding this comment

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

I have a feeling people will get broken because we haven't stitched together the feature-flag with the code written in otlptranslator.

I feel like it's safer to revert the upgrade of otlptranslator to 1.0.0, revist the code behind that feature-gate and once we're confident that they are working well together... then we upgrade otlptranslator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would really love to avoid a configuration option for this, and encourage users to just migrate. As a workaround, we can tell users to use the transform processor to rename metrics prior to reaching the exporter. When we graduate the feature gate to beta, users still have the option to revert, and open issues with feedback. If this change turns out to be too disruptive, we can revisit adding config options at that point.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

that's fine by me -- I was inclined to be more cautious given the amount of pings I get when metric names break.

Where would be a good place to put that workaround recommendation so people find it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably in the package README under the feature gate?

@ywwg
Copy link
Copy Markdown
Contributor Author

ywwg commented Oct 2, 2025

no config needed, will update README in a separate PR

@ywwg ywwg closed this Oct 2, 2025
@ywwg
Copy link
Copy Markdown
Contributor Author

ywwg commented Oct 2, 2025

can someone reopen this? I do not have permission

atoulme pushed a commit that referenced this pull request Oct 4, 2025
)

Followon from
#43050

#### Description

Connects up PermissiveLabelSanitization feature gate.

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
First part of
#43077

<!--Describe what testing was performed and which tests were added.-->
#### Testing

New unit tests

<!--Describe the documentation added.-->
#### Documentation

explanatory comments added to new options in code

<!--Please delete paragraphs that you did not use before submitting.-->

---------

Signed-off-by: Owen Williams <owen.williams@grafana.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prometheusexporter: Expose new translation options

4 participants