mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 22:19:40 -08:00
498 lines
15 KiB
Plaintext
498 lines
15 KiB
Plaintext
# 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
|
|
|
|
load 5m
|
|
x{a="b"} NaN NaN NaN
|
|
x{a="c"} 0 NaN 0
|
|
|
|
eval instant at 15m changes(x[15m])
|
|
{a="b"} 0
|
|
{a="c"} 2
|
|
|
|
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
|
|
|
|
eval instant at 50m increase(http_requests[100m])
|
|
{path="/foo"} 100
|
|
{path="/bar"} 90
|
|
|
|
clear
|
|
|
|
# Test for increase() with counter reset.
|
|
# When the counter is reset, it always starts at 0.
|
|
# So the sequence 3 2 (decreasing counter = reset) is interpreted the same as 3 0 1 2.
|
|
# Prometheus assumes it missed the intermediate values 0 and 1.
|
|
load 5m
|
|
http_requests{path="/foo"} 0 1 2 3 2 3 4
|
|
|
|
eval instant at 30m increase(http_requests[30m])
|
|
{path="/foo"} 7
|
|
|
|
clear
|
|
|
|
# Tests for irate().
|
|
load 5m
|
|
http_requests{path="/foo"} 0+10x10
|
|
http_requests{path="/bar"} 0+10x5 0+10x5
|
|
|
|
eval instant at 50m irate(http_requests[50m])
|
|
{path="/foo"} .03333333333333333333
|
|
{path="/bar"} .03333333333333333333
|
|
|
|
# Counter reset.
|
|
eval instant at 30m irate(http_requests[50m])
|
|
{path="/foo"} .03333333333333333333
|
|
{path="/bar"} 0
|
|
|
|
clear
|
|
|
|
# Tests for delta().
|
|
load 5m
|
|
http_requests{path="/foo"} 0 50 100 150 200
|
|
http_requests{path="/bar"} 200 150 100 50 0
|
|
|
|
eval instant at 20m delta(http_requests[20m])
|
|
{path="/foo"} 200
|
|
{path="/bar"} -200
|
|
|
|
clear
|
|
|
|
# Tests for idelta().
|
|
load 5m
|
|
http_requests{path="/foo"} 0 50 100 150
|
|
http_requests{path="/bar"} 0 50 100 50
|
|
|
|
eval instant at 20m idelta(http_requests[20m])
|
|
{path="/foo"} 50
|
|
{path="/bar"} -50
|
|
|
|
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"}[50m])
|
|
{group="canary", instance="1", job="app-server"} 0.26666666666666666
|
|
|
|
eval instant at 50m deriv(http_requests{group="canary", instance="1", job="app-server"}[50m])
|
|
{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.
|
|
# X/s = [ 0, 300, 600, 900,1200,1500,1800,2100,2400,2700,3000]
|
|
# Y = [ 0, 10, 20, 30, 40, 0, 10, 20, 30, 40, 50]
|
|
# sumX = 16500
|
|
# sumY = 250
|
|
# sumXY = 480000
|
|
# sumX2 = 34650000
|
|
# n = 11
|
|
# covXY = 105000
|
|
# varX = 9900000
|
|
# slope = 0.010606060606060607
|
|
# intercept at t=0: 6.818181818181818
|
|
# intercept at t=3000: 38.63636363636364
|
|
# intercept at t=3000+3600: 76.81818181818181
|
|
eval instant at 50m predict_linear(testcounter_reset_middle[100m], 3600)
|
|
{} 76.81818181818181
|
|
|
|
# With http_requests, there is a sample value exactly at the end of
|
|
# the range, and it has exactly the predicted value, so predict_linear
|
|
# can be emulated with 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
|
|
|
|
clear
|
|
|
|
# Tests for label_replace.
|
|
load 5m
|
|
testmetric{src="source-value-10",dst="original-destination-value"} 0
|
|
testmetric{src="source-value-20",dst="original-destination-value"} 1
|
|
|
|
# label_replace does a full-string match and replace.
|
|
eval instant at 0m label_replace(testmetric, "dst", "destination-value-$1", "src", "source-value-(.*)")
|
|
testmetric{src="source-value-10",dst="destination-value-10"} 0
|
|
testmetric{src="source-value-20",dst="destination-value-20"} 1
|
|
|
|
# label_replace does not do a sub-string match.
|
|
eval instant at 0m label_replace(testmetric, "dst", "destination-value-$1", "src", "value-(.*)")
|
|
testmetric{src="source-value-10",dst="original-destination-value"} 0
|
|
testmetric{src="source-value-20",dst="original-destination-value"} 1
|
|
|
|
# label_replace works with multiple capture groups.
|
|
eval instant at 0m label_replace(testmetric, "dst", "$1-value-$2", "src", "(.*)-value-(.*)")
|
|
testmetric{src="source-value-10",dst="source-value-10"} 0
|
|
testmetric{src="source-value-20",dst="source-value-20"} 1
|
|
|
|
# label_replace does not overwrite the destination label if the source label
|
|
# does not exist.
|
|
eval instant at 0m label_replace(testmetric, "dst", "value-$1", "nonexistent-src", "source-value-(.*)")
|
|
testmetric{src="source-value-10",dst="original-destination-value"} 0
|
|
testmetric{src="source-value-20",dst="original-destination-value"} 1
|
|
|
|
# label_replace overwrites the destination label if the source label is empty,
|
|
# but matched.
|
|
eval instant at 0m label_replace(testmetric, "dst", "value-$1", "nonexistent-src", "(.*)")
|
|
testmetric{src="source-value-10",dst="value-"} 0
|
|
testmetric{src="source-value-20",dst="value-"} 1
|
|
|
|
# label_replace does not overwrite the destination label if the source label
|
|
# is not matched.
|
|
eval instant at 0m label_replace(testmetric, "dst", "value-$1", "src", "non-matching-regex")
|
|
testmetric{src="source-value-10",dst="original-destination-value"} 0
|
|
testmetric{src="source-value-20",dst="original-destination-value"} 1
|
|
|
|
# label_replace drops labels that are set to empty values.
|
|
eval instant at 0m label_replace(testmetric, "dst", "", "dst", ".*")
|
|
testmetric{src="source-value-10"} 0
|
|
testmetric{src="source-value-20"} 1
|
|
|
|
# label_replace fails when the regex is invalid.
|
|
eval_fail instant at 0m label_replace(testmetric, "dst", "value-$1", "src", "(.*")
|
|
|
|
# label_replace fails when the destination label name is not a valid Prometheus label name.
|
|
eval_fail instant at 0m label_replace(testmetric, "invalid-label-name", "", "src", "(.*)")
|
|
|
|
# label_replace fails when there would be duplicated identical output label sets.
|
|
eval_fail instant at 0m label_replace(testmetric, "src", "", "", "")
|
|
|
|
clear
|
|
|
|
# Tests for vector, time and timestamp.
|
|
load 10s
|
|
metric 1 1
|
|
|
|
eval instant at 0s timestamp(metric)
|
|
{} 0
|
|
|
|
eval instant at 5s timestamp(metric)
|
|
{} 0
|
|
|
|
eval instant at 10s timestamp(metric)
|
|
{} 10
|
|
|
|
# Tests for label_join.
|
|
load 5m
|
|
testmetric{src="a",src1="b",src2="c",dst="original-destination-value"} 0
|
|
testmetric{src="d",src1="e",src2="f",dst="original-destination-value"} 1
|
|
|
|
# label_join joins all src values in order.
|
|
eval instant at 0m label_join(testmetric, "dst", "-", "src", "src1", "src2")
|
|
testmetric{src="a",src1="b",src2="c",dst="a-b-c"} 0
|
|
testmetric{src="d",src1="e",src2="f",dst="d-e-f"} 1
|
|
|
|
# label_join treats non existent src labels as empty strings.
|
|
eval instant at 0m label_join(testmetric, "dst", "-", "src", "src3", "src1")
|
|
testmetric{src="a",src1="b",src2="c",dst="a--b"} 0
|
|
testmetric{src="d",src1="e",src2="f",dst="d--e"} 1
|
|
|
|
# label_join overwrites the destination label even if the resulting dst label is empty string
|
|
eval instant at 0m label_join(testmetric, "dst", "", "emptysrc", "emptysrc1", "emptysrc2")
|
|
testmetric{src="a",src1="b",src2="c"} 0
|
|
testmetric{src="d",src1="e",src2="f"} 1
|
|
|
|
# test without src label for label_join
|
|
eval instant at 0m label_join(testmetric, "dst", ", ")
|
|
testmetric{src="a",src1="b",src2="c"} 0
|
|
testmetric{src="d",src1="e",src2="f"} 1
|
|
|
|
# test without dst label for label_join
|
|
load 5m
|
|
testmetric1{src="foo",src1="bar",src2="foobar"} 0
|
|
testmetric1{src="fizz",src1="buzz",src2="fizzbuzz"} 1
|
|
|
|
# label_join creates dst label if not present.
|
|
eval instant at 0m label_join(testmetric1, "dst", ", ", "src", "src1", "src2")
|
|
testmetric1{src="foo",src1="bar",src2="foobar",dst="foo, bar, foobar"} 0
|
|
testmetric1{src="fizz",src1="buzz",src2="fizzbuzz",dst="fizz, buzz, fizzbuzz"} 1
|
|
|
|
clear
|
|
|
|
# Tests for vector.
|
|
eval instant at 0m vector(1)
|
|
{} 1
|
|
|
|
eval instant at 0s vector(time())
|
|
{} 0
|
|
|
|
eval instant at 5s vector(time())
|
|
{} 5
|
|
|
|
eval instant at 60m vector(time())
|
|
{} 3600
|
|
|
|
|
|
# Tests for clamp_max and clamp_min().
|
|
load 5m
|
|
test_clamp{src="clamp-a"} -50
|
|
test_clamp{src="clamp-b"} 0
|
|
test_clamp{src="clamp-c"} 100
|
|
|
|
eval instant at 0m clamp_max(test_clamp, 75)
|
|
{src="clamp-a"} -50
|
|
{src="clamp-b"} 0
|
|
{src="clamp-c"} 75
|
|
|
|
eval instant at 0m clamp_min(test_clamp, -25)
|
|
{src="clamp-a"} -25
|
|
{src="clamp-b"} 0
|
|
{src="clamp-c"} 100
|
|
|
|
eval instant at 0m clamp_max(clamp_min(test_clamp, -20), 70)
|
|
{src="clamp-a"} -20
|
|
{src="clamp-b"} 0
|
|
{src="clamp-c"} 70
|
|
|
|
|
|
# Tests for sort/sort_desc.
|
|
clear
|
|
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="api-server", instance="2", group="canary"} NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
|
|
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
|
|
|
|
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
|
|
http_requests{group="canary", instance="2", job="api-server"} NaN
|
|
|
|
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
|
|
http_requests{group="canary", instance="2", job="api-server"} NaN
|
|
|
|
# Tests for holt_winters
|
|
clear
|
|
|
|
# positive trends
|
|
load 10s
|
|
http_requests{job="api-server", instance="0", group="production"} 0+10x1000 100+30x1000
|
|
http_requests{job="api-server", instance="1", group="production"} 0+20x1000 200+30x1000
|
|
http_requests{job="api-server", instance="0", group="canary"} 0+30x1000 300+80x1000
|
|
http_requests{job="api-server", instance="1", group="canary"} 0+40x2000
|
|
|
|
eval instant at 8000s holt_winters(http_requests[1m], 0.01, 0.1)
|
|
{job="api-server", instance="0", group="production"} 8000
|
|
{job="api-server", instance="1", group="production"} 16000
|
|
{job="api-server", instance="0", group="canary"} 24000
|
|
{job="api-server", instance="1", group="canary"} 32000
|
|
|
|
# negative trends
|
|
clear
|
|
load 10s
|
|
http_requests{job="api-server", instance="0", group="production"} 8000-10x1000
|
|
http_requests{job="api-server", instance="1", group="production"} 0-20x1000
|
|
http_requests{job="api-server", instance="0", group="canary"} 0+30x1000 300-80x1000
|
|
http_requests{job="api-server", instance="1", group="canary"} 0-40x1000 0+40x1000
|
|
|
|
eval instant at 8000s holt_winters(http_requests[1m], 0.01, 0.1)
|
|
{job="api-server", instance="0", group="production"} 0
|
|
{job="api-server", instance="1", group="production"} -16000
|
|
{job="api-server", instance="0", group="canary"} 24000
|
|
{job="api-server", instance="1", group="canary"} -32000
|
|
|
|
# Tests for stddev_over_time and stdvar_over_time.
|
|
clear
|
|
load 10s
|
|
metric 0 8 8 2 3
|
|
|
|
eval instant at 1m stdvar_over_time(metric[1m])
|
|
{} 10.56
|
|
|
|
eval instant at 1m stddev_over_time(metric[1m])
|
|
{} 3.249615
|
|
|
|
# Tests for quantile_over_time
|
|
clear
|
|
|
|
load 10s
|
|
data{test="two samples"} 0 1
|
|
data{test="three samples"} 0 1 2
|
|
data{test="uneven samples"} 0 1 4
|
|
|
|
eval instant at 1m quantile_over_time(0, data[1m])
|
|
{test="two samples"} 0
|
|
{test="three samples"} 0
|
|
{test="uneven samples"} 0
|
|
|
|
eval instant at 1m quantile_over_time(0.5, data[1m])
|
|
{test="two samples"} 0.5
|
|
{test="three samples"} 1
|
|
{test="uneven samples"} 1
|
|
|
|
eval instant at 1m quantile_over_time(0.75, data[1m])
|
|
{test="two samples"} 0.75
|
|
{test="three samples"} 1.5
|
|
{test="uneven samples"} 2.5
|
|
|
|
eval instant at 1m quantile_over_time(0.8, data[1m])
|
|
{test="two samples"} 0.8
|
|
{test="three samples"} 1.6
|
|
{test="uneven samples"} 2.8
|
|
|
|
eval instant at 1m quantile_over_time(1, data[1m])
|
|
{test="two samples"} 1
|
|
{test="three samples"} 2
|
|
{test="uneven samples"} 4
|
|
|
|
eval instant at 1m quantile_over_time(-1, data[1m])
|
|
{test="two samples"} -Inf
|
|
{test="three samples"} -Inf
|
|
{test="uneven samples"} -Inf
|
|
|
|
eval instant at 1m quantile_over_time(2, data[1m])
|
|
{test="two samples"} +Inf
|
|
{test="three samples"} +Inf
|
|
{test="uneven samples"} +Inf
|
|
|
|
clear
|
|
|
|
# Test time-related functions.
|
|
eval instant at 0m year()
|
|
{} 1970
|
|
|
|
eval instant at 1ms time()
|
|
0.001
|
|
|
|
eval instant at 0m year(vector(1136239445))
|
|
{} 2006
|
|
|
|
eval instant at 0m month()
|
|
{} 1
|
|
|
|
eval instant at 0m month(vector(1136239445))
|
|
{} 1
|
|
|
|
eval instant at 0m day_of_month()
|
|
{} 1
|
|
|
|
eval instant at 0m day_of_month(vector(1136239445))
|
|
{} 2
|
|
|
|
# Thursday.
|
|
eval instant at 0m day_of_week()
|
|
{} 4
|
|
|
|
eval instant at 0m day_of_week(vector(1136239445))
|
|
{} 1
|
|
|
|
eval instant at 0m hour()
|
|
{} 0
|
|
|
|
eval instant at 0m hour(vector(1136239445))
|
|
{} 22
|
|
|
|
eval instant at 0m minute()
|
|
{} 0
|
|
|
|
eval instant at 0m minute(vector(1136239445))
|
|
{} 4
|
|
|
|
# 2008-12-31 23:59:59 just before leap second.
|
|
eval instant at 0m year(vector(1230767999))
|
|
{} 2008
|
|
|
|
# 2009-01-01 00:00:00 just after leap second.
|
|
eval instant at 0m year(vector(1230768000))
|
|
{} 2009
|
|
|
|
# 2016-02-29 23:59:59 Febuary 29th in leap year.
|
|
eval instant at 0m month(vector(1456790399)) + day_of_month(vector(1456790399)) / 100
|
|
{} 2.29
|
|
|
|
# 2016-03-01 00:00:00 March 1st in leap year.
|
|
eval instant at 0m month(vector(1456790400)) + day_of_month(vector(1456790400)) / 100
|
|
{} 3.01
|
|
|
|
# Febuary 1st 2016 in leap year.
|
|
eval instant at 0m days_in_month(vector(1454284800))
|
|
{} 29
|
|
|
|
# Febuary 1st 2017 not in leap year.
|
|
eval instant at 0m days_in_month(vector(1485907200))
|
|
{} 28
|
|
|