Skip to content

expfmt: reject duplicate histogram buckets and summary quantiles - #1019

Open
wilmore11 wants to merge 1 commit into
prometheus:mainfrom
wilmore11:fix/expfmt-duplicate-buckets-quantiles
Open

wilmore11 wants to merge 1 commit into
prometheus:mainfrom
wilmore11:fix/expfmt-duplicate-buckets-quantiles

Conversation

@wilmore11

Copy link
Copy Markdown

When a histogram contains two buckets with the same upper bound, or a summary contains the same quantile twice, the expfmt decoders currently accept the input and SampleDecoder produces duplicate samples. This affects both Prometheus text and delimited protobuf input.

This change rejects duplicate bounds and quantiles within each metric when decoding either format. ExtractSamples also rejects invalid families while continuing to extract samples from the remaining valid families. Checks are scoped to each metric, so different label sets can still share the same bounds, and valid input is not reordered.

Fixes #51.

Validation:

  • Regression tests fail against main at 25bdf5c and pass with this change.
  • go test -race ./... passes with Go 1.26.9.
  • make test style check-go-mod-version passes with Go 1.27.2 and golangci-lint v2.14.0.
  • golangci-lint fmt --diff and git diff --cached --check pass.

Tests cover finite and infinite duplicate bounds, signed zero, gauge histograms, duplicate quantiles, unsorted distinct bounds, separate label sets, empty quantile lists, sample extraction, and reaching EOF after rejecting a family.

The change deliberately leaves the low-level TextParser API unchanged; validation happens at the Decoder and ExtractSamples boundaries. Reviewers may prefer validation in TextParser as a follow-up.

AI assistance was used to implement this change, write regression tests, and prepare this description. The test results above were obtained by running the commands against the checkout.

@roidelapluie @gotjosh

Validate duplicate bounds and quantiles for both text and protobuf
decoders, and reject invalid families during bulk sample extraction.
Keep validation scoped to individual metrics and preserve valid data.

Add regression tests for both encodings and sample extraction.

Fixes prometheus#51

Signed-off-by: leii2008 <ubun426406@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

expfmt: Handle duplicate buckets and quantiles during decoding

2 participants