beorn7
c46074f4dd
promql: make avg aggregation more precise and less expensive
...
The basic idea here is that the previous code was always doing
incremental calculation of the mean value, which is more costly and
can be less precise. It protects against overflows, but in most cases,
an overflow doesn't happen anyway.
The other idea applied here is to expand on #14074 , where Kahan
summation was applied to sum().
With this commit, the average is calculated in a conventional way
(adding everything up and divide in the end) as long as the sum isn't
overflowing float64. This is combined with Kahan summation so that the
avg aggregation, in most cases, is really equivalent to the sum
aggregation with a following division (which is the user's expectation
as avg is supposed to be syntactic sugar for sum with a following
divison).
If the sum hits ±Inf, the calculation reverts to incremental
calculation of the mean value. Kahan summation is also applied here,
although it cannot fully compensate for the numerical errors
introduced by the incremental mean calculation. (The tests added in
this commit would fail if incremental mean calculation was always
used.)
Signed-off-by: beorn7 <beorn@grafana.com>
2024-07-10 19:20:24 +02:00
darshanime
bd4ea118e9
Allow durations for number rule
...
Signed-off-by: darshanime <deathbullet@gmail.com>
2024-07-10 15:50:22 +02:00
darshanime
cfad8ff3b2
Deprecate duration token
...
Signed-off-by: darshanime <deathbullet@gmail.com>
2024-07-10 15:49:58 +02:00
darshanime
8c8860d2d6
Allow number literals as duration
...
Signed-off-by: darshanime <deathbullet@gmail.com>
2024-07-10 15:49:30 +02:00
Filip Petkovski
acb6c1ae4b
Fix decoding buckets for native histograms in binops
...
The optimizer which detects cases where histogram buckets can be skipped
does not take into account binary expressions. This can lead to buckets
not being decoded if a metric is used with both histogram_fraction/quantile and
histogram_sum/count in the same expression.
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
2024-07-10 11:55:29 +02:00
beorn7
b5b04ddbe3
promql: add avg aggregation benchmark
...
Signed-off-by: beorn7 <beorn@grafana.com>
2024-07-04 18:59:30 +02:00
beorn7
44d8c1d182
nit: add period at end of sentence
...
Signed-off-by: beorn7 <beorn@grafana.com>
2024-07-04 17:31:39 +02:00
beorn7
9a837b7f3c
promql: Make groupedAggregation.groupCount a float64
...
It's always used as such. Let's avoid the countless conversions.
Signed-off-by: beorn7 <beorn@grafana.com>
2024-07-04 17:31:34 +02:00
JuanJo Ciarlante
c94c5b64c3
feat: add limitk() and limit_ratio() operators ( #12503 )
...
* rebase 2024-07-01, picks previous renaming to `limitk()` and `limit_ratio()`
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* gofumpt -d -extra
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* more lint fixes
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* more lint fixes+
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* put limitk() and limit_ratio() behind --enable-feature=promql-experimental-functions
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* EnableExperimentalFunctions for TestConcurrentRangeQueries() also
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* use testutil.RequireEqual to fix tests, WIP equivalent thingie for require.Contains
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* lint fix
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* moar linting
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* rebase 2024-06-19
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* re-add limit(2, metric) testing for N=2 common series subset
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* move `ratio = param` to default switch case, for better readability
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* gofumpt -d -extra util/testutil/cmp.go
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* early break when reaching k elems in limitk(), should have always been so (!)
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* small typo fix
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* no-change small break-loop rearrange for readability
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* remove IsNan(ratio) condition in switch-case, already handled as input validation
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* no-change adding some comments
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* no-change simplify fullMatrix() helper functions used for tests
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* add `limitk(-1, metric)` testcase, which is handled as any k < 1 case
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* engine_test.go: no-change create `requireCommonSeries() helper func (moving code into it) for readability
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* rebase 2024-06-21
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* engine_test.go: HAPPY NOW about its code -> reorg, create and use simpleRangeQuery() function, less lines and more readable ftW \o/
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* move limitk(), limit_ratio() testing to promql/promqltest/testdata/limit.test
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* remove stale leftover after moving tests from engine_test.go to testdata/
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* fix flaky `limit_ratio(0.5, ...)` test case
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* Update promql/engine.go
Co-authored-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* Update promql/engine.go
Co-authored-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* Update promql/engine.go
Co-authored-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* fix AddRatioSample() implementation to use a single conditional (instead of switch/case + fallback return)
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* docs/querying/operators.md: document r < 0
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* add negative limit_ratio() example to docs/querying/examples.md
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* move more extensive docu examples to docs/querying/operators.md
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* typo
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* small docu fix for poor-mans-normality-check, add it to limit.test ;)
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* limit.test: expand "Poor man's normality check" to whole eval range
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* restore mistakenly removed existing small comment
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* expand poors-man-normality-check case(s)
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* Revert "expand poors-man-normality-check case(s)"
This reverts commit f69e1603b2ebe69c0a100197cfbcf6f81644b564, indeed too
flaky 0:)
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* remove humor from docs/querying/operators.md
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* fix signoff
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* add web/ui missing changes
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* expand limit_ratio test cases, cross-fingering they'll not be flaky
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* remove flaky test
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* add missing warnings.Merge(ws) in instant-query return shortcut
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* add missing LimitK||LimitRatio case to codemirror-promql/src/parser/parser.ts
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* fix ui-lint
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* actually fix returned warnings :]
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
---------
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
Co-authored-by: Julius Volz <julius.volz@gmail.com>
2024-07-03 22:18:57 +02:00
Arve Knudsen
493e196f10
Fix bad merge
...
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2024-07-03 15:12:40 +02:00
Arve Knudsen
020b0f200a
Merge remote-tracking branch 'prometheus/main' into arve/close-engine
2024-07-03 15:12:12 +02:00
Ganesh Vernekar
3d54bcc018
Merge pull request #14362 from charleskorn/charleskorn/sum-infinity
2024-07-03 01:05:03 -04:00
Arve Knudsen
e8ae8cf012
Merge remote-tracking branch 'prometheus/main' into arve/close-engine
...
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2024-07-01 10:47:21 +02:00
Charles Korn
fd6bdf5230
Fix issue where summation of +/- infinity returns NaN instead of infinity
...
Signed-off-by: Charles Korn <charles.korn@grafana.com>
2024-06-28 11:26:54 +10:00
Björn Rabenstein
2e58d46522
Merge pull request #13662 from prometheus/nhcb
...
Native histograms custom buckets storage
2024-06-27 21:44:20 +02:00
Björn Rabenstein
19da579799
Merge pull request #12821 from rexagod/12769
...
parser: support underscores
2024-06-27 17:04:18 +02:00
Pranshu Srivastava
3c9e3ee552
parser: support underscores
...
Support underscores in numbers, namely, decimals, hexadecimals, and
exponentials.
Fixes #12769
Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
2024-06-27 19:20:52 +05:30
Bryan Boreham
b6aba4ff14
Merge pull request #14074 from bboreham/kahan-sum-sum
...
[ENHANCEMENT] PromQL: use Kahan summation for sum()
2024-06-24 11:13:26 +01:00
🌲 Harry 🌊 John 🏔
d5f6887294
Pass limit param as hint to storage.Querier
...
Signed-off-by: 🌲 Harry 🌊 John 🏔 <johrry@amazon.com>
2024-06-20 09:47:38 -07:00
Jeanette Tan
dda5f48c9e
Merge branch 'main' into nhcb-review-2
2024-06-20 22:50:00 +08:00
Jeanette Tan
fc9dc72028
remove eval_with_nhcb
...
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
2024-06-20 22:49:00 +08:00
Jeanette Tan
a6d788b1be
update missed suggested change from code review
...
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
2024-06-20 22:49:00 +08:00
Bryan Boreham
84602bbace
Merge branch 'main' into fix-matcher-string-with-empty-label-name
2024-06-19 05:56:25 -04:00
Charles Korn
aeec30f082
Convert TestTimestampFunction_StepsMoreOftenThanSamples
...
Signed-off-by: Charles Korn <charles.korn@grafana.com>
2024-06-17 16:56:56 +10:00
Charles Korn
987fa5c6a2
Convert range query test cases to test scripting language
...
Signed-off-by: Charles Korn <charles.korn@grafana.com>
2024-06-17 16:43:01 +10:00
Arve Knudsen
b7320ef636
Merge remote-tracking branch 'prometheus/main' into arve/close-engine
2024-06-14 10:51:35 +02:00
Oleg Zaytsev
03cf6141d4
Fix Matcher.String() with empty label name
...
When the label name is empty, which can happen now with quoted label
name, it should be quoted when printed as a string again.
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
2024-06-13 18:46:35 +02:00
Björn Rabenstein
08621bebe9
Merge pull request #14269 from prometheus/beorn7/histogram-test
...
promql: Add tests for histogram counter reset only in bucket
2024-06-08 16:59:47 +02:00
Jeanette Tan
b8cb12b989
rename hist to histogram according to code review
...
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
2024-06-07 20:26:41 +08:00
Jeanette Tan
4c2aa872d4
update readme for testing framework
...
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
2024-06-07 20:21:05 +08:00
Jeanette Tan
14f8dded39
Merge branch 'main' into nhcb
...
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
2024-06-07 19:17:14 +08:00
Jeanette Tan
b0e320425c
refine test rewriting regex and add validation
...
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
2024-06-07 18:50:59 +08:00
Jeanette Tan
9adc1699c3
fix according to code review
...
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
2024-06-07 18:50:59 +08:00
Charles Korn
1f988f77ff
promql: extend test scripting language to support asserting on expected error message ( #14038 )
...
Add ability to assert that a query fails with a particular error message
This also adds documentation for the test scripting language in general,
including the new feature.
Signed-off-by: Charles Korn <charles.korn@grafana.com>
---------
Signed-off-by: Charles Korn <charles.korn@grafana.com>
2024-06-06 17:56:25 +02:00
beorn7
c7fdfe8004
promql: Add tests for histogram counter reset only in bucket
...
This also exercises the "fast path" (only decoding count and sum),
i.e. where the counter reset isn't visible at all in the decoded data.
Signed-off-by: beorn7 <beorn@grafana.com>
2024-06-06 17:47:38 +02:00
Filip Petkovski
6e68046c25
Implement histogram statistics decoder ( #14097 )
...
Implement histogram statistics decoder
This commit speeds up histogram_count and histogram_sum
functions on native histograms. The idea is to have separate decoders which can be
used by the engine to only read count/sum values from histogram objects. This should help
with reducing allocations when decoding histograms, as well as with speeding up aggregations
like sum since they will be done on floats and not on histogram objects.
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
---------
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
2024-06-06 17:17:13 +02:00
Arve Knudsen
e57aac8084
Merge remote-tracking branch 'prometheus/main' into arve/close-engine
...
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2024-06-05 11:37:44 +02:00
Charles Korn
24ef000025
Merge branch 'main' into sort-matrix-series
...
# Conflicts:
# promql/engine_test.go
2024-05-31 12:44:27 +10:00
Arve Knudsen
0cc99e677a
promql.Engine: Add Close method
...
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2024-05-28 12:01:47 +02:00
Arve Knudsen
f3b8750339
Join errors
...
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2024-05-27 17:14:17 +02:00
Arve Knudsen
7b56353090
Merge remote-tracking branch 'prometheus/main' into arve/query-logger-munmap
2024-05-27 17:08:33 +02:00
Björn Rabenstein
114dc5c393
Merge pull request #13638 from NeerajGartia21/promql-test
...
Converts existing native histogram unit tests to the PromQL testing framework
2024-05-19 19:35:36 +02:00
Arve Knudsen
0f01d4b336
Fix flaky test
...
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2024-05-15 21:58:56 +02:00
Arve Knudsen
bf8d88f326
Merge remote-tracking branch 'origin/main' into arve/query-logger-munmap
2024-05-15 21:02:03 +02:00
Oleksandr Redko
f10c3454e9
Enable perfsprint linter and fix up code
...
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
2024-05-15 17:51:05 +03:00
Björn Rabenstein
e6be4240be
Merge pull request #14068 from colega/quote-label-name-in-matchers-when-needed
...
Bugfix: quote label name in matchers when needed
2024-05-14 17:18:58 +02:00
Jeanette Tan
f028496133
Merge branch 'main' into nhcb
...
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
2024-05-14 16:20:15 +08:00
Neeraj Gartia
661856cb65
removes the added tests from engine_test.go
...
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
2024-05-13 22:58:25 +05:30
Neeraj Gartia
6119124d0e
some nits
...
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
2024-05-13 22:55:38 +05:30
Neeraj Gartia
adf5a36c1e
adds test for sum, count, stddev, stdvar, quantile and fraction func to promql testing framework
...
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
2024-05-13 22:55:38 +05:30
Neeraj Gartia
8b838a05d9
adds test for native histogram rate func in promql testing framework
...
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
2024-05-13 22:55:38 +05:30
Neeraj Gartia
548bd9d6fb
adds TestNativeHistogramRate func to promql test framework
...
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
2024-05-13 22:55:38 +05:30
Charles Korn
0e934dba8e
Capture timing information while sorting
...
Signed-off-by: Charles Korn <charles.korn@grafana.com>
2024-05-13 19:47:18 +10:00
Charles Korn
036c87223c
Ensure series in matrix values returned for instant queries are always sorted
...
Signed-off-by: Charles Korn <charles.korn@grafana.com>
2024-05-13 11:03:15 +10:00
Charles Korn
a4381608a0
Add failing test case
...
Signed-off-by: Charles Korn <charles.korn@grafana.com>
2024-05-13 11:03:14 +10:00
Bryan Boreham
ea82b49c33
[ENHANCEMENT] PromQL: use Kahan summation for sum()
...
This can give a more precise result, by keeping a separate running
compensation value to accumulate small errors.
See https://en.wikipedia.org/wiki/Kahan_summation_algorithm
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-05-09 14:29:38 +01:00
Arve Knudsen
aabe4d6e4a
promql.ActiveQueryTracker: Unmap mmapped file when done
...
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2024-05-09 14:27:29 +02:00
Bryan Boreham
3fd24d1cd7
Merge pull request #13999 from bboreham/extract-promqltest
...
[Test] Extract most PromQL test code into separate packages
2024-05-09 13:23:11 +01:00
Bryan Boreham
786e0e706c
test: PromQL: stop using internal fields of engine
...
* set enablePerStepStats and lookback duration via
`NewTestEngine` parameters.
* check maxSamples by recreating query engine
* check lookback without modifying internals
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-05-08 19:58:41 +01:00
Bryan Boreham
0dbfd20b69
test: move most PromQL tests into separate test package
...
So that they can import promqltest which imports promql.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-05-08 16:28:56 +01:00
Bryan Boreham
4a72607c4a
refactor: extract some PromQL Engine tests which use unexported structs
...
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-05-08 16:27:17 +01:00
Bryan Boreham
e7c77f7b40
promql: export NewTestQuery
...
So that tests can call it from another package.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-05-08 16:08:04 +01:00
Bryan Boreham
babfcfdd91
refactor: Move NewTestEngine into promqltest
...
And export `DefaultMaxSamplesPerQuery` so callers can replicate previous
behaviour.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-05-08 16:07:28 +01:00
Oleg Zaytsev
dabd789fd5
Quote label name in matchers when needed
...
When the label name of a matcher contains non-standard characters, like
a dot, or starts with a digit, it should be quoted.
If it's not quoted, then `VectorSelector.String()` isn't a valid PromQL.
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
2024-05-08 16:58:51 +02:00
Bryan Boreham
b3c15d2246
test: clean up promqltest package references
...
So it nearly compiles.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-05-08 13:42:55 +01:00
Bryan Boreham
9aa321d672
test: make field initializers explicit
...
Lint started complaining after I moved the file.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-05-08 13:42:55 +01:00
Bryan Boreham
ccf73266f0
test: move promqltest tests together with the implementation
...
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-05-08 13:42:55 +01:00
Bryan Boreham
11b27d5d22
test: move test files into new promqltest package
...
So that promql package does not bring in test-only dependencies.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-05-08 13:42:55 +01:00
Bryan Boreham
a6e427660a
test: check for @-modifier without using engine internals
...
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-05-08 13:42:55 +01:00
Bryan Boreham
2b0c87b1b6
test: turn TestKahanSum into scripted test
...
This saves having a function solely to call kahanSumInc.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-05-08 13:42:55 +01:00
Bryan Boreham
a1af3c27d4
refactor: extract almost.Equal() to new package
...
To avoid a circular reference between promql and promqltest.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-05-08 13:42:10 +01:00
zenador
545a7e48f9
[nhcb branch] Enhance unit test framework for nhcb and warnings ( #14009 )
...
* process custom values in histogram unit test framework
* check for warnings when evaluating in unit test framework
* add test cases for custom buckets in test framework
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
2024-05-08 13:58:24 +02:00
Jeanette Tan
796b1bbfde
Merge branch 'main' into nhcb
...
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
2024-05-08 19:11:39 +08:00
Arve Knudsen
a25160e6a4
[REFACTOR] PromQL: simplify rangeEvalTimestampFunctionOverVectorSelector ( #14021 )
...
The function `rangeEvalTimestampFunctionOverVectorSelector` appeared to be checking histogram size, however the value it used was always 0 due to subtle variable shadowing.
However we don't need to pass sample values to the `timestamp` function, since the latter only cares about timestamps. This also affects peak sample count in statistics, since we are no longer copying histogram samples.
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2024-05-08 10:39:44 +01:00
Oleg Zaytsev
4b7a44c7a0
Fix parser.VectorSelector.String()
with empty name matcher ( #14015 )
...
The check fell into "this matcher equals vector selector's name" case when vector selector doesn't have a name and the matcher is an explicit matcher for an empty __name__ label.
To provide some context about why this is important: some downstream projects use the promql.Parse(expr.String()) to clone an expression's AST, and with this bug that matcher disappears in the cloning.
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
2024-05-06 11:51:08 +02:00
guangwu
9fda9443d4
fix(promql/query_logger): close file in error handling ( #13948 )
...
Signed-off-by: guoguangwu <guoguangwug@gmail.com>
2024-04-30 10:47:10 +02:00
György Krajcsovits
bcafa5f1f9
Merge remote-tracking branch 'upstream/main' into update-nhcb
2024-04-24 11:06:59 +02:00
zenador
81862aabd7
[nhcb branch] Add basic unit tests for native histograms with custom buckets converted from classic histograms ( #13794 )
...
* modify unit test framework to automatically generate native histograms with custom buckets from classic histogram series
* add very basic tests for classic histogram converted into native histogram with custom bounds
* fix histogram_quantile for native histograms with custom buckets
* make loading with nhcb explicit
* evaluate native histograms with custom buckets on queries with explicit keyword
* use regex replacer
* use temp histogram struct for automatically loading converted nhcb
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
Signed-off-by: George Krajcsovits <krajorama@users.noreply.github.com>
2024-04-24 09:36:05 +02:00
Owen Williams
4a6f8704ef
parser: remake generated_parser output ( #13923 )
...
In a previous PR, the generated parser was created using an old version of goyacc.
Also adds -l to disable line directives, which fixes debug processing and reduces diffs at the expense of making it more difficult to reason about the generated output.
Signed-off-by: Owen Williams <owen.williams@grafana.com>
2024-04-13 12:59:54 +02:00
Neeraj Gartia
612de026da
Adds Inf and NaN as Numbers to Histogram in Promql Testing Framework ( #13916 )
...
includes Inf and NaN as numbers to histogram
---------
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
Signed-off-by: Björn Rabenstein <github@rabenste.in>
Co-authored-by: Björn Rabenstein <github@rabenste.in>
2024-04-11 12:53:28 +02:00
Matthieu MOREL
6f595c6762
golangci-lint: enable whitespace linter ( #13905 )
...
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2024-04-11 09:27:54 +01:00
Bryan Boreham
12961c6a37
promql: refactor: eliminate one 'else'
...
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
0ac927515b
promql: move group-seen into group struct
...
Save allocating an auxilliary array.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
7499d90913
promql: remove pointer to aggregation groups
...
Just allocate in one slice.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
cfbeb6681b
promql: re-use one heap for topk and bottomk
...
Slightly ugly casting saves memory.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
5e3914a27c
promql: remove histogramMean from groupedAggregation
...
Re-use histogramValue since we don't need them separately.
Tidy up initialization.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
2cf3c9de8f
promql: store labels per-group only for count_values
...
This saves memory in other kinds of aggregation.
We don't need `orderedResult` in `aggregationCountValues`; the ordering
is not guaranteed.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
185290a0d2
promql: pull checking of q and k out of loop
...
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
4584f67e17
promql: inline nextSample function
...
Move Sample out of loop to reduce allocations, otherwise it escapes to
the heap.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
526ce4ee7a
promql: simplify data collection in aggregations
...
We don't need a Sample, just the float and histogram values.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
2f03acbafc
promql: refactor: split topk/bottomk from sum/avg/etc
...
They aggregate results in different ways.
topk/bottomk don't consider histograms so can simplify data collection.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
74eed67ef6
promql: refactor: pull fetching input data out of rangeEvalAgg
...
This is a cleaner split of responsibilities.
We now check the sample count after calling rangeEvalAgg.
Changed re-use of samples to use `Clone` and `defer`.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
602eb69edf
promql: refactor: extract function nextSample
...
With sub-function nextValues which we shall use shortly.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
eb41e770b7
promql: refactor: extract function addToSeries
...
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
53a3138eeb
promql aggregations: pre-generate mapping from inputs to outputs
...
So we don't have to re-create it on every time step.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
cb6c4b3092
promql: simplify k/q parameter to topk/bottomk/quantile
...
Pass it as a float64 not as interface{}.
Make k a simple int, since that is the parameter to make().
Pull invalid quantile warning out of the loop.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
b3bda7df4b
promql: aggregations: skip copying input to a Vector
...
We can work directly from the inputMatrix on each timestep.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
c9b6c4c55a
promql: aggregations: output directly to matrix for instant queries
...
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
3851b74db1
promql: aggregations: skip result vector in range queries
...
Adjust test to match the lower count, since samples in the vector
are no longer counted.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00
Bryan Boreham
59548b8a0b
promql: refactor: move collection of results into aggregation()
...
We don't need to check for duplicates as aggregation cannot generate them.
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-04-05 15:47:54 +01:00