prometheus/web/ui/module/lezer-promql/src/tokens.js

90 lines
1.8 KiB
JavaScript
Raw Normal View History

// Copyright 2021 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import {
And,
Avg,
Atan2,
Bool,
Bottomk,
By,
Count,
CountValues,
End,
Group,
GroupLeft,
GroupRight,
Ignoring,
inf,
Max,
Min,
nan,
Offset,
On,
Or,
Quantile,
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 <[email protected]> * gofumpt -d -extra Signed-off-by: JuanJo Ciarlante <[email protected]> * more lint fixes Signed-off-by: JuanJo Ciarlante <[email protected]> * more lint fixes+ Signed-off-by: JuanJo Ciarlante <[email protected]> * put limitk() and limit_ratio() behind --enable-feature=promql-experimental-functions Signed-off-by: JuanJo Ciarlante <[email protected]> * EnableExperimentalFunctions for TestConcurrentRangeQueries() also Signed-off-by: JuanJo Ciarlante <[email protected]> * use testutil.RequireEqual to fix tests, WIP equivalent thingie for require.Contains Signed-off-by: JuanJo Ciarlante <[email protected]> * lint fix Signed-off-by: JuanJo Ciarlante <[email protected]> * moar linting Signed-off-by: JuanJo Ciarlante <[email protected]> * rebase 2024-06-19 Signed-off-by: JuanJo Ciarlante <[email protected]> * re-add limit(2, metric) testing for N=2 common series subset Signed-off-by: JuanJo Ciarlante <[email protected]> * move `ratio = param` to default switch case, for better readability Signed-off-by: JuanJo Ciarlante <[email protected]> * gofumpt -d -extra util/testutil/cmp.go Signed-off-by: JuanJo Ciarlante <[email protected]> * early break when reaching k elems in limitk(), should have always been so (!) Signed-off-by: JuanJo Ciarlante <[email protected]> * small typo fix Signed-off-by: JuanJo Ciarlante <[email protected]> * no-change small break-loop rearrange for readability Signed-off-by: JuanJo Ciarlante <[email protected]> * remove IsNan(ratio) condition in switch-case, already handled as input validation Signed-off-by: JuanJo Ciarlante <[email protected]> * no-change adding some comments Signed-off-by: JuanJo Ciarlante <[email protected]> * no-change simplify fullMatrix() helper functions used for tests Signed-off-by: JuanJo Ciarlante <[email protected]> * add `limitk(-1, metric)` testcase, which is handled as any k < 1 case Signed-off-by: JuanJo Ciarlante <[email protected]> * engine_test.go: no-change create `requireCommonSeries() helper func (moving code into it) for readability Signed-off-by: JuanJo Ciarlante <[email protected]> * rebase 2024-06-21 Signed-off-by: JuanJo Ciarlante <[email protected]> * 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 <[email protected]> * move limitk(), limit_ratio() testing to promql/promqltest/testdata/limit.test Signed-off-by: JuanJo Ciarlante <[email protected]> * remove stale leftover after moving tests from engine_test.go to testdata/ Signed-off-by: JuanJo Ciarlante <[email protected]> * fix flaky `limit_ratio(0.5, ...)` test case Signed-off-by: JuanJo Ciarlante <[email protected]> * Update promql/engine.go Co-authored-by: Julius Volz <[email protected]> Signed-off-by: JuanJo Ciarlante <[email protected]> * Update promql/engine.go Co-authored-by: Julius Volz <[email protected]> Signed-off-by: JuanJo Ciarlante <[email protected]> * Update promql/engine.go Co-authored-by: Julius Volz <[email protected]> Signed-off-by: JuanJo Ciarlante <[email protected]> * fix AddRatioSample() implementation to use a single conditional (instead of switch/case + fallback return) Signed-off-by: JuanJo Ciarlante <[email protected]> * docs/querying/operators.md: document r < 0 Signed-off-by: JuanJo Ciarlante <[email protected]> * add negative limit_ratio() example to docs/querying/examples.md Signed-off-by: JuanJo Ciarlante <[email protected]> * move more extensive docu examples to docs/querying/operators.md Signed-off-by: JuanJo Ciarlante <[email protected]> * typo Signed-off-by: JuanJo Ciarlante <[email protected]> * small docu fix for poor-mans-normality-check, add it to limit.test ;) Signed-off-by: JuanJo Ciarlante <[email protected]> * limit.test: expand "Poor man's normality check" to whole eval range Signed-off-by: JuanJo Ciarlante <[email protected]> * restore mistakenly removed existing small comment Signed-off-by: JuanJo Ciarlante <[email protected]> * expand poors-man-normality-check case(s) Signed-off-by: JuanJo Ciarlante <[email protected]> * Revert "expand poors-man-normality-check case(s)" This reverts commit f69e1603b2ebe69c0a100197cfbcf6f81644b564, indeed too flaky 0:) Signed-off-by: JuanJo Ciarlante <[email protected]> * remove humor from docs/querying/operators.md Signed-off-by: JuanJo Ciarlante <[email protected]> * fix signoff Signed-off-by: JuanJo Ciarlante <[email protected]> * add web/ui missing changes Signed-off-by: JuanJo Ciarlante <[email protected]> * expand limit_ratio test cases, cross-fingering they'll not be flaky Signed-off-by: JuanJo Ciarlante <[email protected]> * remove flaky test Signed-off-by: JuanJo Ciarlante <[email protected]> * add missing warnings.Merge(ws) in instant-query return shortcut Signed-off-by: JuanJo Ciarlante <[email protected]> * add missing LimitK||LimitRatio case to codemirror-promql/src/parser/parser.ts Signed-off-by: JuanJo Ciarlante <[email protected]> * fix ui-lint Signed-off-by: JuanJo Ciarlante <[email protected]> * actually fix returned warnings :] Signed-off-by: JuanJo Ciarlante <[email protected]> --------- Signed-off-by: JuanJo Ciarlante <[email protected]> Co-authored-by: Julius Volz <[email protected]>
2024-07-03 13:18:57 -07:00
LimitK,
LimitRatio,
Start,
Stddev,
Stdvar,
Sum,
Topk,
Unless,
Without,
} from './parser.terms.js';
const keywordTokens = {
inf: inf,
nan: nan,
bool: Bool,
ignoring: Ignoring,
on: On,
group_left: GroupLeft,
group_right: GroupRight,
offset: Offset,
};
export const specializeIdentifier = (value, stack) => {
return keywordTokens[value.toLowerCase()] || -1;
};
const contextualKeywordTokens = {
avg: Avg,
atan2: Atan2,
bottomk: Bottomk,
count: Count,
count_values: CountValues,
group: Group,
max: Max,
min: Min,
quantile: Quantile,
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 <[email protected]> * gofumpt -d -extra Signed-off-by: JuanJo Ciarlante <[email protected]> * more lint fixes Signed-off-by: JuanJo Ciarlante <[email protected]> * more lint fixes+ Signed-off-by: JuanJo Ciarlante <[email protected]> * put limitk() and limit_ratio() behind --enable-feature=promql-experimental-functions Signed-off-by: JuanJo Ciarlante <[email protected]> * EnableExperimentalFunctions for TestConcurrentRangeQueries() also Signed-off-by: JuanJo Ciarlante <[email protected]> * use testutil.RequireEqual to fix tests, WIP equivalent thingie for require.Contains Signed-off-by: JuanJo Ciarlante <[email protected]> * lint fix Signed-off-by: JuanJo Ciarlante <[email protected]> * moar linting Signed-off-by: JuanJo Ciarlante <[email protected]> * rebase 2024-06-19 Signed-off-by: JuanJo Ciarlante <[email protected]> * re-add limit(2, metric) testing for N=2 common series subset Signed-off-by: JuanJo Ciarlante <[email protected]> * move `ratio = param` to default switch case, for better readability Signed-off-by: JuanJo Ciarlante <[email protected]> * gofumpt -d -extra util/testutil/cmp.go Signed-off-by: JuanJo Ciarlante <[email protected]> * early break when reaching k elems in limitk(), should have always been so (!) Signed-off-by: JuanJo Ciarlante <[email protected]> * small typo fix Signed-off-by: JuanJo Ciarlante <[email protected]> * no-change small break-loop rearrange for readability Signed-off-by: JuanJo Ciarlante <[email protected]> * remove IsNan(ratio) condition in switch-case, already handled as input validation Signed-off-by: JuanJo Ciarlante <[email protected]> * no-change adding some comments Signed-off-by: JuanJo Ciarlante <[email protected]> * no-change simplify fullMatrix() helper functions used for tests Signed-off-by: JuanJo Ciarlante <[email protected]> * add `limitk(-1, metric)` testcase, which is handled as any k < 1 case Signed-off-by: JuanJo Ciarlante <[email protected]> * engine_test.go: no-change create `requireCommonSeries() helper func (moving code into it) for readability Signed-off-by: JuanJo Ciarlante <[email protected]> * rebase 2024-06-21 Signed-off-by: JuanJo Ciarlante <[email protected]> * 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 <[email protected]> * move limitk(), limit_ratio() testing to promql/promqltest/testdata/limit.test Signed-off-by: JuanJo Ciarlante <[email protected]> * remove stale leftover after moving tests from engine_test.go to testdata/ Signed-off-by: JuanJo Ciarlante <[email protected]> * fix flaky `limit_ratio(0.5, ...)` test case Signed-off-by: JuanJo Ciarlante <[email protected]> * Update promql/engine.go Co-authored-by: Julius Volz <[email protected]> Signed-off-by: JuanJo Ciarlante <[email protected]> * Update promql/engine.go Co-authored-by: Julius Volz <[email protected]> Signed-off-by: JuanJo Ciarlante <[email protected]> * Update promql/engine.go Co-authored-by: Julius Volz <[email protected]> Signed-off-by: JuanJo Ciarlante <[email protected]> * fix AddRatioSample() implementation to use a single conditional (instead of switch/case + fallback return) Signed-off-by: JuanJo Ciarlante <[email protected]> * docs/querying/operators.md: document r < 0 Signed-off-by: JuanJo Ciarlante <[email protected]> * add negative limit_ratio() example to docs/querying/examples.md Signed-off-by: JuanJo Ciarlante <[email protected]> * move more extensive docu examples to docs/querying/operators.md Signed-off-by: JuanJo Ciarlante <[email protected]> * typo Signed-off-by: JuanJo Ciarlante <[email protected]> * small docu fix for poor-mans-normality-check, add it to limit.test ;) Signed-off-by: JuanJo Ciarlante <[email protected]> * limit.test: expand "Poor man's normality check" to whole eval range Signed-off-by: JuanJo Ciarlante <[email protected]> * restore mistakenly removed existing small comment Signed-off-by: JuanJo Ciarlante <[email protected]> * expand poors-man-normality-check case(s) Signed-off-by: JuanJo Ciarlante <[email protected]> * Revert "expand poors-man-normality-check case(s)" This reverts commit f69e1603b2ebe69c0a100197cfbcf6f81644b564, indeed too flaky 0:) Signed-off-by: JuanJo Ciarlante <[email protected]> * remove humor from docs/querying/operators.md Signed-off-by: JuanJo Ciarlante <[email protected]> * fix signoff Signed-off-by: JuanJo Ciarlante <[email protected]> * add web/ui missing changes Signed-off-by: JuanJo Ciarlante <[email protected]> * expand limit_ratio test cases, cross-fingering they'll not be flaky Signed-off-by: JuanJo Ciarlante <[email protected]> * remove flaky test Signed-off-by: JuanJo Ciarlante <[email protected]> * add missing warnings.Merge(ws) in instant-query return shortcut Signed-off-by: JuanJo Ciarlante <[email protected]> * add missing LimitK||LimitRatio case to codemirror-promql/src/parser/parser.ts Signed-off-by: JuanJo Ciarlante <[email protected]> * fix ui-lint Signed-off-by: JuanJo Ciarlante <[email protected]> * actually fix returned warnings :] Signed-off-by: JuanJo Ciarlante <[email protected]> --------- Signed-off-by: JuanJo Ciarlante <[email protected]> Co-authored-by: Julius Volz <[email protected]>
2024-07-03 13:18:57 -07:00
limitk: LimitK,
limit_ratio: LimitRatio,
stddev: Stddev,
stdvar: Stdvar,
sum: Sum,
topk: Topk,
by: By,
without: Without,
and: And,
or: Or,
unless: Unless,
start: Start,
end: End,
};
export const extendIdentifier = (value, stack) => {
return contextualKeywordTokens[value.toLowerCase()] || -1;
};