2015-05-26 17:01:34 +00:00
|
|
|
# Testdata for resets() and changes().
|
2015-05-26 15:47:52 +00:00
|
|
|
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
|
2015-05-26 17:01:34 +00:00
|
|
|
http_requests{path="/biz"} 0 0 0 0 0 1 1 1 1 1
|
2015-05-26 15:47:52 +00:00
|
|
|
|
2015-05-26 17:01:34 +00:00
|
|
|
# Tests for resets().
|
2015-05-26 15:47:52 +00:00
|
|
|
eval instant at 50m resets(http_requests[5m])
|
|
|
|
{path="/foo"} 0
|
|
|
|
{path="/bar"} 0
|
2015-05-26 17:01:34 +00:00
|
|
|
{path="/biz"} 0
|
2015-05-26 15:47:52 +00:00
|
|
|
|
|
|
|
eval instant at 50m resets(http_requests[20m])
|
|
|
|
{path="/foo"} 1
|
|
|
|
{path="/bar"} 0
|
2015-05-26 17:01:34 +00:00
|
|
|
{path="/biz"} 0
|
2015-05-26 15:47:52 +00:00
|
|
|
|
|
|
|
eval instant at 50m resets(http_requests[30m])
|
|
|
|
{path="/foo"} 2
|
|
|
|
{path="/bar"} 1
|
2015-05-26 17:01:34 +00:00
|
|
|
{path="/biz"} 0
|
2015-05-26 15:47:52 +00:00
|
|
|
|
|
|
|
eval instant at 50m resets(http_requests[50m])
|
|
|
|
{path="/foo"} 3
|
|
|
|
{path="/bar"} 1
|
2015-05-26 17:01:34 +00:00
|
|
|
{path="/biz"} 0
|
2015-05-26 15:47:52 +00:00
|
|
|
|
|
|
|
eval instant at 50m resets(nonexistent_metric[50m])
|
2015-05-26 17:01:34 +00:00
|
|
|
|
|
|
|
# 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])
|
2015-05-24 18:48:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2015-07-28 11:30:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-08-17 21:25:53 +00:00
|
|
|
# deriv should return the same as rate in simple cases.
|
2015-07-28 11:30:57 +00:00
|
|
|
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
|
|
|
|
|
2015-08-17 21:25:53 +00:00
|
|
|
# deriv should return correct result.
|
2015-07-28 11:30:57 +00:00
|
|
|
eval instant at 50m deriv(testcounter_reset_middle[100m])
|
|
|
|
{} 0.010606060606060607
|
|
|
|
|
2015-08-17 21:25:53 +00:00
|
|
|
# predict_linear should return correct result.
|
2015-07-28 11:30:57 +00:00
|
|
|
eval instant at 50m predict_linear(testcounter_reset_middle[100m], 3600)
|
|
|
|
{} 88.181818181818185200
|
|
|
|
|
2015-08-17 21:25:53 +00:00
|
|
|
# predict_linear is syntactic sugar around deriv.
|
2015-07-28 11:30:57 +00:00
|
|
|
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
|
2015-08-17 21:25:53 +00:00
|
|
|
|
|
|
|
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 substring match and replace.
|
|
|
|
eval instant at 0m label_replace(testmetric, "dst", "destination-value-$1", "src", "value-(.*)")
|
|
|
|
testmetric{src="source-value-10",dst="destination-value-10"} 0
|
|
|
|
testmetric{src="source-value-20",dst="destination-value-20"} 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", "", "", "")
|