Prometheus exporter: Clarify interation between content negotiation and translation strategy#5134
Prometheus exporter: Clarify interation between content negotiation and translation strategy#5134ArthurSens wants to merge 3 commits into
Conversation
…nd translation strategy Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
|
cc @open-telemetry/prometheus-interoperability |
|
|
||
| - If configured with `NoTranslation` but the client requests `escaping=underscores`, the exporter MUST apply underscore escaping. | ||
| - If configured with `UnderscoreEscapingWithSuffixes` but the client requests `escaping=allow-utf8`, there's no need to revert what has been translated since the exporter will continue to be compliant. | ||
| - If configured with `UnderscoreEscapingWithSuffixes` but the client requests `escaping=allow-utf-8`, there's no need to revert what has been translated since the exporter will continue to be compliant. |
There was a problem hiding this comment.
@zeitlinger does this align with what you've been working on in open-telemetry/opentelemetry-java#8346?
What are the conditions that would allow a client to actually see metrics conforming to the configured translation strategy? Does a client essentially have to set escaping=allow-utf-8 to avoid the prometheus client library undoing the translation strategy?
There was a problem hiding this comment.
@zeitlinger does this align with what you've been working on in open-telemetry/opentelemetry-java#8346?
yes it does
What are the conditions that would allow a client to actually see metrics conforming to the configured translation strategy? Does a client essentially have to set
escaping=allow-utf-8to avoid the prometheus client library undoing the translation strategy?
yes
There was a problem hiding this comment.
I think we should augment the examples list with all the combinations of translation and header. For example, something like
Examples:
For a counter metric named `foo.bar`:
- With `escaping=underscores` or no `Accept` header (Prometheus's default behavior in Prometheus 2.x):
- If configured with `UnderscoreEscapingWithSuffixes` (default), the metric will be named `foo_bar_total`
- If configured with `UnderscoreEscapingWithoutSuffixes`, the metric will be named `foo_bar`
- If configured with `NoUTF8EscapingWithSuffixes`, the metric will be named `foo_bar_total`
- if configured with `NoTranslation`, the metric will be named `foo_bar`
- With `escaping=allow-utf-8` (Prometheus's default behavior in Prometheus 3.x):
- If configured with `UnderscoreEscapingWithSuffixes` (default), the metric will be named `foo_bar_total`
- If configured with `UnderscoreEscapingWithoutSuffixes`, the metric will be named `foo_bar`
- If configured with `NoUTF8EscapingWithSuffixes`, the metric will be named `foo.bar_total`
- if configured with `NoTranslation`, the metric will be named `foo.bar`
I think I have all of those combinations correct. There is no value for translation_strategy that will result in Prometheus 2.x seeing foo_bar_total and Prometheus 3.x seeing foo.bar.
There was a problem hiding this comment.
I would do it as a table - but yes, would be great to have this explicit
There was a problem hiding this comment.
Yes, the combinations are correct IMO
| When a Prometheus Exporter is configured with a permissive `translation_strategy`, | ||
| such as `NoTranslation`, the final output format and character escaping MUST | ||
| comply with the content negotiation's restrictions based on the `Accept` header. |
There was a problem hiding this comment.
I think it should just explicitly say that content negotiation happens after translation. Something like:
First, `translation_strategy` MUST be applied to construct metric names. Then,
the Prometheus exporter MUST apply content negotiation, which can include
a second translation of metric names.
|
|
||
| - If configured with `NoTranslation` but the client requests `escaping=underscores`, the exporter MUST apply underscore escaping. | ||
| - If configured with `UnderscoreEscapingWithSuffixes` but the client requests `escaping=allow-utf8`, there's no need to revert what has been translated since the exporter will continue to be compliant. | ||
| - If configured with `UnderscoreEscapingWithSuffixes` but the client requests `escaping=allow-utf-8`, there's no need to revert what has been translated since the exporter will continue to be compliant. |
There was a problem hiding this comment.
I think we should augment the examples list with all the combinations of translation and header. For example, something like
Examples:
For a counter metric named `foo.bar`:
- With `escaping=underscores` or no `Accept` header (Prometheus's default behavior in Prometheus 2.x):
- If configured with `UnderscoreEscapingWithSuffixes` (default), the metric will be named `foo_bar_total`
- If configured with `UnderscoreEscapingWithoutSuffixes`, the metric will be named `foo_bar`
- If configured with `NoUTF8EscapingWithSuffixes`, the metric will be named `foo_bar_total`
- if configured with `NoTranslation`, the metric will be named `foo_bar`
- With `escaping=allow-utf-8` (Prometheus's default behavior in Prometheus 3.x):
- If configured with `UnderscoreEscapingWithSuffixes` (default), the metric will be named `foo_bar_total`
- If configured with `UnderscoreEscapingWithoutSuffixes`, the metric will be named `foo_bar`
- If configured with `NoUTF8EscapingWithSuffixes`, the metric will be named `foo.bar_total`
- if configured with `NoTranslation`, the metric will be named `foo.bar`
I think I have all of those combinations correct. There is no value for translation_strategy that will result in Prometheus 2.x seeing foo_bar_total and Prometheus 3.x seeing foo.bar.
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Clarifies how a Prometheus Exporter’s translation_strategy interacts with Prometheus content negotiation, especially when the configured strategy is permissive and may need additional escaping based on the client’s Accept header.
Changes:
- Replaces example bullets with a step-by-step description of applying
translation_strategyfirst, then applying content negotiation (including potentially a second escaping step). - Adds a concrete example table mapping
translation_strategyand requestedescapingscheme to resulting metric names.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Fixes #5062
Changes
CHANGELOG.mdfile updated for non-trivial changes[chore]in the PR title to skip the changelog check