github.com/thanos-io/thanos@v0.32.5/pkg/query/testdata/promql/prometheus/aggregators.test (about)

     1  load 5m
     2    http_requests{job="api-server", instance="0", group="production"} 0+10x10
     3    http_requests{job="api-server", instance="1", group="production"} 0+20x10
     4    http_requests{job="api-server", instance="0", group="canary"}   0+30x10
     5    http_requests{job="api-server", instance="1", group="canary"}   0+40x10
     6    http_requests{job="app-server", instance="0", group="production"} 0+50x10
     7    http_requests{job="app-server", instance="1", group="production"} 0+60x10
     8    http_requests{job="app-server", instance="0", group="canary"}   0+70x10
     9    http_requests{job="app-server", instance="1", group="canary"}   0+80x10
    10  
    11  load 5m
    12    foo{job="api-server", instance="0", region="europe"} 0+90x10
    13    foo{job="api-server"} 0+100x10
    14  
    15  # Simple sum.
    16  eval instant at 50m SUM BY (group) (http_requests{job="api-server"})
    17    {group="canary"} 700
    18    {group="production"} 300
    19  
    20  eval instant at 50m SUM BY (group) (((http_requests{job="api-server"})))
    21    {group="canary"} 700
    22    {group="production"} 300
    23  
    24  # Test alternative "by"-clause order.
    25  eval instant at 50m sum by (group) (http_requests{job="api-server"})
    26    {group="canary"} 700
    27    {group="production"} 300
    28  
    29  # Simple average.
    30  eval instant at 50m avg by (group) (http_requests{job="api-server"})
    31    {group="canary"} 350
    32    {group="production"} 150
    33  
    34  # Simple count.
    35  eval instant at 50m count by (group) (http_requests{job="api-server"})
    36    {group="canary"} 2
    37    {group="production"} 2
    38  
    39  # Simple without.
    40  eval instant at 50m sum without (instance) (http_requests{job="api-server"})
    41    {group="canary",job="api-server"} 700
    42    {group="production",job="api-server"} 300
    43  
    44  # Empty by.
    45  eval instant at 50m sum by () (http_requests{job="api-server"})
    46    {} 1000
    47  
    48  # No by/without.
    49  eval instant at 50m sum(http_requests{job="api-server"})
    50    {} 1000
    51  
    52  # Empty without.
    53  eval instant at 50m sum without () (http_requests{job="api-server",group="production"})
    54    {group="production",job="api-server",instance="0"} 100
    55    {group="production",job="api-server",instance="1"} 200
    56  
    57  # Without with mismatched and missing labels. Do not do this.
    58  eval instant at 50m sum without (instance) (http_requests{job="api-server"} or foo)
    59    {group="canary",job="api-server"} 700
    60    {group="production",job="api-server"} 300
    61    {region="europe",job="api-server"} 900
    62    {job="api-server"} 1000
    63  
    64  # Lower-cased aggregation operators should work too.
    65  eval instant at 50m sum(http_requests) by (job) + min(http_requests) by (job) + max(http_requests) by (job) + avg(http_requests) by (job)
    66    {job="app-server"} 4550
    67    {job="api-server"} 1750
    68  
    69  # Test alternative "by"-clause order.
    70  eval instant at 50m sum by (group) (http_requests{job="api-server"})
    71    {group="canary"} 700
    72    {group="production"} 300
    73  
    74  # Test both alternative "by"-clause orders in one expression.
    75  # Public health warning: stick to one form within an expression (or even
    76  # in an organization), or risk serious user confusion.
    77  eval instant at 50m sum(sum by (group) (http_requests{job="api-server"})) by (job)
    78    {} 1000
    79  
    80  eval instant at 50m SUM(http_requests)
    81  	{} 3600
    82  
    83  eval instant at 50m SUM(http_requests{instance="0"}) BY(job)
    84  	{job="api-server"} 400
    85  	{job="app-server"} 1200
    86  
    87  eval instant at 50m SUM(http_requests) BY (job)
    88  	{job="api-server"} 1000
    89  	{job="app-server"} 2600
    90  
    91  # Non-existent labels mentioned in BY-clauses shouldn't propagate to output.
    92  eval instant at 50m SUM(http_requests) BY (job, nonexistent)
    93  	{job="api-server"} 1000
    94  	{job="app-server"} 2600
    95  
    96  eval instant at 50m COUNT(http_requests) BY (job)
    97  	{job="api-server"} 4
    98  	{job="app-server"} 4
    99  
   100  eval instant at 50m SUM(http_requests) BY (job, group)
   101  	{group="canary", job="api-server"} 700
   102  	{group="canary", job="app-server"} 1500
   103  	{group="production", job="api-server"} 300
   104  	{group="production", job="app-server"} 1100
   105  
   106  eval instant at 50m AVG(http_requests) BY (job)
   107  	{job="api-server"} 250
   108  	{job="app-server"} 650
   109  
   110  eval instant at 50m MIN(http_requests) BY (job)
   111  	{job="api-server"} 100
   112  	{job="app-server"} 500
   113  
   114  eval instant at 50m MAX(http_requests) BY (job)
   115  	{job="api-server"} 400
   116  	{job="app-server"} 800
   117  
   118  eval instant at 50m abs(-1 * http_requests{group="production",job="api-server"})
   119  	{group="production", instance="0", job="api-server"} 100
   120  	{group="production", instance="1", job="api-server"} 200
   121  
   122  eval instant at 50m floor(0.004 * http_requests{group="production",job="api-server"})
   123  	{group="production", instance="0", job="api-server"} 0
   124  	{group="production", instance="1", job="api-server"} 0
   125  
   126  eval instant at 50m ceil(0.004 * http_requests{group="production",job="api-server"})
   127  	{group="production", instance="0", job="api-server"} 1
   128  	{group="production", instance="1", job="api-server"} 1
   129  
   130  eval instant at 50m round(0.004 * http_requests{group="production",job="api-server"})
   131  	{group="production", instance="0", job="api-server"} 0
   132  	{group="production", instance="1", job="api-server"} 1
   133  
   134  # Round should correctly handle negative numbers.
   135  eval instant at 50m round(-1 * (0.004 * http_requests{group="production",job="api-server"}))
   136  	{group="production", instance="0", job="api-server"} 0
   137  	{group="production", instance="1", job="api-server"} -1
   138  
   139  # Round should round half up.
   140  eval instant at 50m round(0.005 * http_requests{group="production",job="api-server"})
   141  	{group="production", instance="0", job="api-server"} 1
   142  	{group="production", instance="1", job="api-server"} 1
   143  
   144  eval instant at 50m round(-1 * (0.005 * http_requests{group="production",job="api-server"}))
   145  	{group="production", instance="0", job="api-server"} 0
   146  	{group="production", instance="1", job="api-server"} -1
   147  
   148  eval instant at 50m round(1 + 0.005 * http_requests{group="production",job="api-server"})
   149  	{group="production", instance="0", job="api-server"} 2
   150  	{group="production", instance="1", job="api-server"} 2
   151  
   152  eval instant at 50m round(-1 * (1 + 0.005 * http_requests{group="production",job="api-server"}))
   153  	{group="production", instance="0", job="api-server"} -1
   154  	{group="production", instance="1", job="api-server"} -2
   155  
   156  # Round should accept the number to round nearest to.
   157  eval instant at 50m round(0.0005 * http_requests{group="production",job="api-server"}, 0.1)
   158  	{group="production", instance="0", job="api-server"} 0.1
   159  	{group="production", instance="1", job="api-server"} 0.1
   160  
   161  eval instant at 50m round(2.1 + 0.0005 * http_requests{group="production",job="api-server"}, 0.1)
   162  	{group="production", instance="0", job="api-server"} 2.2
   163  	{group="production", instance="1", job="api-server"} 2.2
   164  
   165  eval instant at 50m round(5.2 + 0.0005 * http_requests{group="production",job="api-server"}, 0.1)
   166  	{group="production", instance="0", job="api-server"} 5.3
   167  	{group="production", instance="1", job="api-server"} 5.3
   168  
   169  # Round should work correctly with negative numbers and multiple decimal places.
   170  eval instant at 50m round(-1 * (5.2 + 0.0005 * http_requests{group="production",job="api-server"}), 0.1)
   171  	{group="production", instance="0", job="api-server"} -5.2
   172  	{group="production", instance="1", job="api-server"} -5.3
   173  
   174  # Round should work correctly with big toNearests.
   175  eval instant at 50m round(0.025 * http_requests{group="production",job="api-server"}, 5)
   176  	{group="production", instance="0", job="api-server"} 5
   177  	{group="production", instance="1", job="api-server"} 5
   178  
   179  eval instant at 50m round(0.045 * http_requests{group="production",job="api-server"}, 5)
   180  	{group="production", instance="0", job="api-server"} 5
   181  	{group="production", instance="1", job="api-server"} 10
   182  
   183  # Standard deviation and variance.
   184  eval instant at 50m stddev(http_requests)
   185    {} 229.12878474779
   186  
   187  eval instant at 50m stddev by (instance)(http_requests)
   188    {instance="0"} 223.60679774998
   189    {instance="1"} 223.60679774998
   190  
   191  eval instant at 50m stdvar(http_requests)
   192    {} 52500
   193  
   194  eval instant at 50m stdvar by (instance)(http_requests)
   195    {instance="0"} 50000
   196    {instance="1"} 50000
   197  
   198  # Float precision test for standard deviation and variance
   199  clear
   200  load 5m
   201    http_requests{job="api-server", instance="0", group="production"} 0+1.33x10
   202    http_requests{job="api-server", instance="1", group="production"} 0+1.33x10
   203    http_requests{job="api-server", instance="0", group="canary"} 0+1.33x10
   204  
   205  eval instant at 50m stddev(http_requests)
   206    {} 0.0
   207  
   208  eval instant at 50m stdvar(http_requests)
   209    {} 0.0
   210  
   211  
   212  # Regression test for missing separator byte in labelsToGroupingKey.
   213  clear
   214  load 5m
   215    label_grouping_test{a="aa", b="bb"} 0+10x10
   216    label_grouping_test{a="a", b="abb"} 0+20x10
   217  
   218  eval instant at 50m sum(label_grouping_test) by (a, b)
   219    {a="a", b="abb"} 200
   220    {a="aa", b="bb"} 100
   221  
   222  
   223  
   224  # Tests for min/max.
   225  clear
   226  load 5m
   227    http_requests{job="api-server", instance="0", group="production"}	1
   228    http_requests{job="api-server", instance="1", group="production"}	2
   229    http_requests{job="api-server", instance="0", group="canary"}		NaN
   230    http_requests{job="api-server", instance="1", group="canary"}		3
   231    http_requests{job="api-server", instance="2", group="canary"}		4
   232  
   233  eval instant at 0m max(http_requests)
   234    {} 4
   235  
   236  eval instant at 0m min(http_requests)
   237    {} 1
   238  
   239  eval instant at 0m max by (group) (http_requests)
   240    {group="production"} 2
   241    {group="canary"} 4
   242  
   243  eval instant at 0m min by (group) (http_requests)
   244    {group="production"} 1
   245    {group="canary"} 3
   246  
   247  clear
   248  
   249  # Tests for topk/bottomk.
   250  load 5m
   251  	http_requests{job="api-server", instance="0", group="production"}	0+10x10
   252  	http_requests{job="api-server", instance="1", group="production"}	0+20x10
   253  	http_requests{job="api-server", instance="2", group="production"}	NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
   254  	http_requests{job="api-server", instance="0", group="canary"}		0+30x10
   255  	http_requests{job="api-server", instance="1", group="canary"}		0+40x10
   256  	http_requests{job="app-server", instance="0", group="production"}	0+50x10
   257  	http_requests{job="app-server", instance="1", group="production"}	0+60x10
   258  	http_requests{job="app-server", instance="0", group="canary"}		0+70x10
   259  	http_requests{job="app-server", instance="1", group="canary"}		0+80x10
   260  	foo 3+0x10
   261  
   262  eval_ordered instant at 50m topk(3, http_requests)
   263  	http_requests{group="canary", instance="1", job="app-server"} 800
   264  	http_requests{group="canary", instance="0", job="app-server"} 700
   265  	http_requests{group="production", instance="1", job="app-server"} 600
   266  
   267  eval_ordered instant at 50m topk((3), (http_requests))
   268  	http_requests{group="canary", instance="1", job="app-server"} 800
   269  	http_requests{group="canary", instance="0", job="app-server"} 700
   270  	http_requests{group="production", instance="1", job="app-server"} 600
   271  
   272  eval_ordered instant at 50m topk(5, http_requests{group="canary",job="app-server"})
   273  	http_requests{group="canary", instance="1", job="app-server"} 800
   274  	http_requests{group="canary", instance="0", job="app-server"} 700
   275  
   276  eval_ordered instant at 50m bottomk(3, http_requests)
   277  	http_requests{group="production", instance="0", job="api-server"} 100
   278  	http_requests{group="production", instance="1", job="api-server"} 200
   279  	http_requests{group="canary", instance="0", job="api-server"} 300
   280  
   281  eval_ordered instant at 50m bottomk(5, http_requests{group="canary",job="app-server"})
   282  	http_requests{group="canary", instance="0", job="app-server"} 700
   283  	http_requests{group="canary", instance="1", job="app-server"} 800
   284  
   285  eval instant at 50m topk by (group) (1, http_requests)
   286    http_requests{group="production", instance="1", job="app-server"} 600
   287    http_requests{group="canary", instance="1", job="app-server"} 800
   288  
   289  eval instant at 50m bottomk by (group) (2, http_requests)
   290    http_requests{group="canary", instance="0", job="api-server"} 300
   291    http_requests{group="canary", instance="1", job="api-server"} 400
   292    http_requests{group="production", instance="0", job="api-server"} 100
   293    http_requests{group="production", instance="1", job="api-server"} 200
   294  
   295  eval_ordered instant at 50m bottomk by (group) (2, http_requests{group="production"})
   296    http_requests{group="production", instance="0", job="api-server"} 100
   297    http_requests{group="production", instance="1", job="api-server"} 200
   298  
   299  # Test NaN is sorted away from the top/bottom.
   300  eval_ordered instant at 50m topk(3, http_requests{job="api-server",group="production"})
   301  	http_requests{job="api-server", instance="1", group="production"}	200
   302  	http_requests{job="api-server", instance="0", group="production"}	100
   303  	http_requests{job="api-server", instance="2", group="production"}	NaN
   304  
   305  eval_ordered instant at 50m bottomk(3, http_requests{job="api-server",group="production"})
   306  	http_requests{job="api-server", instance="0", group="production"}	100
   307  	http_requests{job="api-server", instance="1", group="production"}	200
   308  	http_requests{job="api-server", instance="2", group="production"}	NaN
   309  
   310  # Test topk and bottomk allocate min(k, input_vector) for results vector
   311  eval_ordered instant at 50m bottomk(9999999999, http_requests{job="app-server",group="canary"})
   312  	http_requests{group="canary", instance="0", job="app-server"} 700
   313  	http_requests{group="canary", instance="1", job="app-server"} 800
   314  
   315  eval_ordered instant at 50m topk(9999999999, http_requests{job="api-server",group="production"})
   316  	http_requests{job="api-server", instance="1", group="production"}	200
   317  	http_requests{job="api-server", instance="0", group="production"}	100
   318  	http_requests{job="api-server", instance="2", group="production"}	NaN
   319  
   320  # Bug #5276.
   321  eval_ordered instant at 50m topk(scalar(foo), http_requests)
   322  	http_requests{group="canary", instance="1", job="app-server"} 800
   323  	http_requests{group="canary", instance="0", job="app-server"} 700
   324  	http_requests{group="production", instance="1", job="app-server"} 600
   325  
   326  clear
   327  
   328  # Tests for count_values.
   329  load 5m
   330  	version{job="api-server", instance="0", group="production"}	6
   331  	version{job="api-server", instance="1", group="production"}	6
   332  	version{job="api-server", instance="2", group="production"}	6
   333  	version{job="api-server", instance="0", group="canary"}		8
   334  	version{job="api-server", instance="1", group="canary"}		8
   335  	version{job="app-server", instance="0", group="production"}	6
   336  	version{job="app-server", instance="1", group="production"}	6
   337  	version{job="app-server", instance="0", group="canary"}		7
   338  	version{job="app-server", instance="1", group="canary"}		7
   339  
   340  eval instant at 5m count_values("version", version)
   341  	{version="6"} 5
   342  	{version="7"} 2
   343  	{version="8"} 2
   344  
   345  
   346  eval instant at 5m count_values(((("version"))), version)
   347         {version="6"} 5
   348         {version="7"} 2
   349         {version="8"} 2
   350  
   351  
   352  eval instant at 5m count_values without (instance)("version", version)
   353  	{job="api-server", group="production", version="6"} 3
   354  	{job="api-server", group="canary", version="8"} 2
   355  	{job="app-server", group="production", version="6"} 2
   356  	{job="app-server", group="canary", version="7"} 2
   357  
   358  # Overwrite label with output. Don't do this.
   359  eval instant at 5m count_values without (instance)("job", version)
   360  	{job="6", group="production"} 5
   361  	{job="8", group="canary"} 2
   362  	{job="7", group="canary"} 2
   363  
   364  # Overwrite label with output. Don't do this.
   365  eval instant at 5m count_values by (job, group)("job", version)
   366  	{job="6", group="production"} 5
   367  	{job="8", group="canary"} 2
   368  	{job="7", group="canary"} 2
   369  
   370  
   371  # Tests for quantile.
   372  clear
   373  
   374  load 10s
   375  	data{test="two samples",point="a"} 0
   376  	data{test="two samples",point="b"} 1
   377  	data{test="three samples",point="a"} 0
   378  	data{test="three samples",point="b"} 1
   379  	data{test="three samples",point="c"} 2
   380  	data{test="uneven samples",point="a"} 0
   381  	data{test="uneven samples",point="b"} 1
   382  	data{test="uneven samples",point="c"} 4
   383  	foo .8
   384  
   385  eval instant at 1m quantile without(point)(0.8, data)
   386  	{test="two samples"} 0.8
   387  	{test="three samples"} 1.6
   388  	{test="uneven samples"} 2.8
   389  
   390  # Bug #5276.
   391  eval instant at 1m quantile without(point)(scalar(foo), data)
   392  	{test="two samples"} 0.8
   393  	{test="three samples"} 1.6
   394  	{test="uneven samples"} 2.8
   395  
   396  
   397  eval instant at 1m quantile without(point)((scalar(foo)), data)
   398  	{test="two samples"} 0.8
   399  	{test="three samples"} 1.6
   400  	{test="uneven samples"} 2.8
   401  
   402  # Tests for group.
   403  clear
   404  
   405  load 10s
   406  	data{test="two samples",point="a"} 0
   407  	data{test="two samples",point="b"} 1
   408  	data{test="three samples",point="a"} 0
   409  	data{test="three samples",point="b"} 1
   410  	data{test="three samples",point="c"} 2
   411  	data{test="uneven samples",point="a"} 0
   412  	data{test="uneven samples",point="b"} 1
   413  	data{test="uneven samples",point="c"} 4
   414  	foo .8
   415  
   416  eval instant at 1m group without(point)(data)
   417  	{test="two samples"} 1
   418  	{test="three samples"} 1
   419  	{test="uneven samples"} 1
   420  
   421  eval instant at 1m group(foo)
   422  	{} 1
   423  
   424  # Tests for avg.
   425  clear
   426  
   427  load 10s
   428  	data{test="ten",point="a"} 8
   429  	data{test="ten",point="b"} 10
   430  	data{test="ten",point="c"} 12
   431  	data{test="inf",point="a"} 0
   432  	data{test="inf",point="b"} Inf
   433  	data{test="inf",point="d"} Inf
   434  	data{test="inf",point="c"} 0
   435  	data{test="-inf",point="a"} -Inf
   436  	data{test="-inf",point="b"} -Inf
   437  	data{test="-inf",point="c"} 0
   438  	data{test="inf2",point="a"} Inf
   439  	data{test="inf2",point="b"} 0
   440  	data{test="inf2",point="c"} Inf
   441  	data{test="-inf2",point="a"} -Inf
   442  	data{test="-inf2",point="b"} 0
   443  	data{test="-inf2",point="c"} -Inf
   444  	data{test="inf3",point="b"} Inf
   445  	data{test="inf3",point="d"} Inf
   446  	data{test="inf3",point="c"} Inf
   447  	data{test="inf3",point="d"} -Inf
   448  	data{test="-inf3",point="b"} -Inf
   449  	data{test="-inf3",point="d"} -Inf
   450  	data{test="-inf3",point="c"} -Inf
   451  	data{test="-inf3",point="c"} Inf
   452  	data{test="nan",point="a"} -Inf
   453  	data{test="nan",point="b"} 0
   454  	data{test="nan",point="c"} Inf
   455  	data{test="big",point="a"} 9.988465674311579e+307
   456  	data{test="big",point="b"} 9.988465674311579e+307
   457  	data{test="big",point="c"} 9.988465674311579e+307
   458  	data{test="big",point="d"} 9.988465674311579e+307
   459  	data{test="-big",point="a"} -9.988465674311579e+307
   460  	data{test="-big",point="b"} -9.988465674311579e+307
   461  	data{test="-big",point="c"} -9.988465674311579e+307
   462  	data{test="-big",point="d"} -9.988465674311579e+307
   463  	data{test="bigzero",point="a"} -9.988465674311579e+307
   464  	data{test="bigzero",point="b"} -9.988465674311579e+307
   465  	data{test="bigzero",point="c"} 9.988465674311579e+307
   466  	data{test="bigzero",point="d"} 9.988465674311579e+307
   467  
   468  eval instant at 1m avg(data{test="ten"})
   469  	{} 10
   470  
   471  eval instant at 1m avg(data{test="inf"})
   472  	{} Inf
   473  
   474  eval instant at 1m avg(data{test="inf2"})
   475  	{} Inf
   476  
   477  eval instant at 1m avg(data{test="inf3"})
   478  	{} NaN
   479  
   480  eval instant at 1m avg(data{test="-inf"})
   481  	{} -Inf
   482  
   483  eval instant at 1m avg(data{test="-inf2"})
   484  	{} -Inf
   485  
   486  eval instant at 1m avg(data{test="-inf3"})
   487  	{} NaN
   488  
   489  eval instant at 1m avg(data{test="nan"})
   490  	{} NaN
   491  
   492  eval instant at 1m avg(data{test="big"})
   493  	{} 9.988465674311579e+307
   494  
   495  eval instant at 1m avg(data{test="-big"})
   496  	{} -9.988465674311579e+307
   497  
   498  eval instant at 1m avg(data{test="bigzero"})
   499  	{} 0