created docker-prometheus compose file and edited the Prometheus yml file
This commit is contained in:
94
prom/promql/testdata/functions.test
vendored
Normal file
94
prom/promql/testdata/functions.test
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
# Testdata for resets() and changes().
|
||||
load 5m
|
||||
http_requests{path="/foo"} 1 2 3 0 1 0 0 1 2 0
|
||||
http_requests{path="/bar"} 1 2 3 4 5 1 2 3 4 5
|
||||
http_requests{path="/biz"} 0 0 0 0 0 1 1 1 1 1
|
||||
|
||||
# Tests for resets().
|
||||
eval instant at 50m resets(http_requests[5m])
|
||||
{path="/foo"} 0
|
||||
{path="/bar"} 0
|
||||
{path="/biz"} 0
|
||||
|
||||
eval instant at 50m resets(http_requests[20m])
|
||||
{path="/foo"} 1
|
||||
{path="/bar"} 0
|
||||
{path="/biz"} 0
|
||||
|
||||
eval instant at 50m resets(http_requests[30m])
|
||||
{path="/foo"} 2
|
||||
{path="/bar"} 1
|
||||
{path="/biz"} 0
|
||||
|
||||
eval instant at 50m resets(http_requests[50m])
|
||||
{path="/foo"} 3
|
||||
{path="/bar"} 1
|
||||
{path="/biz"} 0
|
||||
|
||||
eval instant at 50m resets(nonexistent_metric[50m])
|
||||
|
||||
# Tests for changes().
|
||||
eval instant at 50m changes(http_requests[5m])
|
||||
{path="/foo"} 0
|
||||
{path="/bar"} 0
|
||||
{path="/biz"} 0
|
||||
|
||||
eval instant at 50m changes(http_requests[20m])
|
||||
{path="/foo"} 3
|
||||
{path="/bar"} 3
|
||||
{path="/biz"} 0
|
||||
|
||||
eval instant at 50m changes(http_requests[30m])
|
||||
{path="/foo"} 4
|
||||
{path="/bar"} 5
|
||||
{path="/biz"} 1
|
||||
|
||||
eval instant at 50m changes(http_requests[50m])
|
||||
{path="/foo"} 8
|
||||
{path="/bar"} 9
|
||||
{path="/biz"} 1
|
||||
|
||||
eval instant at 50m changes(nonexistent_metric[50m])
|
||||
|
||||
|
||||
clear
|
||||
|
||||
# Tests for increase().
|
||||
load 5m
|
||||
http_requests{path="/foo"} 0+10x10
|
||||
http_requests{path="/bar"} 0+10x5 0+10x5
|
||||
|
||||
# Tests for increase().
|
||||
eval instant at 50m increase(http_requests[50m])
|
||||
{path="/foo"} 100
|
||||
{path="/bar"} 90
|
||||
|
||||
|
||||
clear
|
||||
|
||||
# Tests for deriv() and predict_linear().
|
||||
load 5m
|
||||
testcounter_reset_middle 0+10x4 0+10x5
|
||||
http_requests{job="app-server", instance="1", group="canary"} 0+80x10
|
||||
|
||||
# Deriv should return the same as rate in simple cases.
|
||||
eval instant at 50m rate(http_requests{group="canary", instance="1", job="app-server"}[60m])
|
||||
{group="canary", instance="1", job="app-server"} 0.26666666666666666
|
||||
|
||||
eval instant at 50m deriv(http_requests{group="canary", instance="1", job="app-server"}[60m])
|
||||
{group="canary", instance="1", job="app-server"} 0.26666666666666666
|
||||
|
||||
# Deriv should return correct result.
|
||||
eval instant at 50m deriv(testcounter_reset_middle[100m])
|
||||
{} 0.010606060606060607
|
||||
|
||||
# Predict_linear should return correct result.
|
||||
eval instant at 50m predict_linear(testcounter_reset_middle[100m], 3600)
|
||||
{} 88.181818181818185200
|
||||
|
||||
# Predict_linear is syntactic sugar around deriv.
|
||||
eval instant at 50m predict_linear(http_requests[50m], 3600) - (http_requests + deriv(http_requests[50m]) * 3600)
|
||||
{group="canary", instance="1", job="app-server"} 0
|
||||
|
||||
eval instant at 50m predict_linear(testcounter_reset_middle[100m], 3600) - (testcounter_reset_middle + deriv(testcounter_reset_middle[100m]) * 3600)
|
||||
{} 0
|
141
prom/promql/testdata/histograms.test
vendored
Normal file
141
prom/promql/testdata/histograms.test
vendored
Normal file
@ -0,0 +1,141 @@
|
||||
# Two histograms with 4 buckets each (x_sum and x_count not included,
|
||||
# only buckets). Lowest bucket for one histogram < 0, for the other >
|
||||
# 0. They have the same name, just separated by label. Not useful in
|
||||
# practice, but can happen (if clients change bucketing), and the
|
||||
# server has to cope with it.
|
||||
|
||||
# Test histogram.
|
||||
load 5m
|
||||
testhistogram_bucket{le="0.1", start="positive"} 0+5x10
|
||||
testhistogram_bucket{le=".2", start="positive"} 0+7x10
|
||||
testhistogram_bucket{le="1e0", start="positive"} 0+11x10
|
||||
testhistogram_bucket{le="+Inf", start="positive"} 0+12x10
|
||||
testhistogram_bucket{le="-.2", start="negative"} 0+1x10
|
||||
testhistogram_bucket{le="-0.1", start="negative"} 0+2x10
|
||||
testhistogram_bucket{le="0.3", start="negative"} 0+2x10
|
||||
testhistogram_bucket{le="+Inf", start="negative"} 0+3x10
|
||||
|
||||
|
||||
# Now a more realistic histogram per job and instance to test aggregation.
|
||||
load 5m
|
||||
request_duration_seconds_bucket{job="job1", instance="ins1", le="0.1"} 0+1x10
|
||||
request_duration_seconds_bucket{job="job1", instance="ins1", le="0.2"} 0+3x10
|
||||
request_duration_seconds_bucket{job="job1", instance="ins1", le="+Inf"} 0+4x10
|
||||
request_duration_seconds_bucket{job="job1", instance="ins2", le="0.1"} 0+2x10
|
||||
request_duration_seconds_bucket{job="job1", instance="ins2", le="0.2"} 0+5x10
|
||||
request_duration_seconds_bucket{job="job1", instance="ins2", le="+Inf"} 0+6x10
|
||||
request_duration_seconds_bucket{job="job2", instance="ins1", le="0.1"} 0+3x10
|
||||
request_duration_seconds_bucket{job="job2", instance="ins1", le="0.2"} 0+4x10
|
||||
request_duration_seconds_bucket{job="job2", instance="ins1", le="+Inf"} 0+6x10
|
||||
request_duration_seconds_bucket{job="job2", instance="ins2", le="0.1"} 0+4x10
|
||||
request_duration_seconds_bucket{job="job2", instance="ins2", le="0.2"} 0+7x10
|
||||
request_duration_seconds_bucket{job="job2", instance="ins2", le="+Inf"} 0+9x10
|
||||
|
||||
|
||||
# Quantile too low.
|
||||
eval instant at 50m histogram_quantile(-0.1, testhistogram_bucket)
|
||||
{start="positive"} -Inf
|
||||
{start="negative"} -Inf
|
||||
|
||||
# Quantile too high.
|
||||
eval instant at 50m histogram_quantile(1.01, testhistogram_bucket)
|
||||
{start="positive"} +Inf
|
||||
{start="negative"} +Inf
|
||||
|
||||
# Quantile value in lowest bucket, which is positive.
|
||||
eval instant at 50m histogram_quantile(0, testhistogram_bucket{start="positive"})
|
||||
{start="positive"} 0
|
||||
|
||||
# Quantile value in lowest bucket, which is negative.
|
||||
eval instant at 50m histogram_quantile(0, testhistogram_bucket{start="negative"})
|
||||
{start="negative"} -0.2
|
||||
|
||||
# Quantile value in highest bucket.
|
||||
eval instant at 50m histogram_quantile(1, testhistogram_bucket)
|
||||
{start="positive"} 1
|
||||
{start="negative"} 0.3
|
||||
|
||||
# Finally some useful quantiles.
|
||||
eval instant at 50m histogram_quantile(0.2, testhistogram_bucket)
|
||||
{start="positive"} 0.048
|
||||
{start="negative"} -0.2
|
||||
|
||||
|
||||
eval instant at 50m histogram_quantile(0.5, testhistogram_bucket)
|
||||
{start="positive"} 0.15
|
||||
{start="negative"} -0.15
|
||||
|
||||
eval instant at 50m histogram_quantile(0.8, testhistogram_bucket)
|
||||
{start="positive"} 0.72
|
||||
{start="negative"} 0.3
|
||||
|
||||
# More realistic with rates.
|
||||
eval instant at 50m histogram_quantile(0.2, rate(testhistogram_bucket[5m]))
|
||||
{start="positive"} 0.048
|
||||
{start="negative"} -0.2
|
||||
|
||||
eval instant at 50m histogram_quantile(0.5, rate(testhistogram_bucket[5m]))
|
||||
{start="positive"} 0.15
|
||||
{start="negative"} -0.15
|
||||
|
||||
eval instant at 50m histogram_quantile(0.8, rate(testhistogram_bucket[5m]))
|
||||
{start="positive"} 0.72
|
||||
{start="negative"} 0.3
|
||||
|
||||
# Aggregated histogram: Everything in one.
|
||||
eval instant at 50m histogram_quantile(0.3, sum(rate(request_duration_seconds_bucket[5m])) by (le))
|
||||
{} 0.075
|
||||
|
||||
eval instant at 50m histogram_quantile(0.5, sum(rate(request_duration_seconds_bucket[5m])) by (le))
|
||||
{} 0.1277777777777778
|
||||
|
||||
# Aggregated histogram: Everything in one. Now with avg, which does not change anything.
|
||||
eval instant at 50m histogram_quantile(0.3, avg(rate(request_duration_seconds_bucket[5m])) by (le))
|
||||
{} 0.075
|
||||
|
||||
eval instant at 50m histogram_quantile(0.5, avg(rate(request_duration_seconds_bucket[5m])) by (le))
|
||||
{} 0.12777777777777778
|
||||
|
||||
# Aggregated histogram: By job.
|
||||
eval instant at 50m histogram_quantile(0.3, sum(rate(request_duration_seconds_bucket[5m])) by (le, instance))
|
||||
{instance="ins1"} 0.075
|
||||
{instance="ins2"} 0.075
|
||||
|
||||
eval instant at 50m histogram_quantile(0.5, sum(rate(request_duration_seconds_bucket[5m])) by (le, instance))
|
||||
{instance="ins1"} 0.1333333333
|
||||
{instance="ins2"} 0.125
|
||||
|
||||
# Aggregated histogram: By instance.
|
||||
eval instant at 50m histogram_quantile(0.3, sum(rate(request_duration_seconds_bucket[5m])) by (le, job))
|
||||
{job="job1"} 0.1
|
||||
{job="job2"} 0.0642857142857143
|
||||
|
||||
eval instant at 50m histogram_quantile(0.5, sum(rate(request_duration_seconds_bucket[5m])) by (le, job))
|
||||
{job="job1"} 0.14
|
||||
{job="job2"} 0.1125
|
||||
|
||||
# Aggregated histogram: By job and instance.
|
||||
eval instant at 50m histogram_quantile(0.3, sum(rate(request_duration_seconds_bucket[5m])) by (le, job, instance))
|
||||
{instance="ins1", job="job1"} 0.11
|
||||
{instance="ins2", job="job1"} 0.09
|
||||
{instance="ins1", job="job2"} 0.06
|
||||
{instance="ins2", job="job2"} 0.0675
|
||||
|
||||
eval instant at 50m histogram_quantile(0.5, sum(rate(request_duration_seconds_bucket[5m])) by (le, job, instance))
|
||||
{instance="ins1", job="job1"} 0.15
|
||||
{instance="ins2", job="job1"} 0.1333333333333333
|
||||
{instance="ins1", job="job2"} 0.1
|
||||
{instance="ins2", job="job2"} 0.1166666666666667
|
||||
|
||||
# The unaggregated histogram for comparison. Same result as the previous one.
|
||||
eval instant at 50m histogram_quantile(0.3, rate(request_duration_seconds_bucket[5m]))
|
||||
{instance="ins1", job="job1"} 0.11
|
||||
{instance="ins2", job="job1"} 0.09
|
||||
{instance="ins1", job="job2"} 0.06
|
||||
{instance="ins2", job="job2"} 0.0675
|
||||
|
||||
eval instant at 50m histogram_quantile(0.5, rate(request_duration_seconds_bucket[5m]))
|
||||
{instance="ins1", job="job1"} 0.15
|
||||
{instance="ins2", job="job1"} 0.13333333333333333
|
||||
{instance="ins1", job="job2"} 0.1
|
||||
{instance="ins2", job="job2"} 0.11666666666666667
|
665
prom/promql/testdata/legacy.test
vendored
Normal file
665
prom/promql/testdata/legacy.test
vendored
Normal file
@ -0,0 +1,665 @@
|
||||
load 5m
|
||||
http_requests{job="api-server", instance="0", group="production"} 0+10x10
|
||||
http_requests{job="api-server", instance="1", group="production"} 0+20x10
|
||||
http_requests{job="api-server", instance="0", group="canary"} 0+30x10
|
||||
http_requests{job="api-server", instance="1", group="canary"} 0+40x10
|
||||
http_requests{job="app-server", instance="0", group="production"} 0+50x10
|
||||
http_requests{job="app-server", instance="1", group="production"} 0+60x10
|
||||
http_requests{job="app-server", instance="0", group="canary"} 0+70x10
|
||||
http_requests{job="app-server", instance="1", group="canary"} 0+80x10
|
||||
|
||||
load 5m
|
||||
x{y="testvalue"} 0+10x10
|
||||
|
||||
load 5m
|
||||
testcounter_reset_middle 0+10x4 0+10x5
|
||||
testcounter_reset_end 0+10x9 0 10
|
||||
|
||||
load 5m
|
||||
label_grouping_test{a="aa", b="bb"} 0+10x10
|
||||
label_grouping_test{a="a", b="abb"} 0+20x10
|
||||
|
||||
load 5m
|
||||
vector_matching_a{l="x"} 0+1x100
|
||||
vector_matching_a{l="y"} 0+2x50
|
||||
vector_matching_b{l="x"} 0+4x25
|
||||
|
||||
load 5m
|
||||
cpu_count{instance="0", type="numa"} 0+30x10
|
||||
cpu_count{instance="0", type="smp"} 0+10x20
|
||||
cpu_count{instance="1", type="smp"} 0+20x10
|
||||
|
||||
|
||||
eval instant at 50m SUM(http_requests)
|
||||
{} 3600
|
||||
|
||||
eval instant at 50m SUM(http_requests{instance="0"}) BY(job)
|
||||
{job="api-server"} 400
|
||||
{job="app-server"} 1200
|
||||
|
||||
eval instant at 50m SUM(http_requests{instance="0"}) BY(job) KEEP_COMMON
|
||||
{instance="0", job="api-server"} 400
|
||||
{instance="0", job="app-server"} 1200
|
||||
|
||||
eval instant at 50m SUM(http_requests) BY (job)
|
||||
{job="api-server"} 1000
|
||||
{job="app-server"} 2600
|
||||
|
||||
# Non-existent labels mentioned in BY-clauses shouldn't propagate to output.
|
||||
eval instant at 50m SUM(http_requests) BY (job, nonexistent)
|
||||
{job="api-server"} 1000
|
||||
{job="app-server"} 2600
|
||||
|
||||
|
||||
eval instant at 50m COUNT(http_requests) BY (job)
|
||||
{job="api-server"} 4
|
||||
{job="app-server"} 4
|
||||
|
||||
|
||||
eval instant at 50m SUM(http_requests) BY (job, group)
|
||||
{group="canary", job="api-server"} 700
|
||||
{group="canary", job="app-server"} 1500
|
||||
{group="production", job="api-server"} 300
|
||||
{group="production", job="app-server"} 1100
|
||||
|
||||
|
||||
eval instant at 50m AVG(http_requests) BY (job)
|
||||
{job="api-server"} 250
|
||||
{job="app-server"} 650
|
||||
|
||||
|
||||
eval instant at 50m MIN(http_requests) BY (job)
|
||||
{job="api-server"} 100
|
||||
{job="app-server"} 500
|
||||
|
||||
|
||||
eval instant at 50m MAX(http_requests) BY (job)
|
||||
{job="api-server"} 400
|
||||
{job="app-server"} 800
|
||||
|
||||
|
||||
eval instant at 50m SUM(http_requests) BY (job) - COUNT(http_requests) BY (job)
|
||||
{job="api-server"} 996
|
||||
{job="app-server"} 2596
|
||||
|
||||
|
||||
eval instant at 50m 2 - SUM(http_requests) BY (job)
|
||||
{job="api-server"} -998
|
||||
{job="app-server"} -2598
|
||||
|
||||
|
||||
eval instant at 50m 1000 / SUM(http_requests) BY (job)
|
||||
{job="api-server"} 1
|
||||
{job="app-server"} 0.38461538461538464
|
||||
|
||||
|
||||
eval instant at 50m SUM(http_requests) BY (job) - 2
|
||||
{job="api-server"} 998
|
||||
{job="app-server"} 2598
|
||||
|
||||
|
||||
eval instant at 50m SUM(http_requests) BY (job) % 3
|
||||
{job="api-server"} 1
|
||||
{job="app-server"} 2
|
||||
|
||||
|
||||
eval instant at 50m SUM(http_requests) BY (job) / 0
|
||||
{job="api-server"} +Inf
|
||||
{job="app-server"} +Inf
|
||||
|
||||
|
||||
eval instant at 50m SUM(http_requests) BY (job) > 1000
|
||||
{job="app-server"} 2600
|
||||
|
||||
|
||||
eval instant at 50m 1000 < SUM(http_requests) BY (job)
|
||||
{job="app-server"} 1000
|
||||
|
||||
|
||||
eval instant at 50m SUM(http_requests) BY (job) <= 1000
|
||||
{job="api-server"} 1000
|
||||
|
||||
|
||||
eval instant at 50m SUM(http_requests) BY (job) != 1000
|
||||
{job="app-server"} 2600
|
||||
|
||||
|
||||
eval instant at 50m SUM(http_requests) BY (job) == 1000
|
||||
{job="api-server"} 1000
|
||||
|
||||
|
||||
eval instant at 50m SUM(http_requests) BY (job) + SUM(http_requests) BY (job)
|
||||
{job="api-server"} 2000
|
||||
{job="app-server"} 5200
|
||||
|
||||
|
||||
eval instant at 50m http_requests{job="api-server", group="canary"}
|
||||
http_requests{group="canary", instance="0", job="api-server"} 300
|
||||
http_requests{group="canary", instance="1", job="api-server"} 400
|
||||
|
||||
|
||||
eval instant at 50m http_requests{job="api-server", group="canary"} + rate(http_requests{job="api-server"}[5m]) * 5 * 60
|
||||
{group="canary", instance="0", job="api-server"} 330
|
||||
{group="canary", instance="1", job="api-server"} 440
|
||||
|
||||
|
||||
eval instant at 50m rate(http_requests[25m]) * 25 * 60
|
||||
{group="canary", instance="0", job="api-server"} 150
|
||||
{group="canary", instance="0", job="app-server"} 350
|
||||
{group="canary", instance="1", job="api-server"} 200
|
||||
{group="canary", instance="1", job="app-server"} 400
|
||||
{group="production", instance="0", job="api-server"} 50
|
||||
{group="production", instance="0", job="app-server"} 249.99999999999997
|
||||
{group="production", instance="1", job="api-server"} 100
|
||||
{group="production", instance="1", job="app-server"} 300
|
||||
|
||||
eval instant at 50m delta(http_requests[25m], 1)
|
||||
{group="canary", instance="0", job="api-server"} 150
|
||||
{group="canary", instance="0", job="app-server"} 350
|
||||
{group="canary", instance="1", job="api-server"} 200
|
||||
{group="canary", instance="1", job="app-server"} 400
|
||||
{group="production", instance="0", job="api-server"} 50
|
||||
{group="production", instance="0", job="app-server"} 250
|
||||
{group="production", instance="1", job="api-server"} 100
|
||||
{group="production", instance="1", job="app-server"} 300
|
||||
|
||||
eval_ordered instant at 50m sort(http_requests)
|
||||
http_requests{group="production", instance="0", job="api-server"} 100
|
||||
http_requests{group="production", instance="1", job="api-server"} 200
|
||||
http_requests{group="canary", instance="0", job="api-server"} 300
|
||||
http_requests{group="canary", instance="1", job="api-server"} 400
|
||||
http_requests{group="production", instance="0", job="app-server"} 500
|
||||
http_requests{group="production", instance="1", job="app-server"} 600
|
||||
http_requests{group="canary", instance="0", job="app-server"} 700
|
||||
http_requests{group="canary", instance="1", job="app-server"} 800
|
||||
|
||||
eval_ordered instant at 50m sort(0 / round(http_requests, 400) + http_requests)
|
||||
{group="production", instance="0", job="api-server"} NaN
|
||||
{group="production", instance="1", job="api-server"} 200
|
||||
{group="canary", instance="0", job="api-server"} 300
|
||||
{group="canary", instance="1", job="api-server"} 400
|
||||
{group="production", instance="0", job="app-server"} 500
|
||||
{group="production", instance="1", job="app-server"} 600
|
||||
{group="canary", instance="0", job="app-server"} 700
|
||||
{group="canary", instance="1", job="app-server"} 800
|
||||
|
||||
|
||||
eval_ordered instant at 50m sort_desc(http_requests)
|
||||
http_requests{group="canary", instance="1", job="app-server"} 800
|
||||
http_requests{group="canary", instance="0", job="app-server"} 700
|
||||
http_requests{group="production", instance="1", job="app-server"} 600
|
||||
http_requests{group="production", instance="0", job="app-server"} 500
|
||||
http_requests{group="canary", instance="1", job="api-server"} 400
|
||||
http_requests{group="canary", instance="0", job="api-server"} 300
|
||||
http_requests{group="production", instance="1", job="api-server"} 200
|
||||
http_requests{group="production", instance="0", job="api-server"} 100
|
||||
|
||||
eval_ordered instant at 50m topk(3, http_requests)
|
||||
http_requests{group="canary", instance="1", job="app-server"} 800
|
||||
http_requests{group="canary", instance="0", job="app-server"} 700
|
||||
http_requests{group="production", instance="1", job="app-server"} 600
|
||||
|
||||
eval_ordered instant at 50m topk(5, http_requests{group="canary",job="app-server"})
|
||||
http_requests{group="canary", instance="1", job="app-server"} 800
|
||||
http_requests{group="canary", instance="0", job="app-server"} 700
|
||||
|
||||
eval_ordered instant at 50m bottomk(3, http_requests)
|
||||
http_requests{group="production", instance="0", job="api-server"} 100
|
||||
http_requests{group="production", instance="1", job="api-server"} 200
|
||||
http_requests{group="canary", instance="0", job="api-server"} 300
|
||||
|
||||
eval_ordered instant at 50m bottomk(5, http_requests{group="canary",job="app-server"})
|
||||
http_requests{group="canary", instance="0", job="app-server"} 700
|
||||
http_requests{group="canary", instance="1", job="app-server"} 800
|
||||
|
||||
|
||||
# Single-letter label names and values.
|
||||
eval instant at 50m x{y="testvalue"}
|
||||
x{y="testvalue"} 100
|
||||
|
||||
|
||||
# Lower-cased aggregation operators should work too.
|
||||
eval instant at 50m sum(http_requests) by (job) + min(http_requests) by (job) + max(http_requests) by (job) + avg(http_requests) by (job)
|
||||
{job="app-server"} 4550
|
||||
{job="api-server"} 1750
|
||||
|
||||
|
||||
# Deltas should be adjusted for target interval vs. samples under target interval.
|
||||
eval instant at 50m delta(http_requests{group="canary", instance="1", job="app-server"}[18m])
|
||||
{group="canary", instance="1", job="app-server"} 288
|
||||
|
||||
|
||||
# Deltas should perform the same operation when 2nd argument is 0.
|
||||
eval instant at 50m delta(http_requests{group="canary", instance="1", job="app-server"}[18m], 0)
|
||||
{group="canary", instance="1", job="app-server"} 288
|
||||
|
||||
|
||||
# Rates should calculate per-second rates.
|
||||
eval instant at 50m rate(http_requests{group="canary", instance="1", job="app-server"}[60m])
|
||||
{group="canary", instance="1", job="app-server"} 0.26666666666666666
|
||||
|
||||
# Counter resets at in the middle of range are handled correctly by rate().
|
||||
eval instant at 50m rate(testcounter_reset_middle[60m])
|
||||
{} 0.03
|
||||
|
||||
|
||||
# Counter resets at end of range are ignored by rate().
|
||||
eval instant at 50m rate(testcounter_reset_end[5m])
|
||||
{} 0
|
||||
|
||||
# count_scalar for a non-empty vector should return scalar element count.
|
||||
eval instant at 50m count_scalar(http_requests)
|
||||
8
|
||||
|
||||
# count_scalar for an empty vector should return scalar 0.
|
||||
eval instant at 50m count_scalar(nonexistent)
|
||||
0
|
||||
|
||||
eval instant at 50m http_requests{group!="canary"}
|
||||
http_requests{group="production", instance="1", job="app-server"} 600
|
||||
http_requests{group="production", instance="0", job="app-server"} 500
|
||||
http_requests{group="production", instance="1", job="api-server"} 200
|
||||
http_requests{group="production", instance="0", job="api-server"} 100
|
||||
|
||||
eval instant at 50m http_requests{job=~"server",group!="canary"}
|
||||
http_requests{group="production", instance="1", job="app-server"} 600
|
||||
http_requests{group="production", instance="0", job="app-server"} 500
|
||||
http_requests{group="production", instance="1", job="api-server"} 200
|
||||
http_requests{group="production", instance="0", job="api-server"} 100
|
||||
|
||||
eval instant at 50m http_requests{job!~"api",group!="canary"}
|
||||
http_requests{group="production", instance="1", job="app-server"} 600
|
||||
http_requests{group="production", instance="0", job="app-server"} 500
|
||||
|
||||
eval instant at 50m count_scalar(http_requests{job=~"^server$"})
|
||||
0
|
||||
|
||||
eval instant at 50m http_requests{group="production",job=~"^api"}
|
||||
http_requests{group="production", instance="0", job="api-server"} 100
|
||||
http_requests{group="production", instance="1", job="api-server"} 200
|
||||
|
||||
eval instant at 50m abs(-1 * http_requests{group="production",job="api-server"})
|
||||
{group="production", instance="0", job="api-server"} 100
|
||||
{group="production", instance="1", job="api-server"} 200
|
||||
|
||||
eval instant at 50m floor(0.004 * http_requests{group="production",job="api-server"})
|
||||
{group="production", instance="0", job="api-server"} 0
|
||||
{group="production", instance="1", job="api-server"} 0
|
||||
|
||||
eval instant at 50m ceil(0.004 * http_requests{group="production",job="api-server"})
|
||||
{group="production", instance="0", job="api-server"} 1
|
||||
{group="production", instance="1", job="api-server"} 1
|
||||
|
||||
eval instant at 50m round(0.004 * http_requests{group="production",job="api-server"})
|
||||
{group="production", instance="0", job="api-server"} 0
|
||||
{group="production", instance="1", job="api-server"} 1
|
||||
|
||||
# Round should correctly handle negative numbers.
|
||||
eval instant at 50m round(-1 * (0.004 * http_requests{group="production",job="api-server"}))
|
||||
{group="production", instance="0", job="api-server"} 0
|
||||
{group="production", instance="1", job="api-server"} -1
|
||||
|
||||
# Round should round half up.
|
||||
eval instant at 50m round(0.005 * http_requests{group="production",job="api-server"})
|
||||
{group="production", instance="0", job="api-server"} 1
|
||||
{group="production", instance="1", job="api-server"} 1
|
||||
|
||||
eval instant at 50m round(-1 * (0.005 * http_requests{group="production",job="api-server"}))
|
||||
{group="production", instance="0", job="api-server"} 0
|
||||
{group="production", instance="1", job="api-server"} -1
|
||||
|
||||
eval instant at 50m round(1 + 0.005 * http_requests{group="production",job="api-server"})
|
||||
{group="production", instance="0", job="api-server"} 2
|
||||
{group="production", instance="1", job="api-server"} 2
|
||||
|
||||
eval instant at 50m round(-1 * (1 + 0.005 * http_requests{group="production",job="api-server"}))
|
||||
{group="production", instance="0", job="api-server"} -1
|
||||
{group="production", instance="1", job="api-server"} -2
|
||||
|
||||
# Round should accept the number to round nearest to.
|
||||
eval instant at 50m round(0.0005 * http_requests{group="production",job="api-server"}, 0.1)
|
||||
{group="production", instance="0", job="api-server"} 0.1
|
||||
{group="production", instance="1", job="api-server"} 0.1
|
||||
|
||||
eval instant at 50m round(2.1 + 0.0005 * http_requests{group="production",job="api-server"}, 0.1)
|
||||
{group="production", instance="0", job="api-server"} 2.2
|
||||
{group="production", instance="1", job="api-server"} 2.2
|
||||
|
||||
eval instant at 50m round(5.2 + 0.0005 * http_requests{group="production",job="api-server"}, 0.1)
|
||||
{group="production", instance="0", job="api-server"} 5.3
|
||||
{group="production", instance="1", job="api-server"} 5.3
|
||||
|
||||
# Round should work correctly with negative numbers and multiple decimal places.
|
||||
eval instant at 50m round(-1 * (5.2 + 0.0005 * http_requests{group="production",job="api-server"}), 0.1)
|
||||
{group="production", instance="0", job="api-server"} -5.2
|
||||
{group="production", instance="1", job="api-server"} -5.3
|
||||
|
||||
# Round should work correctly with big toNearests.
|
||||
eval instant at 50m round(0.025 * http_requests{group="production",job="api-server"}, 5)
|
||||
{group="production", instance="0", job="api-server"} 5
|
||||
{group="production", instance="1", job="api-server"} 5
|
||||
|
||||
eval instant at 50m round(0.045 * http_requests{group="production",job="api-server"}, 5)
|
||||
{group="production", instance="0", job="api-server"} 5
|
||||
{group="production", instance="1", job="api-server"} 10
|
||||
|
||||
eval instant at 50m avg_over_time(http_requests{group="production",job="api-server"}[1h])
|
||||
{group="production", instance="0", job="api-server"} 50
|
||||
{group="production", instance="1", job="api-server"} 100
|
||||
|
||||
eval instant at 50m count_over_time(http_requests{group="production",job="api-server"}[1h])
|
||||
{group="production", instance="0", job="api-server"} 11
|
||||
{group="production", instance="1", job="api-server"} 11
|
||||
|
||||
eval instant at 50m max_over_time(http_requests{group="production",job="api-server"}[1h])
|
||||
{group="production", instance="0", job="api-server"} 100
|
||||
{group="production", instance="1", job="api-server"} 200
|
||||
|
||||
eval instant at 50m min_over_time(http_requests{group="production",job="api-server"}[1h])
|
||||
{group="production", instance="0", job="api-server"} 0
|
||||
{group="production", instance="1", job="api-server"} 0
|
||||
|
||||
eval instant at 50m sum_over_time(http_requests{group="production",job="api-server"}[1h])
|
||||
{group="production", instance="0", job="api-server"} 550
|
||||
{group="production", instance="1", job="api-server"} 1100
|
||||
|
||||
eval instant at 50m time()
|
||||
3000
|
||||
|
||||
eval instant at 50m drop_common_labels(http_requests{group="production",job="api-server"})
|
||||
http_requests{instance="0"} 100
|
||||
http_requests{instance="1"} 200
|
||||
|
||||
eval instant at 50m {__name__=~".+"}
|
||||
http_requests{group="canary", instance="0", job="api-server"} 300
|
||||
http_requests{group="canary", instance="0", job="app-server"} 700
|
||||
http_requests{group="canary", instance="1", job="api-server"} 400
|
||||
http_requests{group="canary", instance="1", job="app-server"} 800
|
||||
http_requests{group="production", instance="0", job="api-server"} 100
|
||||
http_requests{group="production", instance="0", job="app-server"} 500
|
||||
http_requests{group="production", instance="1", job="api-server"} 200
|
||||
http_requests{group="production", instance="1", job="app-server"} 600
|
||||
testcounter_reset_end 0
|
||||
testcounter_reset_middle 50
|
||||
x{y="testvalue"} 100
|
||||
label_grouping_test{a="a", b="abb"} 200
|
||||
label_grouping_test{a="aa", b="bb"} 100
|
||||
vector_matching_a{l="x"} 10
|
||||
vector_matching_a{l="y"} 20
|
||||
vector_matching_b{l="x"} 40
|
||||
cpu_count{instance="1", type="smp"} 200
|
||||
cpu_count{instance="0", type="smp"} 100
|
||||
cpu_count{instance="0", type="numa"} 300
|
||||
|
||||
|
||||
eval instant at 50m {job=~"server", job!~"api"}
|
||||
http_requests{group="canary", instance="0", job="app-server"} 700
|
||||
http_requests{group="canary", instance="1", job="app-server"} 800
|
||||
http_requests{group="production", instance="0", job="app-server"} 500
|
||||
http_requests{group="production", instance="1", job="app-server"} 600
|
||||
|
||||
# Test alternative "by"-clause order.
|
||||
eval instant at 50m sum by (group) (http_requests{job="api-server"})
|
||||
{group="canary"} 700
|
||||
{group="production"} 300
|
||||
|
||||
# Test alternative "by"-clause order with "keep_common".
|
||||
eval instant at 50m sum by (group) keep_common (http_requests{job="api-server"})
|
||||
{group="canary", job="api-server"} 700
|
||||
{group="production", job="api-server"} 300
|
||||
|
||||
# Test both alternative "by"-clause orders in one expression.
|
||||
# Public health warning: stick to one form within an expression (or even
|
||||
# in an organization), or risk serious user confusion.
|
||||
eval instant at 50m sum(sum by (group) keep_common (http_requests{job="api-server"})) by (job)
|
||||
{job="api-server"} 1000
|
||||
|
||||
eval instant at 50m http_requests{group="canary"} and http_requests{instance="0"}
|
||||
http_requests{group="canary", instance="0", job="api-server"} 300
|
||||
http_requests{group="canary", instance="0", job="app-server"} 700
|
||||
|
||||
eval instant at 50m (http_requests{group="canary"} + 1) and http_requests{instance="0"}
|
||||
{group="canary", instance="0", job="api-server"} 301
|
||||
{group="canary", instance="0", job="app-server"} 701
|
||||
|
||||
eval instant at 50m (http_requests{group="canary"} + 1) and on(instance, job) http_requests{instance="0", group="production"}
|
||||
{group="canary", instance="0", job="api-server"} 301
|
||||
{group="canary", instance="0", job="app-server"} 701
|
||||
|
||||
eval instant at 50m (http_requests{group="canary"} + 1) and on(instance) http_requests{instance="0", group="production"}
|
||||
{group="canary", instance="0", job="api-server"} 301
|
||||
{group="canary", instance="0", job="app-server"} 701
|
||||
|
||||
eval instant at 50m http_requests{group="canary"} or http_requests{group="production"}
|
||||
http_requests{group="canary", instance="0", job="api-server"} 300
|
||||
http_requests{group="canary", instance="0", job="app-server"} 700
|
||||
http_requests{group="canary", instance="1", job="api-server"} 400
|
||||
http_requests{group="canary", instance="1", job="app-server"} 800
|
||||
http_requests{group="production", instance="0", job="api-server"} 100
|
||||
http_requests{group="production", instance="0", job="app-server"} 500
|
||||
http_requests{group="production", instance="1", job="api-server"} 200
|
||||
http_requests{group="production", instance="1", job="app-server"} 600
|
||||
|
||||
# On overlap the rhs samples must be dropped.
|
||||
eval instant at 50m (http_requests{group="canary"} + 1) or http_requests{instance="1"}
|
||||
{group="canary", instance="0", job="api-server"} 301
|
||||
{group="canary", instance="0", job="app-server"} 701
|
||||
{group="canary", instance="1", job="api-server"} 401
|
||||
{group="canary", instance="1", job="app-server"} 801
|
||||
http_requests{group="production", instance="1", job="api-server"} 200
|
||||
http_requests{group="production", instance="1", job="app-server"} 600
|
||||
|
||||
# Matching only on instance excludes everything that has instance=0/1 but includes
|
||||
# entries without the instance label.
|
||||
eval instant at 50m (http_requests{group="canary"} + 1) or on(instance) (http_requests or cpu_count or vector_matching_a)
|
||||
{group="canary", instance="0", job="api-server"} 301
|
||||
{group="canary", instance="0", job="app-server"} 701
|
||||
{group="canary", instance="1", job="api-server"} 401
|
||||
{group="canary", instance="1", job="app-server"} 801
|
||||
vector_matching_a{l="x"} 10
|
||||
vector_matching_a{l="y"} 20
|
||||
|
||||
eval instant at 50m http_requests{group="canary"} / on(instance,job) http_requests{group="production"}
|
||||
{instance="0", job="api-server"} 3
|
||||
{instance="0", job="app-server"} 1.4
|
||||
{instance="1", job="api-server"} 2
|
||||
{instance="1", job="app-server"} 1.3333333333333333
|
||||
|
||||
# Include labels must guarantee uniquely identifiable time series.
|
||||
eval_fail instant at 50m http_requests{group="production"} / on(instance) group_left(group) cpu_count{type="smp"}
|
||||
|
||||
# Many-to-many matching is not allowed.
|
||||
eval_fail instant at 50m http_requests{group="production"} / on(instance) group_left(job,type) cpu_count
|
||||
|
||||
# Many-to-one matching must be explicit.
|
||||
eval_fail instant at 50m http_requests{group="production"} / on(instance) cpu_count{type="smp"}
|
||||
|
||||
eval instant at 50m http_requests{group="production"} / on(instance) group_left(job) cpu_count{type="smp"}
|
||||
{instance="1", job="api-server"} 1
|
||||
{instance="0", job="app-server"} 5
|
||||
{instance="1", job="app-server"} 3
|
||||
{instance="0", job="api-server"} 1
|
||||
|
||||
# Ensure sidedness of grouping preserves operand sides.
|
||||
eval instant at 50m cpu_count{type="smp"} / on(instance) group_right(job) http_requests{group="production"}
|
||||
{instance="1", job="app-server"} 0.3333333333333333
|
||||
{instance="0", job="app-server"} 0.2
|
||||
{instance="1", job="api-server"} 1
|
||||
{instance="0", job="api-server"} 1
|
||||
|
||||
# Include labels from both sides.
|
||||
eval instant at 50m http_requests{group="production"} / on(instance) group_left(job) cpu_count{type="smp"}
|
||||
{instance="1", job="api-server"} 1
|
||||
{instance="0", job="app-server"} 5
|
||||
{instance="1", job="app-server"} 3
|
||||
{instance="0", job="api-server"} 1
|
||||
|
||||
eval instant at 50m http_requests{group="production"} < on(instance,job) http_requests{group="canary"}
|
||||
{instance="1", job="app-server"} 600
|
||||
{instance="0", job="app-server"} 500
|
||||
{instance="1", job="api-server"} 200
|
||||
{instance="0", job="api-server"} 100
|
||||
|
||||
|
||||
eval instant at 50m http_requests{group="production"} > on(instance,job) http_requests{group="canary"}
|
||||
# no output
|
||||
|
||||
eval instant at 50m http_requests{group="production"} == on(instance,job) http_requests{group="canary"}
|
||||
# no output
|
||||
|
||||
eval instant at 50m http_requests > on(instance) group_left(group,job) cpu_count{type="smp"}
|
||||
{group="canary", instance="0", job="app-server"} 700
|
||||
{group="canary", instance="1", job="app-server"} 800
|
||||
{group="canary", instance="0", job="api-server"} 300
|
||||
{group="canary", instance="1", job="api-server"} 400
|
||||
{group="production", instance="0", job="app-server"} 500
|
||||
{group="production", instance="1", job="app-server"} 600
|
||||
|
||||
eval instant at 50m {l="x"} + on(__name__) {l="y"}
|
||||
vector_matching_a 30
|
||||
|
||||
eval instant at 50m absent(nonexistent)
|
||||
{} 1
|
||||
|
||||
|
||||
eval instant at 50m absent(nonexistent{job="testjob", instance="testinstance", method=~".x"})
|
||||
{instance="testinstance", job="testjob"} 1
|
||||
|
||||
eval instant at 50m count_scalar(absent(http_requests))
|
||||
0
|
||||
|
||||
eval instant at 50m count_scalar(absent(sum(http_requests)))
|
||||
0
|
||||
|
||||
eval instant at 50m absent(sum(nonexistent{job="testjob", instance="testinstance"}))
|
||||
{} 1
|
||||
|
||||
eval instant at 50m http_requests{group="production",job="api-server"} offset 5m
|
||||
http_requests{group="production", instance="0", job="api-server"} 90
|
||||
http_requests{group="production", instance="1", job="api-server"} 180
|
||||
|
||||
eval instant at 50m rate(http_requests{group="production",job="api-server"}[10m] offset 5m)
|
||||
{group="production", instance="0", job="api-server"} 0.03333333333333333
|
||||
{group="production", instance="1", job="api-server"} 0.06666666666666667
|
||||
|
||||
# Regression test for missing separator byte in labelsToGroupingKey.
|
||||
eval instant at 50m sum(label_grouping_test) by (a, b)
|
||||
{a="a", b="abb"} 200
|
||||
{a="aa", b="bb"} 100
|
||||
|
||||
eval instant at 50m http_requests{group="canary", instance="0", job="api-server"} / 0
|
||||
{group="canary", instance="0", job="api-server"} +Inf
|
||||
|
||||
eval instant at 50m -1 * http_requests{group="canary", instance="0", job="api-server"} / 0
|
||||
{group="canary", instance="0", job="api-server"} -Inf
|
||||
|
||||
eval instant at 50m 0 * http_requests{group="canary", instance="0", job="api-server"} / 0
|
||||
{group="canary", instance="0", job="api-server"} NaN
|
||||
|
||||
eval instant at 50m 0 * http_requests{group="canary", instance="0", job="api-server"} % 0
|
||||
{group="canary", instance="0", job="api-server"} NaN
|
||||
|
||||
eval instant at 50m exp(vector_matching_a)
|
||||
{l="x"} 22026.465794806718
|
||||
{l="y"} 485165195.4097903
|
||||
|
||||
eval instant at 50m exp(vector_matching_a - 10)
|
||||
{l="y"} 22026.465794806718
|
||||
{l="x"} 1
|
||||
|
||||
eval instant at 50m exp(vector_matching_a - 20)
|
||||
{l="x"} 4.5399929762484854e-05
|
||||
{l="y"} 1
|
||||
|
||||
eval instant at 50m ln(vector_matching_a)
|
||||
{l="x"} 2.302585092994046
|
||||
{l="y"} 2.995732273553991
|
||||
|
||||
eval instant at 50m ln(vector_matching_a - 10)
|
||||
{l="y"} 2.302585092994046
|
||||
{l="x"} -Inf
|
||||
|
||||
eval instant at 50m ln(vector_matching_a - 20)
|
||||
{l="y"} -Inf
|
||||
{l="x"} NaN
|
||||
|
||||
eval instant at 50m exp(ln(vector_matching_a))
|
||||
{l="y"} 20
|
||||
{l="x"} 10
|
||||
|
||||
eval instant at 50m sqrt(vector_matching_a)
|
||||
{l="x"} 3.1622776601683795
|
||||
{l="y"} 4.47213595499958
|
||||
|
||||
eval instant at 50m log2(vector_matching_a)
|
||||
{l="x"} 3.3219280948873626
|
||||
{l="y"} 4.321928094887363
|
||||
|
||||
eval instant at 50m log2(vector_matching_a - 10)
|
||||
{l="y"} 3.3219280948873626
|
||||
{l="x"} -Inf
|
||||
|
||||
eval instant at 50m log2(vector_matching_a - 20)
|
||||
{l="x"} NaN
|
||||
{l="y"} -Inf
|
||||
|
||||
eval instant at 50m log10(vector_matching_a)
|
||||
{l="x"} 1
|
||||
{l="y"} 1.301029995663981
|
||||
|
||||
eval instant at 50m log10(vector_matching_a - 10)
|
||||
{l="y"} 1
|
||||
{l="x"} -Inf
|
||||
|
||||
eval instant at 50m log10(vector_matching_a - 20)
|
||||
{l="x"} NaN
|
||||
{l="y"} -Inf
|
||||
|
||||
eval instant at 50m stddev(http_requests)
|
||||
{} 229.12878474779
|
||||
|
||||
eval instant at 50m stddev by (instance)(http_requests)
|
||||
{instance="0"} 223.60679774998
|
||||
{instance="1"} 223.60679774998
|
||||
|
||||
eval instant at 50m stdvar(http_requests)
|
||||
{} 52500
|
||||
|
||||
eval instant at 50m stdvar by (instance)(http_requests)
|
||||
{instance="0"} 50000
|
||||
{instance="1"} 50000
|
||||
|
||||
|
||||
# Matrix tests.
|
||||
|
||||
clear
|
||||
load 1h
|
||||
testmetric{testlabel="1"} 1 1
|
||||
testmetric{testlabel="2"} _ 2
|
||||
|
||||
eval instant at 0h drop_common_labels(testmetric)
|
||||
testmetric 1
|
||||
|
||||
eval instant at 1h drop_common_labels(testmetric)
|
||||
testmetric{testlabel="1"} 1
|
||||
testmetric{testlabel="2"} 2
|
||||
|
||||
clear
|
||||
load 1h
|
||||
testmetric{testlabel="1"} 1 1
|
||||
testmetric{testlabel="2"} 2 _
|
||||
|
||||
eval instant at 0h sum(testmetric) keep_common
|
||||
{} 3
|
||||
|
||||
eval instant at 1h sum(testmetric) keep_common
|
||||
{testlabel="1"} 1
|
||||
|
||||
clear
|
||||
load 1h
|
||||
testmetric{aa="bb"} 1
|
||||
testmetric{a="abb"} 2
|
||||
|
||||
eval instant at 0h testmetric
|
||||
testmetric{aa="bb"} 1
|
||||
testmetric{a="abb"} 2
|
56
prom/promql/testdata/literals.test
vendored
Normal file
56
prom/promql/testdata/literals.test
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
eval instant at 50m 12.34e6
|
||||
12340000
|
||||
|
||||
eval instant at 50m 12.34e+6
|
||||
12340000
|
||||
|
||||
eval instant at 50m 12.34e-6
|
||||
0.00001234
|
||||
|
||||
eval instant at 50m 1+1
|
||||
2
|
||||
|
||||
eval instant at 50m 1-1
|
||||
0
|
||||
|
||||
eval instant at 50m 1 - -1
|
||||
2
|
||||
|
||||
eval instant at 50m .2
|
||||
0.2
|
||||
|
||||
eval instant at 50m +0.2
|
||||
0.2
|
||||
|
||||
eval instant at 50m -0.2e-6
|
||||
-0.0000002
|
||||
|
||||
eval instant at 50m +Inf
|
||||
+Inf
|
||||
|
||||
eval instant at 50m inF
|
||||
+Inf
|
||||
|
||||
eval instant at 50m -inf
|
||||
-Inf
|
||||
|
||||
eval instant at 50m NaN
|
||||
NaN
|
||||
|
||||
eval instant at 50m nan
|
||||
NaN
|
||||
|
||||
eval instant at 50m 2.
|
||||
2
|
||||
|
||||
eval instant at 50m 1 / 0
|
||||
+Inf
|
||||
|
||||
eval instant at 50m -1 / 0
|
||||
-Inf
|
||||
|
||||
eval instant at 50m 0 / 0
|
||||
NaN
|
||||
|
||||
eval instant at 50m 1 % 0
|
||||
NaN
|
Reference in New Issue
Block a user