Repository navigation
feat: implement histogram and gauge histogram support for OpenMetrics 2.0 - #964
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the OpenMetrics 2.0 encoder to support serialization and validation of histogram and gauge-histogram metrics, aligning output formatting with the OM2 structure (inline histogram fields plus optional exemplars), and adjusts exemplar emission rules to allow empty-label exemplars when a timestamp is present.
Changes:
- Implemented OpenMetrics 2.0 serialization/validation for classic, native, dual, and gauge histograms (including spans/buckets encoding and created timestamps where applicable).
- Updated exemplar handling to no longer drop exemplars solely due to having an empty label set (still dropped if missing timestamp), emitting
{}for empty labels. - Added comprehensive golden/output and error-case test coverage for histogram variants in OM2.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| expfmt/openmetrics_2_0_create.go | Implements histogram/gaugehistogram encoding + validation and updates exemplar formatting for empty-label exemplars. |
| expfmt/openmetrics_2_0_create_test.go | Adds output and error tests covering classic/native/dual/gauge histogram serialization and validation rules. |
ðĄ Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
bwplotka
left a comment
There was a problem hiding this comment.
Looks solid, so far, thanks, some nits
75927dd to
e391204
Compare
âĶ 2.0 Implement serialization and strict validation for classic, native, dual, and gauge histograms in OpenMetrics 2.0 format according to the specification and ABNF grammar. Signed-off-by: David Ashpole <dashpole@google.com>
Signed-off-by: David Ashpole <dashpole@google.com>
Signed-off-by: David Ashpole <dashpole@google.com>
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com> Signed-off-by: David Ashpole <dashpole@google.com>
Signed-off-by: David Ashpole <dashpole@google.com>
âĶncoding Signed-off-by: David Ashpole <dashpole@google.com>
âĶram encoding Signed-off-by: David Ashpole <dashpole@google.com>
Signed-off-by: David Ashpole <dashpole@google.com>
âĶm encoding Signed-off-by: David Ashpole <dashpole@google.com>
Signed-off-by: David Ashpole <dashpole@google.com>
âĶ in OM 2.0 Signed-off-by: David Ashpole <dashpole@google.com>
âĶdBuckets Signed-off-by: David Ashpole <dashpole@google.com>
Signed-off-by: David Ashpole <dashpole@google.com>
e391204 to
18756bb
Compare
bwplotka
left a comment
There was a problem hiding this comment.
Thanks! Looks great, let's iterate. Small nits only, we can merge without those.
| } | ||
|
|
||
| // Stubs for Summary and Histogram | ||
| // Stubs for Summary |
There was a problem hiding this comment.
| // Stubs for Summary |
| }, | ||
| }, | ||
| out: `# TYPE http_requests_total counter | ||
| http_requests_total 1027.0 st@-0.5 # {trace_id="1234"} 1.0 -1.75 |
There was a problem hiding this comment.
Lol that got me off, but it makes sense (initially I expected -1.5 and -2.25 ts) - but the positive NS makes sense
| return n + n2, err | ||
| } | ||
|
|
||
| func writeNanos(w enhancedWriter, nanos int64) (int, error) { |
There was a problem hiding this comment.
Wonder, can't we reuse writeOpenMetricsFloat or so for seconds float precision?
Part 2 of #893
Implement serialization and strict validation for classic, native, dual, and gauge histograms in OpenMetrics 2.0 format according to the specification and ABNF grammar.