mirror of
https://github.com/prometheus/prometheus
synced 2026-04-20 14:31:49 +08:00
Merge pull request #18498 from ldufr/revive-emit-warning-when-sort-is-used-range
Some checks failed
buf.build / lint and publish (push) Has been cancelled
CI / Go tests (push) Has been cancelled
CI / More Go tests (push) Has been cancelled
CI / Go tests for Prometheus upgrades and downgrades (push) Has been cancelled
CI / Go tests with previous Go version (push) Has been cancelled
CI / UI tests (push) Has been cancelled
CI / Go tests on Windows (push) Has been cancelled
CI / Mixins tests (push) Has been cancelled
CI / Compliance testing (push) Has been cancelled
CI / Build Prometheus for common architectures (0) (push) Has been cancelled
CI / Build Prometheus for common architectures (1) (push) Has been cancelled
CI / Build Prometheus for common architectures (2) (push) Has been cancelled
CI / Build Prometheus for all architectures (0) (push) Has been cancelled
CI / Build Prometheus for all architectures (1) (push) Has been cancelled
CI / Build Prometheus for all architectures (10) (push) Has been cancelled
CI / Build Prometheus for all architectures (11) (push) Has been cancelled
CI / Build Prometheus for all architectures (2) (push) Has been cancelled
CI / Build Prometheus for all architectures (3) (push) Has been cancelled
CI / Build Prometheus for all architectures (4) (push) Has been cancelled
CI / Build Prometheus for all architectures (5) (push) Has been cancelled
CI / Build Prometheus for all architectures (6) (push) Has been cancelled
CI / Build Prometheus for all architectures (7) (push) Has been cancelled
CI / Build Prometheus for all architectures (8) (push) Has been cancelled
CI / Build Prometheus for all architectures (9) (push) Has been cancelled
CI / Check generated parser (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
CI / fuzzing (push) Has been cancelled
CI / codeql (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CI / Report status of build Prometheus for all architectures (push) Has been cancelled
CI / Publish main branch artifacts (push) Has been cancelled
CI / Publish release artefacts (push) Has been cancelled
CI / Publish UI on npm Registry (push) Has been cancelled
Sync repo files / repo_sync (push) Has been cancelled
Stale Check / stale (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Some checks failed
buf.build / lint and publish (push) Has been cancelled
CI / Go tests (push) Has been cancelled
CI / More Go tests (push) Has been cancelled
CI / Go tests for Prometheus upgrades and downgrades (push) Has been cancelled
CI / Go tests with previous Go version (push) Has been cancelled
CI / UI tests (push) Has been cancelled
CI / Go tests on Windows (push) Has been cancelled
CI / Mixins tests (push) Has been cancelled
CI / Compliance testing (push) Has been cancelled
CI / Build Prometheus for common architectures (0) (push) Has been cancelled
CI / Build Prometheus for common architectures (1) (push) Has been cancelled
CI / Build Prometheus for common architectures (2) (push) Has been cancelled
CI / Build Prometheus for all architectures (0) (push) Has been cancelled
CI / Build Prometheus for all architectures (1) (push) Has been cancelled
CI / Build Prometheus for all architectures (10) (push) Has been cancelled
CI / Build Prometheus for all architectures (11) (push) Has been cancelled
CI / Build Prometheus for all architectures (2) (push) Has been cancelled
CI / Build Prometheus for all architectures (3) (push) Has been cancelled
CI / Build Prometheus for all architectures (4) (push) Has been cancelled
CI / Build Prometheus for all architectures (5) (push) Has been cancelled
CI / Build Prometheus for all architectures (6) (push) Has been cancelled
CI / Build Prometheus for all architectures (7) (push) Has been cancelled
CI / Build Prometheus for all architectures (8) (push) Has been cancelled
CI / Build Prometheus for all architectures (9) (push) Has been cancelled
CI / Check generated parser (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
CI / fuzzing (push) Has been cancelled
CI / codeql (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CI / Report status of build Prometheus for all architectures (push) Has been cancelled
CI / Publish main branch artifacts (push) Has been cancelled
CI / Publish release artefacts (push) Has been cancelled
CI / Publish UI on npm Registry (push) Has been cancelled
Sync repo files / repo_sync (push) Has been cancelled
Stale Check / stale (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
annotations: add warning for ineffective sort in range queries
This commit is contained in:
@@ -2010,6 +2010,11 @@ func (ev *evaluator) eval(ctx context.Context, expr parser.Expr) (parser.Value,
|
||||
return ev.evalInfo(ctx, e.Args)
|
||||
}
|
||||
|
||||
// Emit a warning when sort is used for range queries.
|
||||
if (e.Func.Name == "sort" || e.Func.Name == "sort_desc" || e.Func.Name == "sort_by_label" || e.Func.Name == "sort_by_label_desc") && ev.startTimestamp != ev.endTimestamp {
|
||||
warnings.Add(annotations.NewSortInRangeQueryWarning(e.PositionRange()))
|
||||
}
|
||||
|
||||
if !matrixArg {
|
||||
// Does not have a matrix argument.
|
||||
return ev.rangeEval(ctx, nil, func(v []Vector, _ Matrix, _ [][]EvalSeriesHelper, enh *EvalNodeHelper) (Vector, annotations.Annotations) {
|
||||
|
||||
65
promql/promqltest/testdata/histograms.test
vendored
65
promql/promqltest/testdata/histograms.test
vendored
@@ -1169,3 +1169,68 @@ eval instant at 0 histogram_fraction(-Inf, 1, series)
|
||||
expect no_info
|
||||
expect warn msg: PromQL warning: vector contains a mix of classic and native histograms for metric name "series"
|
||||
# Should return no results.
|
||||
|
||||
clear
|
||||
|
||||
# Test histogram_quantile(s) and histogram_fraction warns about missing "le"
|
||||
load 1m
|
||||
series{ale="0.1"} 2
|
||||
|
||||
eval instant at 0 histogram_quantile(0.8, series)
|
||||
expect no_info
|
||||
expect warn msg: PromQL warning: bucket label "le" is missing or has a malformed value of "" for metric name "series"
|
||||
# Should return no results.
|
||||
|
||||
eval instant at 0 histogram_quantiles(series, "q", 0.1, 0.2)
|
||||
expect no_info
|
||||
expect warn msg: PromQL warning: bucket label "le" is missing or has a malformed value of "" for metric name "series"
|
||||
# Should return no results.
|
||||
|
||||
eval instant at 0 histogram_fraction(-Inf, 1, series)
|
||||
expect no_info
|
||||
expect warn msg: PromQL warning: bucket label "le" is missing or has a malformed value of "" for metric name "series"
|
||||
# Should return no results.
|
||||
|
||||
clear
|
||||
|
||||
# Test histogram_quantile(s) and histogram_fraction warns about malformated "le"
|
||||
load 1m
|
||||
series{le="Hello World"} 2
|
||||
|
||||
eval instant at 0 histogram_quantile(0.8, series)
|
||||
expect no_info
|
||||
expect warn msg: PromQL warning: bucket label "le" is missing or has a malformed value of "Hello World" for metric name "series"
|
||||
# Should return no results.
|
||||
|
||||
eval instant at 0 histogram_quantiles(series, "q", 0.1, 0.2)
|
||||
expect no_info
|
||||
expect warn msg: PromQL warning: bucket label "le" is missing or has a malformed value of "Hello World" for metric name "series"
|
||||
# Should return no results.
|
||||
|
||||
eval instant at 0 histogram_fraction(-Inf, 1, series)
|
||||
expect no_info
|
||||
expect warn msg: PromQL warning: bucket label "le" is missing or has a malformed value of "Hello World" for metric name "series"
|
||||
# Should return no results.
|
||||
|
||||
clear
|
||||
|
||||
# Test histogram_quantile(s) and histogram_fraction warns about mixed classic and native histogram
|
||||
load 1m
|
||||
series{le="0.1"} 1
|
||||
series{le="1"} 2
|
||||
series{} {{schema:0 count:10 sum:50 buckets:[1 2 3]}}
|
||||
|
||||
eval instant at 0 histogram_quantile(0.8, series)
|
||||
expect no_info
|
||||
expect warn msg: PromQL warning: vector contains a mix of classic and native histograms for metric name "series"
|
||||
# Should return no results.
|
||||
|
||||
eval instant at 0 histogram_quantiles(series, "q", 0.1, 0.2)
|
||||
expect no_info
|
||||
expect warn msg: PromQL warning: vector contains a mix of classic and native histograms for metric name "series"
|
||||
# Should return no results.
|
||||
|
||||
eval instant at 0 histogram_fraction(-Inf, 1, series)
|
||||
expect no_info
|
||||
expect warn msg: PromQL warning: vector contains a mix of classic and native histograms for metric name "series"
|
||||
# Should return no results.
|
||||
|
||||
17
promql/promqltest/testdata/range_queries.test
vendored
17
promql/promqltest/testdata/range_queries.test
vendored
@@ -104,4 +104,19 @@ eval instant at 1m some_nonexistent_metric[1m]
|
||||
expect range vector from 10s to 1m step 10s
|
||||
|
||||
eval instant at 10m some_metric[1m]
|
||||
expect range vector from 9m10s to 10m step 1m
|
||||
expect range vector from 9m10s to 10m step 1m
|
||||
|
||||
eval range from 1m to 2m step 1m sort(series)
|
||||
expect warn msg: PromQL warning: sort is ineffective for range queries since results are always ordered by labels
|
||||
|
||||
eval range from 1m to 2m step 1m sort_desc(series)
|
||||
expect warn msg: PromQL warning: sort is ineffective for range queries since results are always ordered by labels
|
||||
|
||||
eval range from 1m to 2m step 1m sort_by_label(series)
|
||||
expect warn msg: PromQL warning: sort is ineffective for range queries since results are always ordered by labels
|
||||
|
||||
eval range from 1m to 2m step 1m sort_by_label_desc(series)
|
||||
expect warn msg: PromQL warning: sort is ineffective for range queries since results are always ordered by labels
|
||||
|
||||
eval range from 1m to 2m step 1m sum(sort(series))
|
||||
expect warn msg: PromQL warning: sort is ineffective for range queries since results are always ordered by labels
|
||||
|
||||
@@ -156,6 +156,7 @@ var (
|
||||
NativeHistogramNotGaugeWarning = fmt.Errorf("%w: this native histogram metric is not a gauge:", PromQLWarning)
|
||||
MixedExponentialCustomHistogramsWarning = fmt.Errorf("%w: vector contains a mix of histograms with exponential and custom buckets schemas for metric name", PromQLWarning)
|
||||
IncompatibleBucketLayoutInBinOpWarning = fmt.Errorf("%w: incompatible bucket layout encountered for binary operator", PromQLWarning)
|
||||
SortInRangeQueryWarning = fmt.Errorf("%w: sort is ineffective for range queries since results are always ordered by labels", PromQLWarning)
|
||||
|
||||
PossibleNonCounterInfo = fmt.Errorf("%w: metric might not be a counter, name does not end in _total/_sum/_count/_bucket:", PromQLInfo)
|
||||
PossibleNonCounterLabelInfo = fmt.Errorf("%w: metric might not be a counter, __type__ label is not set to %q or %q", PromQLInfo, model.MetricTypeCounter, model.MetricTypeHistogram)
|
||||
@@ -424,6 +425,15 @@ func NewIncompatibleBucketLayoutInBinOpWarning(operator string, pos posrange.Pos
|
||||
}
|
||||
}
|
||||
|
||||
// NewSortInRangeQueryWarning is used when sort or sort_desc functions are used
|
||||
// in range queries where they have no effect since results are always ordered by labels.
|
||||
func NewSortInRangeQueryWarning(pos posrange.PositionRange) error {
|
||||
return &annoErr{
|
||||
PositionRange: pos,
|
||||
Err: SortInRangeQueryWarning,
|
||||
}
|
||||
}
|
||||
|
||||
func NewNativeHistogramQuantileNaNResultInfo(metricName string, pos posrange.PositionRange) error {
|
||||
return &annoErr{
|
||||
PositionRange: pos,
|
||||
|
||||
Reference in New Issue
Block a user