Skip to content

Commit 8cf1fd9

Browse files
committed
Stabilize Prometheus Native Histogram -> OTLP (Exponential) Histogram
Fixes: #4748 See task list in the issues comments. Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
1 parent fc2e1a9 commit 8cf1fd9

File tree

2 files changed

+82
-11
lines changed

2 files changed

+82
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ release.
3232

3333
### Compatibility
3434

35+
- Clarify Prometheus Native Histogram to OTLP Exponential Histogram conversion,
36+
add conversion rules for Native Histograms with Custom Buckets (NHCB) to OTLP
37+
Histogram.
38+
([#4898](https://github.com/open-telemetry/opentelemetry-specification/pull/4898))
39+
3540
### SDK Configuration
3641

3742
### Supplementary Guidelines

specification/compatibility/prometheus_and_openmetrics.md

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,28 +157,94 @@ with standard (exponential) schema (i.e. schemas -4 to 8) and which are
157157
of the integer and counter [flavor](https://prometheus.io/docs/specs/native_histograms/#flavors)
158158
MUST be converted to an OTLP Exponential Histogram as follows:
159159

160+
- If the Native Histogram `ResetHint` (or `CounterResetHint`) indicates gauge
161+
type, the native histogram is dropped. Otherwise this field is ignored.
160162
- `Schema` is converted to the Exponential Histogram `Scale`.
161163
- The `NoRecordedValue` flag is set to `true` if the `Sum` is equal to the
162-
Stale NaN value. Otherwise,
163-
- `Count` is converted to Exponential Histogram `Count`.
164-
- `Sum` is converted to the Exponential Histogram `Sum`.
164+
[Stale NaN value](https://github.com/prometheus/prometheus/blob/main/model/value/value.go).
165+
Otherwise,
166+
- `Count` is converted to Exponential Histogram `Count`. Note that the `Count`
167+
may be greater than the sum of all `Positive`, `Negative` and `Zero` bucket
168+
counts in case the Native Histogram observed values outside the IEEE float
169+
range, for example `-Inf`, `+Inf`, `NaN`.
170+
- `Sum` is converted to the Exponential Histogram `Sum`. Note that the `Sum`
171+
may be `NaN` in case the Native Histogram observed the value `NaN` or both
172+
`-Inf` and `+Inf`. The `Sum` may also be `-Inf` or `+Inf`.
165173
- `Timestamp` is converted to the Exponential Histogram `TimeUnixNano` after
166174
converting milliseconds to nanoseconds.
167175
- `ZeroCount` is converted directly to the Exponential Histogram `ZeroCount`.
168176
- `ZeroThreshold`, is converted to the Exponential Histogram `ZeroThreshold`.
169-
- The sparse bucket layout represented by `PositiveSpans` and `PositiveDeltas` is
170-
converted to the Exponential Histogram dense layout represented by `Positive`
171-
bucket counts and `Offset`. The same holds for `NegativeSpans` and
172-
`NegativeDeltas`. Note that Prometheus Native Histograms buckets are indexed by
173-
upper boundary while Exponential Histograms are indexed by lower boundary, the
174-
result being that the Offset fields are different-by-one.
177+
- The [sparse bucket layout](https://prometheus.io/docs/specs/native_histograms/#buckets)
178+
represented by `PositiveSpans` and `PositiveDeltas` is converted to the
179+
Exponential Histogram dense layout represented by `Positive` bucket counts and
180+
`Offset`.
181+
182+
- The `PositiveDeltas` are delta encoded bucket counts, where the first value
183+
is an absolute bucket count and each subsequent value is a delta to the
184+
previous value.
185+
- The Exponential Histogram `Positive` `Offset` is set to the first
186+
`PositiveSpan`'s `Offset` minus 1 (`PositiveSpans[0].Offset-1`) if there
187+
are spans, otherwise left at 0. Note that Prometheus Native Histogram
188+
buckets are indexed by upper boundary while Exponential Histograms are
189+
indexed by lower boundary, hence the minus one.
190+
- The `PositiveSpans` encode the index into the `Positive` bucket counts for
191+
each value in the `PositiveDeltas`. The index starts from 0 for the first
192+
span, for subsequent spans the span's `Offset` is added to the previous
193+
index. The span's `Length` indicates the number of continuous indexes to
194+
use.
195+
- The Native Histogram may contain overflow buckets. If converted to
196+
an Exponential Histogram bucket, the overflow bucket would map to values
197+
outside the IEEE float range. The Native Histogram SHOULD be dropped in
198+
accordance with [ExponentialHistogram: Consumer Recommendations](../metrics/data-model.md/#exponentialhistogram-consumer-recommendations).
199+
If the Native Histogram is not dropped, the overflow bucket itself MUST be
200+
dropped.
201+
202+
- The `NegativeSpans` and `NegativeDeltas` are converted the same way as the
203+
positive buckets.
204+
- `Min` and `Max` are not set.
205+
- `StartTimeUnixNano` is set to the `Start Timestamp` timestamp, if available.
206+
- `AggregationTemporality` is set to `cumulative`.
207+
208+
A Native histogram with custom buckets (NHCB) schema (i.e. schema -53) and which
209+
are of the integer and counter [flavor](https://prometheus.io/docs/specs/native_histograms/#flavors)
210+
MUST be converted to an OTLP Histogram as follows:
211+
212+
- If the Native Histogram `ResetHint` (or `CounterResetHint`) indicates gauge
213+
type, the native histogram is dropped. Otherwise this field is ignored.
214+
- The `NoRecordedValue` flag is set to `true` if the `Sum` is equal to the
215+
[Stale NaN value](https://github.com/prometheus/prometheus/blob/main/model/value/value.go).
216+
Otherwise,
217+
- `Count` is converted to Histogram `Count`. Note that the `Count`
218+
is equal to the sum of all bucket counts.
219+
- `Sum` is converted to the Histogram `Sum`. Note that the `Sum`
220+
may be `NaN` in case the Native Histogram observed the value `NaN` or both
221+
`-Inf` and `+Inf`. The `Sum` may also be `-Inf` or `+Inf`.
222+
- `Timestamp` is converted to the Histogram `TimeUnixNano` after
223+
converting milliseconds to nanoseconds.
175224
- `Min` and `Max` are not set.
176-
- `StartTimeUnixNano` is set to the `Created` timestamp, if available.
225+
- [`CustomValues`](https://prometheus.io/docs/specs/native_histograms/#custom-values)
226+
is converted to bucket boundaries. The `+Inf` bucket is implicit, therefore
227+
`N` `CustomValues` represent `N+1` Histogram bucket counts.
228+
- The [sparse bucket layout](https://prometheus.io/docs/specs/native_histograms/#buckets)
229+
represented by `PositiveSpans` and `PositiveDeltas` is converted to
230+
Histogram bucket counts.
231+
232+
- The `PositiveDeltas` are delta encoded bucket counts, where the first value
233+
is an absolute bucket count and each subsequent value is a delta to the
234+
previous value.
235+
- The `PositiveSpans` encode the index into the bucket counts for each value
236+
in the `PositiveDeltas`. The index starts from the `Offset` in the first
237+
span and for subsequent spans the span's `Offset` is added to the previous
238+
index. The span's `Length` indicates the number of continuous indexes to
239+
use.
240+
241+
- `StartTimeUnixNano` is set to the `Start Timestamp`, if available.
177242
- `AggregationTemporality` is set to `cumulative`.
178243

179244
Native histograms of the float or gauge flavors MUST be dropped.
180245

181-
Native Histograms with `Schema` outside of the range [-4, 8] MUST be dropped.
246+
Native Histograms with `Schema` outside of the range [-4, 8] and not equal to
247+
-53 MUST be dropped.
182248

183249
### Summaries
184250

0 commit comments

Comments
 (0)