expfmt: prevent st@ leaking to Gauge and Untyped samples in OpenMetrics 2.0 - #971
Open
dashpole wants to merge 1 commit into
Open
expfmt: prevent st@ leaking to Gauge and Untyped samples in OpenMetrics 2.0#971dashpole wants to merge 1 commit into
dashpole wants to merge 1 commit into
Conversation
dashpole
force-pushed
the
fix-om20-timestamps
branch
from
August 24, 2026 16:28
50b5d21 to
93d3808
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Follow-up fixes to the OpenMetrics 2.0 expfmt writer to ensure st@ (start timestamp) is emitted only for Counter samples, plus a small cleanup/adjustment around timestamp formatting and related test coverage.
Changes:
- Pass
CreatedTimestampexplicitly only for Counter samples sost@doesn’t leak into Gauge/Untyped output. - Simplify
writeOpenMetrics20Timestampby relying onstrconv.AppendFloatbehavior directly. - Improve proto timestamp formatting for pre-epoch timestamps and add coverage for those cases.
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 |
Ensures st@ is only written when explicitly provided (Counters), simplifies timestamp writing, and improves proto timestamp formatting for pre-epoch values. |
expfmt/openmetrics_2_0_create_test.go |
Adds scenarios preventing st@ leakage to Gauge/Untyped and adds tests for pre-epoch proto timestamp formatting; adjusts timestamp unit tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…cs 2.0 Signed-off-by: David Ashpole <dashpole@google.com>
dashpole
force-pushed
the
fix-om20-timestamps
branch
from
August 24, 2026 17:54
8708e66 to
750ac47
Compare
dashpole
marked this pull request as ready for review
August 24, 2026 18:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some small follow-ups to the OpenMetrics 2.0 support introduced by #894.
Previously,
writeOpenMetrics20Sampleinspectedmetric.Counter.CreatedTimestampdirectly when rendering samples. If adto.Metricstruct had multiple type fields populated (e.g., a Gauge with a leftoverCounter.CreatedTimestamp),st@would incorrectly render on Gauge or Untyped sample lines.This PR:
startTimestampexplicitly towriteOpenMetrics20Sampleonly from the Counter branch (passingnilfor Gauge and Untyped).NaN/Infbranches inwriteOpenMetrics20Timestampin favor of directstrconv.AppendFloatformatting.st@is isolated to Counter metrics and does not leak onto Gauge/Untyped samples.