Skip to content

ingester: fix ingestion delay histogram reset duration - #7772

Open
mehrdadbn9 wants to merge 3 commits into
cortexproject:masterfrom
mehrdadbn9:fix/ingestion-delay-histogram-reset-7731
Open

ingester: fix ingestion delay histogram reset duration#7772
mehrdadbn9 wants to merge 3 commits into
cortexproject:masterfrom
mehrdadbn9:fix/ingestion-delay-histogram-reset-7731

Conversation

@mehrdadbn9

Copy link
Copy Markdown
Contributor

Summary

Fixes #7731.

cortex_ingester_ingestion_delay_seconds was registered with NativeHistogramMinResetDuration: 1. The field is a time.Duration, so the bare integer 1 is interpreted as 1 nanosecond, which resets the native histogram on essentially every scrape and discards ~86% of observations.

This change sets it to 1 * time.Hour (consistent with the sibling minResetDuration on the adjacent histogram) and extracts the histogram options into a package-level ingestionDelaySecondsHistogramOpts so the reset duration is directly testable.

Test plan

  • Added TestIngestionDelaySecondsHistogramResetDuration asserting NativeHistogramMinResetDuration == time.Hour.
  • Verified with the fix in place; the test fails (RED) with the original 1 literal and passes (GREEN) with 1 * time.Hour.

Checklist

  • CHANGELOG updated
  • Tests added/updated
  • DCO sign-off present

Signed-off-by: mehrdadbn9 mehrdadbn9@users.noreply.github.com

Mehrdad Biukian Naeini added 3 commits August 16, 2026 03:34
trimStringByBytes scans backwards from the truncation point to find a
UTF-8 rune start, but the loop had no lower bound. When a request field
consists only of UTF-8 continuation bytes (0x80-0xBF) there is no rune
start to land on, so size underflows past zero and bytesStr[-1] panics
with 'index out of range [-1]'. Because the active query tracker is
enabled by default and the panic happens on a goroutine without recover(),
an attacker-supplied match[]/query value can crash the querier.

Bound the scan with 'size > 0' so it stops at the start of the string
instead of underflowing. When no rune start exists the field is truncated
to an empty string, which is safe.

Add TestTrimForJsonMarshalContinuationBytes covering the all-continuation-
byte case; existing multi-byte tests use valid UTF-8 ('世') which always
terminates the scan at index 0 and therefore never exercised the underflow.

Fixes cortexproject#7729

Signed-off-by: ...
Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
…roject#7731)

Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
…#7731)

Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cortex_ingester_ingestion_delay_seconds loses ~86% of observations: NativeHistogramMinResetDuration is 1ns, not 1h

1 participant