OpenTelemetry bridge: classic histograms exported with +Inf boundary included, violating counts == boundaries + 1 contract
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 82/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- java
调研方向
从 prometheus-metrics-exporter-opentelemetry/src/main/java/io/prometheus/metrics/exporter/opentelemetry/otelmodel/PrometheusClassicHistogram.java 开始,阅读 toOtelDataPoint()、makeBoundaries() 和 makeCounts();然后跟踪 MetricDataFactory.java 以了解入口点。验证生成的 HistogramPointData 仅包含有限边界,并且 counts.size() == boundaries.size() + 1,其中最后一个计数表示隐式溢出桶。
由索引模型根据 Issue 内容生成。
描述
Summary
PrometheusClassicHistogram.toOtelDataPoint() converts a Prometheus classic histogram into an OpenTelemetry HistogramPointData, but it passes the Prometheus bucket boundaries including the final +Inf boundary and emits exactly one count per boundary. The OpenTelemetry data model requires counts.size() == boundaries.size() + 1, with boundaries containing only finite values (the last, +Inf bucket is implicit). The converted point therefore violates the OTel contract that downstream consumers rely on.
Static-analysis finding against current master; not executed here.
Location
- File:
prometheus-metrics-exporter-opentelemetry/src/main/java/io/prometheus/metrics/exporter/opentelemetry/otelmodel/PrometheusClassicHistogram.java - Methods:
makeBoundaries(ClassicHistogramBuckets)(~lines 66-72) andmakeCounts(ClassicHistogramBuckets)(~lines 74-80), called fromtoOtelDataPoint()(~lines 45-58).
Problem
makeBoundaries() iterates all classic buckets and appends every upper bound - for a Prometheus classic histogram the last bucket's upper bound is Double.POSITIVE_INFINITY, so +Inf ends up inside HistogramPointData.getBoundaries(). makeCounts() returns buckets.size() counts, i.e. counts.size() == boundaries.size().
Per the OTel SDK data model (io.opentelemetry.sdk.metrics.data.HistogramPointData), boundaries are the finite bucket edges and there is always one extra count for the implicit last bucket:
getCounts().size() == getBoundaries().size() + 1- boundaries must be finite (
Double.POSITIVE_INFINITYis not a legal explicit bound; the OTLPexplicit_boundsfield likewise expects finite values)
Concretely, a Prometheus histogram with bounds [1, 5, +Inf] and counts [c0, c1, c2] is converted to:
- boundaries
[1.0, 5.0, Infinity] - counts
[c0, c1, c2]
An OTel consumer reading this point interprets it as four buckets: [..,1], [1,5], [5,+Inf] (count c2) plus an implicit trailing (+Inf) bucket with count 0 - misrepresenting both bucket structure and totals. Anything that validates the model (or the OTLP exporter's serialization of infinite explicit bounds) will reject or distort the histogram instead of exporting it faithfully.
Trigger / Reproduction
Based on static analysis; no runtime run was performed:
- Expose any classic histogram through
PrometheusMetricsExporterwith the OpenTelemetry bridge enabled (MetricDataFactoryline ~73 constructsPrometheusClassicHistogramwhenever the snapshot has classic histogram data). - Observe the resulting
HistogramPointData:getBoundaries().contains(Double.POSITIVE_INFINITY)andgetCounts().size() == getBoundaries().size().
Expected Behavior
The conversion should drop the final +Inf upper bound from boundaries and append the total observation count as the extra last element of counts (the implicit overflow bucket), e.g. boundaries [1.0, 5.0], counts [c0, c1, c0+c1+c2]. (calculateCount() already computes this sum when the snapshot lacks an explicit count.)
Actual Behavior
+Inf remains in the boundary list and no implicit-bucket count is appended, producing an out-of-contract HistogramPointData.
Impact
Every classic histogram exported through the OpenTelemetry bridge carries malformed bucket metadata: OTLP exports can fail validation or silently shift all bucket assignments, and aggregation logic built on the OTel model (e.g., heatmap rendering, downstream collectors) computes wrong distributions.
Suggested Direction
In toOtelDataPoint() (or in the two helpers), strip the trailing +Inf boundary when present and build counts as the per-boundary counts followed by the total count. Keeping the helpers symmetric (boundaries.size() == counts.size() - 1) would make the invariant locally verifiable.
Evidence
PrometheusClassicHistogram.makeBoundaries(): unconditionalbuckets.getUpperBound(i)loop;ClassicHistogramBucketssnapshots from the core module always end with+Inffor classic histograms.MetricDataFactory.javaline ~73: result is fed directly into the OTelMetricDatatree consumed by the exporter pipeline.
- 主要语言
- Java
- 星标
- 2.3k
- 派生
- 833
- 平均合并
- 2 天 16 小时
- 30 天内合并 PR
- 86
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
prometheus/client_java 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 86/100
prometheus/client_java#2182 ·
-
难度 5/5 一周以上 新手友好度 35/100
prometheus/client_java#2306 · 9 条评论 · 4 个 reaction ·
-
难度 5/5 一周以上 新手友好度 32/100
prometheus/client_java#2084 · 3 条评论 ·
-
难度 5/5 一周以上 新手友好度 35/100
prometheus/client_java#2075 · 10 条评论 · 1 个 reaction ·
-
prometheus/client_java#1915 · 已指派 1 人 ·
查看 prometheus/client_java 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
infinispan/infinispan#18150 ·
-
难度 2/5 1-3 小时 新手友好度 84/100
-
untriaged
难度 2/5 1-3 小时 新手友好度 82/100
opensearch-project/k-NN#3597 ·
-
bug
难度 2/5 1-3 小时 新手友好度 88/100
-
bug
难度 2/5 1-3 小时 新手友好度 82/100