Repository navigation
expfmt: omit incompatible OpenMetrics unit metadata - #1012
Open
itsmeasadali wants to merge 1 commit into
Open
itsmeasadali wants to merge 1 commit into
itsmeasadali wants to merge 1 commit into
Conversation
Signed-off-by: Asad Ali <asad@ztabs.co>
bwplotka
approved these changes
Oct 14, 2026
bwplotka
left a comment
Member
There was a problem hiding this comment.
I think that's a valid solution, given our parser enforcement and the fact we add unit support after some time, thanks!
Ideally we notify user in some way this happens, but this is a good start
| } | ||
| } | ||
|
|
||
| func TestCreateOpenMetricsUnitSuffix(t *testing.T) { |
Member
There was a problem hiding this comment.
Can we move this to the existing table test, to avoid test duplication?
dashpole
self-requested a review
October 14, 2026 16: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.
Fixes #1005.
OpenMetrics 1.0 requires a non-empty UNIT to match the metric family name's underscore-separated suffix. After #877 stopped adding units to metric names, the encoder could still emit incompatible UNIT metadata, which Prometheus rejects and which can fail the whole scrape.
This proposes the omission approach described in the issue: emit a non-empty UNIT only when it matches the family name, after the existing counter
_totalhandling. Sample names and values are unchanged. Nil/empty units and valid units retain their behavior. The separate OpenMetrics 2.0 encoder is unchanged.Add 12 table-driven regression cases for matching/mismatching units, missing separators, partial suffixes, counter/gauge suffix handling, compound units, nil and empty units, byte counts, and input immutability. Update existing expectations that previously required incompatible UNIT lines.
Validation on Windows amd64 with Go 1.27.1:
go test ./expfmt -count=1passed.go vet ./...passed.TestMissingBearerAuthFile, whose Windows error-message mismatch also reproduces without this change. The unfiltered root suite is not reported as fully passing.golangci-lint 2.13.1 run ./...andgo mod tidy -diffpassed on a clean LF checkout.@roidelapluie @gotjosh: does omitting incompatible UNIT metadata look like the preferred resolution while preserving metric names?