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>
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>
The test called ruleManager.start() before ruleManager.Update(), so the
group goroutine skipped the <-m.block wait and began evaluating
immediately. The fixture has a recording rule, and if the first 10s
tick fired before defer ruleManager.Stop() ran, Eval was called with a
nil QueryFunc (and nil Appendable), causing a nil pointer dereference.
Fix by providing Appendable, Queryable, and QueryFunc in the
ManagerOptions, matching the pattern used by other tests that load real
rule files and start the manager.
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
The ClientSecret field in OAuthConfig was typed as plain string,
causing it to be exposed in plaintext via the /-/config HTTP endpoint.
Change it to config_util.Secret so Prometheus redacts it as <secret>.
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
I have seen some flakiness in these tests, including timeouts. LLM suggested these fixes to make them more deterministic. They look good to me.
Signed-off-by: Owen Williams <owen.williams@grafana.com>
* perf(PromQL): make kahansum.Inc inlineable on Go 1.26
Signed-off-by: linasm <linas.medziunas@gmail.com>
Signed-off-by: Linas Medžiūnas <linasm@users.noreply.github.com>
Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>