Skip to content

receive: include native histograms in samples limit - #8987

Open
lemon0333 wants to merge 1 commit into
thanos-io:mainfrom
lemon0333:feat/receive-samples-limit-histograms
Open

lemon0333 wants to merge 1 commit into
thanos-io:mainfrom
lemon0333:feat/receive-samples-limit-histograms

Conversation

@lemon0333

Copy link
Copy Markdown

Fixes #7593

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

The Receive per-request samples limit only counted float samples when deciding whether to reject a write request as "too many samples". Native histogram data points were not counted, so a request could carry an unbounded number of native histograms without ever hitting the configured samples limit.

This changes the sample counting to also include native histograms:

  • pkg/receive/handler.go: the Prometheus remote-write path now sums len(timeseries.Samples) + len(timeseries.Histograms) before calling requestLimiter.AllowSamples(...).
  • pkg/receive/handler_otlp.go: the OTLP path applies the same inclusion.

Scope is intentionally kept tight to the existing samples limit. The separate total_histogram_samples / total-buckets limits mentioned as larger alternatives in #7593 can be a follow-up.

Verification

  • go build ./pkg/receive/... passes.
  • go test ./pkg/receive/ -run TestReceiveWriteRequestLimits passes, including a new sub-case Request above limit of samples once native histograms are counted: with a samples limit of 200, a request of 10 series × 10 float samples (100 total) stays under the limit on floats alone, but once 10 series × 11 native histograms (110) are also counted the total (210) exceeds the limit and the request is rejected with 413 Request Entity Too Large. This fails without the change and passes with it.
  • gofmt and go vet ./pkg/receive/ are clean.

The per-request samples limit only counted float samples
(len(timeseries.Samples)) before calling AllowSamples. Native
histogram data points were ignored, so a request could carry an
unbounded number of histograms without ever hitting the limit.

Count len(timeseries.Histograms) toward the same limit in both the
Prometheus remote-write path (handler.go) and the OTLP path
(handler_otlp.go), and extend TestReceiveWriteRequestLimits to cover
a request that stays under the limit on floats alone but exceeds it
once histograms are included.

Closes thanos-io#7593

Signed-off-by: lemon0333 <147061193+lemon0333@users.noreply.github.com>
@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.54%. Comparing base (e103a81) to head (175d5ba).
⚠️ Report is 31 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8987   +/-   ##
=======================================
  Coverage   64.54%   64.54%           
=======================================
  Files         289      289           
  Lines       37352    37352           
=======================================
+ Hits        24108    24110    +2     
+ Misses      11150    11148    -2     
  Partials     2094     2094           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

amountSamples: 2,
},
{
// Floats alone (10*10=100) stay under the 200 samples limit, but once

@GiedriusS GiedriusS Aug 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this useless comment, please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Receiver samples limit should include native histograms

2 participants