Add Prometheus translation strategy support#8346
Conversation
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Codecov Report❌ Patch coverage is ❌ Your project check has failed because the head coverage (78.48%) is below the target coverage (89.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #8346 +/- ##
=============================================
- Coverage 91.04% 78.77% -12.27%
- Complexity 7822 8579 +757
=============================================
Files 893 1009 +116
Lines 23721 28993 +5272
Branches 2364 3599 +1235
=============================================
+ Hits 21596 22839 +1243
- Misses 1407 5311 +3904
- Partials 718 843 +125 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
psx95
left a comment
There was a problem hiding this comment.
Also might wanna look at this relevant spec issue: open-telemetry/opentelemetry-specification#5062
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
jack-berg
left a comment
There was a problem hiding this comment.
Some small comments and ideas. Thanks!
- Replace IllegalArgumentException control flow in PrometheusUnitsHelper.sanitizeUnitName with @nullable return; drop the try/catch in unitOrNull. - Extract doConvert helper so convert is just the IAE try/catch boundary. - Inline the getMergeKey ternary at the putOrMerge call site. - Reorder convertMetadataEscapedWithSuffixes for readability and use the explicit 5-arg MetricMetadata constructor. Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Also bumps protobuf-bom 4.34.1 -> 4.35.0 to match the gencode shipped inside prometheus-metrics-exposition-formats 1.7.0 (runtime must be >= gencode version). Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
9e0b450 to
9c20343
Compare
## Summary - Adds `MetricMetadata.builder()` with `name`, `help`, `unit`, `counterSuffix` fields - Builder appends unit to the base name when absent, and appends `_total` to `expositionBaseName` when `counterSuffix=true` - Deprecates the 4-arg and 5-arg constructors; internal callers (`MetricMetadataSupport`, `MetricMetadata.escape`) suppress the warning - Updates `docs/apidiffs/current_vs_latest/prometheus-metrics-model.txt` ## Motivation The OTel exporter ([opentelemetry/opentelemetry-java#8346](open-telemetry/opentelemetry-java#8346)) needs to express per-strategy counter intent without pre-computing `expositionBaseName` manually. The builder encapsulates that logic and provides a cleaner public API for any downstream adapter that constructs `MetricMetadata` directly. ## Test plan - [ ] `MetricMetadataTest` — 8 new builder tests covering: no unit, unit absent/present, counter suffix, counter + unit, UTF-8 name, non-counter, name-required validation - [ ] Existing 4-arg/5-arg constructor tests annotated with `@SuppressWarnings("deprecation")` --------- Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
|
Will undraft once the new prom client release has been published. |
|
@psx95 please have another look |
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
…slation-strategy # Conflicts: # dependencyManagement/build.gradle.kts
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
psx95
left a comment
There was a problem hiding this comment.
Thanks for following up on the updated spec issue, @zeitlinger !
Overall changes LGTM, I just left a couple of small suggestions and mostly verified the translation logic by looking at the tests.
…n tests Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
psx95
left a comment
There was a problem hiding this comment.
Thanks for addressing the feedback!
jack-berg
left a comment
There was a problem hiding this comment.
Re-reviewed. Two more small nits, but still looks good.
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
|
@jack-berg done |
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Summary
TranslationStrategysupport to the Prometheus exporter builder and declarative configclient_javato1.6.1, which provides the released naming support this needsprometheus/otlptranslatorbehavior for invalid characters, repeated underscores, and digit-leading labelsNotes
prometheus/otlptranslatorpreserves labels normalized to__...__; Prometheus Java rejects user labels starting with__, so those labels are collapsed to a valid single-underscore form instead.References
otlptranslator: https://github.com/prometheus/otlptranslatorTest plan
./gradlew :exporters:prometheus:test --tests io.opentelemetry.exporter.prometheus.PrometheusHttpServerTest.fetchOpenMetrics --tests io.opentelemetry.exporter.prometheus.PrometheusHttpServerTest.fetchOpenMetrics_translationStrategyEnablesOm2 --tests io.opentelemetry.exporter.prometheus.PrometheusMetricReaderTest --tests io.opentelemetry.exporter.prometheus.Otel2PrometheusConverterTest --tests io.opentelemetry.exporter.prometheus.internal.PrometheusMetricReaderProviderTest :sdk-extensions:declarative-config:test --tests io.opentelemetry.sdk.autoconfigure.declarativeconfig.MetricReaderFactoryTest.create_PullPrometheusConfiguredResolves #8195