* textparse: fix NaN canonicalization check in OpenMetrics getFloatValue
* textparse: add tests for OpenMetrics summary NaN quantiles
getFloatValue was testing p.exemplarVal instead of the parsed float when normalizing NaN to the canonical representation, so metric values that were NaN were not normalized correctly.
Extend TestOpenMetricsParse with nansum summary lines and cmpopts.EquateNaNs in requireEntries so NaN float values compare equal after canonicalization.
Signed-off-by: Weixie Cui <cuiweixie@gmail.com>
Signed-off-by: cui <cuiweixie@gmail.com>
Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
Without Schema being propagated in HistogramStatsIterator, histograms
served through the stats-only path (e.g. histogram_count(rate(...)))
all appear as Schema=0, causing the exponential/custom-bucket mismatch
detection to be silently skipped.
Add a test that exercises histogram_count(rate()) over a series with
mixed exponential and custom bucket schemas to verify the warning is
emitted.
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
Add a mutex around the fgprof handler so that only one profile can
run at a time. A second concurrent request returns 500 with an error
message matching the pprof behaviour for CPU profiling already in use.
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
calculateDuration converts a float64 seconds value into a time.Duration
nanoseconds value via "time.Duration(duration*1000) * time.Millisecond".
Two related issues let invalid input slip through:
1. The bounds check used "duration > 1<<63-1 || duration < -1<<63",
comparing a value-in-seconds against the int64 nanosecond range. The
safe input range is +/- math.MaxInt64 / 1e9 seconds (about 292 years),
roughly 1e9 times tighter. Arithmetic on legal duration literals
(e.g. constructed via MUL/POW operators in DurationExpr) could
produce a finite value that passed the check but overflowed during
the final time.Duration conversion, yielding an
implementation-defined int64 silently flowing into selector Range,
OriginalOffset, and Step.
2. NaN compares false against everything, so a NaN duration produced
by math.Pow(-1, 0.5) (and similar) bypassed both the negative-value
check and the magnitude check, again producing an
implementation-defined int64 in the conversion.
Reject NaN and +/-Inf up front, and align the magnitude bound with the
parser's offset_duration_expr rule (1<<63 / 1e9), which already had the
correct unit. Add regression tests covering each new failure mode and
a happy-path case just below the new bound.
```release-notes
[BUGFIX] PromQL: Reject NaN, infinite, and out-of-range duration expressions instead of silently producing an out-of-range time.Duration.
```
Signed-off-by: alexmchughdev <alexanderedwardmchugh@gmail.com>
Fixed a bug in the `PositionRange` method where a panic occurred when `e.RHS` was nil.
Previously, the code checked `if e.RHS == nil` but then immediately
accessed `e.RHS.PositionRange().End`, causing a runtime error.
This commit updates the logic to correctly use `e.LHS.PositionRange().End`
when the RHS is missing.
Fixes: ee7d5158a ("Add step(), min(a,b) and max(a,b) in promql duration expressions")
Found by PostgresPro with the Svace static analyzer.
Signed-off-by: Maksim Korotkov <m.korotkov@postgrespro.ru>
Implements ST for Histograms and Float Histograms (and their custom bucket cousins) in WAL. New tests, new benchmarks.
Part of https://github.com/prometheus/prometheus/issues/17790
```release-notes
[CHANGE] Adds Start Time value to all WAL Histogram samples in memory, and therefore may increase memory usage.
```
Signed-off-by: Owen Williams <owen.williams@grafana.com>
initTime previously set minTime first and maxTime second. Because
Head.initialized() keys only off minTime, a concurrent Head.Appender call
could observe initialized() == true while maxTime was still
math.MinInt64. h.appender() then computes appendableMinValidTime as
MaxTime() - chunkRange/2, which underflows to a large positive number
and rejects in-range samples with ErrOutOfBounds.
Set maxTime first, then minTime. The CAS-loser wait now spins on
minTime instead of maxTime, preserving the existing anti-deadlock
timeout. AppenderV2 shares the same gate, so this single change covers
both paths.
The TestHead_InitAppenderRace_ErrOutOfBounds test added in #17963 is now
stable across 1000 iterations (and 100 iterations under -race).
Relates to #17941
Builds on #17963
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Owen Williams <owen.williams@grafana.com>
Replace the hardcoded switch over start characters and keyword names with
a map-driven approach. durationKeywordTokens maps lowercase keyword strings
to their token types, and isDurationKeywordStartChar derives the valid start
characters from that map, so adding a new duration keyword only requires one
change instead of three.
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>