Break aggregation tests out. Add missing tests.

This commit is contained in:
Brian Brazil 2016-02-07 18:00:23 +00:00
parent 328e1d733a
commit b7ef0b45e8
3 changed files with 96 additions and 63 deletions

96
promql/testdata/aggregators.test vendored Normal file
View File

@ -0,0 +1,96 @@
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
# Simple sum.
eval instant at 50m SUM BY (group) (http_requests{job="api-server"})
{group="canary"} 700
{group="production"} 300
# Test alternative "by"-clause order.
eval instant at 50m sum by (group) (http_requests{job="api-server"})
{group="canary"} 700
{group="production"} 300
# Simple average.
eval instant at 50m avg by (group) (http_requests{job="api-server"})
{group="canary"} 350
{group="production"} 150
# Simple count.
eval instant at 50m count by (group) (http_requests{job="api-server"})
{group="canary"} 2
{group="production"} 2
# 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
# 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
# Standard deviation and variance.
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
# Regression test for missing separator byte in labelsToGroupingKey.
clear
load 5m
label_grouping_test{a="aa", b="bb"} 0+10x10
label_grouping_test{a="a", b="abb"} 0+20x10
eval instant at 50m sum(label_grouping_test) by (a, b)
{a="a", b="abb"} 200
{a="aa", b="bb"} 100
# Tests for min/max.
clear
load 5m
http_requests{job="api-server", instance="0", group="production"} 1
http_requests{job="api-server", instance="1", group="production"} 2
http_requests{job="api-server", instance="0", group="canary"} NaN
http_requests{job="api-server", instance="1", group="canary"} 3
http_requests{job="api-server", instance="2", group="canary"} 4
eval instant at 0m max(http_requests)
{} 4
eval instant at 0m min(http_requests)
{} 1
eval instant at 0m max by (group) (http_requests)
{group="production"} 2
{group="canary"} 4
eval instant at 0m min by (group) (http_requests)
{group="production"} 1
{group="canary"} 3

View File

@ -147,12 +147,6 @@ 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
@ -343,22 +337,6 @@ eval instant at 50m {job=~".+-server", job!~"api-.+"}
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
@ -487,11 +465,6 @@ eval instant at 50m rate(http_requests{group="production",job="api-server"}[10m]
{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
@ -560,20 +533,6 @@ 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.

View File

@ -1,22 +0,0 @@
# Tests for min/max.
clear
load 5m
http_requests{job="api-server", instance="0", group="production"} 1
http_requests{job="api-server", instance="1", group="production"} 2
http_requests{job="api-server", instance="0", group="canary"} NaN
http_requests{job="api-server", instance="1", group="canary"} 3
http_requests{job="api-server", instance="2", group="canary"} 4
eval instant at 0m max(http_requests)
{} 4
eval instant at 0m min(http_requests)
{} 1
eval instant at 0m max by (group) (http_requests)
{group="production"} 2
{group="canary"} 4
eval instant at 0m min by (group) (http_requests)
{group="production"} 1
{group="canary"} 3