# 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 eval instant at 50m increase(http_requests[100m]) {path="/foo"} 100 {path="/bar"} 90 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 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. eval instant at 0m vector(1) {} 1 eval instant at 60m vector(time()) {} 3600 clear # 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