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

     1  # Testdata for resets() and changes().
     2  load 5m
     3  	http_requests{path="/foo"}	1 2 3 0 1 0 0 1 2 0
     4  	http_requests{path="/bar"}	1 2 3 4 5 1 2 3 4 5
     5  	http_requests{path="/biz"}	0 0 0 0 0 1 1 1 1 1
     6  
     7  # TODO(bwplotka): Tests for resets() were removed for now. See https://github.com/thanos-io/thanos/issues/3644
     8  
     9  # Tests for changes().
    10  eval instant at 50m changes(http_requests[5m])
    11  	{path="/foo"} 0
    12  	{path="/bar"} 0
    13  	{path="/biz"} 0
    14  
    15  eval instant at 50m changes(http_requests[20m])
    16  	{path="/foo"} 3
    17  	{path="/bar"} 3
    18  	{path="/biz"} 0
    19  
    20  eval instant at 50m changes(http_requests[30m])
    21  	{path="/foo"} 4
    22  	{path="/bar"} 5
    23  	{path="/biz"} 1
    24  
    25  eval instant at 50m changes(http_requests[50m])
    26  	{path="/foo"} 8
    27  	{path="/bar"} 9
    28  	{path="/biz"} 1
    29  
    30  eval instant at 50m changes((http_requests[50m]))
    31  	{path="/foo"} 8
    32  	{path="/bar"} 9
    33  	{path="/biz"} 1
    34  
    35  eval instant at 50m changes(nonexistent_metric[50m])
    36  
    37  clear
    38  
    39  load 5m
    40    x{a="b"} NaN NaN NaN
    41    x{a="c"} 0 NaN 0
    42  
    43  eval instant at 15m changes(x[15m])
    44    {a="b"} 0
    45    {a="c"} 2
    46  
    47  clear
    48  
    49  # Tests for increase().
    50  load 5m
    51  	http_requests{path="/foo"}	0+10x10
    52  	http_requests{path="/bar"}	0+10x5 0+10x5
    53  
    54  # Tests for increase().
    55  eval instant at 50m increase(http_requests[50m])
    56  	{path="/foo"} 100
    57  	{path="/bar"}  90
    58  
    59  eval instant at 50m increase(http_requests[100m])
    60  	{path="/foo"} 100
    61  	{path="/bar"}  90
    62  
    63  clear
    64  
    65  # Test for increase() with counter reset.
    66  # When the counter is reset, it always starts at 0.
    67  # So the sequence 3 2 (decreasing counter = reset) is interpreted the same as 3 0 1 2.
    68  # Prometheus assumes it missed the intermediate values 0 and 1.
    69  load 5m
    70  	http_requests{path="/foo"}	0 1 2 3 2 3 4
    71  
    72  eval instant at 30m increase(http_requests[30m])
    73      {path="/foo"} 7
    74  
    75  clear
    76  
    77  # Tests for rate().
    78  load 5m
    79  	testcounter_reset_middle	0+10x4 0+10x5
    80  	testcounter_reset_end    	0+10x9 0 10
    81  
    82  # Counter resets at in the middle of range are handled correctly by rate().
    83  eval instant at 50m rate(testcounter_reset_middle[50m])
    84  	{} 0.03
    85  
    86  # Counter resets at end of range are ignored by rate().
    87  eval instant at 50m rate(testcounter_reset_end[5m])
    88  	{} 0
    89  
    90  clear
    91  
    92  load 5m
    93  	calculate_rate_offset{x="a"}	0+10x10
    94  	calculate_rate_offset{x="b"}	0+20x10
    95  	calculate_rate_window		0+80x10
    96  
    97  # Rates should calculate per-second rates.
    98  eval instant at 50m rate(calculate_rate_window[50m])
    99  	{} 0.26666666666666666
   100  
   101  eval instant at 50m rate(calculate_rate_offset[10m] offset 5m)
   102  	{x="a"} 0.03333333333333333
   103  	{x="b"} 0.06666666666666667
   104  
   105  clear
   106  
   107  load 4m
   108  	testcounter_zero_cutoff{start="0m"}	0+240x10
   109  	testcounter_zero_cutoff{start="1m"}	60+240x10
   110  	testcounter_zero_cutoff{start="2m"}	120+240x10
   111  	testcounter_zero_cutoff{start="3m"}	180+240x10
   112  	testcounter_zero_cutoff{start="4m"}	240+240x10
   113  	testcounter_zero_cutoff{start="5m"}	300+240x10
   114  
   115  # Zero cutoff for left-side extrapolation.
   116  eval instant at 10m rate(testcounter_zero_cutoff[20m])
   117  	{start="0m"} 0.5
   118  	{start="1m"} 0.55
   119  	{start="2m"} 0.6
   120  	{start="3m"} 0.65
   121  	{start="4m"} 0.7
   122  	{start="5m"} 0.6
   123  
   124  # Normal half-interval cutoff for left-side extrapolation.
   125  eval instant at 50m rate(testcounter_zero_cutoff[20m])
   126  	{start="0m"} 0.6
   127  	{start="1m"} 0.6
   128  	{start="2m"} 0.6
   129  	{start="3m"} 0.6
   130  	{start="4m"} 0.6
   131  	{start="5m"} 0.6
   132  
   133  clear
   134  
   135  # Tests for irate().
   136  load 5m
   137  	http_requests{path="/foo"}	0+10x10
   138  	http_requests{path="/bar"}	0+10x5 0+10x5
   139  
   140  eval instant at 50m irate(http_requests[50m])
   141  	{path="/foo"} .03333333333333333333
   142  	{path="/bar"} .03333333333333333333
   143  
   144  # Counter reset.
   145  eval instant at 30m irate(http_requests[50m])
   146  	{path="/foo"} .03333333333333333333
   147  	{path="/bar"} 0
   148  
   149  clear
   150  
   151  # Tests for delta().
   152  load 5m
   153  	http_requests{path="/foo"}	0 50 100 150 200
   154  	http_requests{path="/bar"}	200 150 100 50 0
   155  
   156  eval instant at 20m delta(http_requests[20m])
   157  	{path="/foo"} 200
   158  	{path="/bar"} -200
   159  
   160  clear
   161  
   162  # Tests for idelta().
   163  load 5m
   164  	http_requests{path="/foo"}	0 50 100 150
   165  	http_requests{path="/bar"}	0 50 100 50
   166  
   167  eval instant at 20m idelta(http_requests[20m])
   168  	{path="/foo"} 50
   169  	{path="/bar"} -50
   170  
   171  clear
   172  
   173  # Tests for deriv() and predict_linear().
   174  load 5m
   175  	testcounter_reset_middle	0+10x4 0+10x5
   176  	http_requests{job="app-server", instance="1", group="canary"}		0+80x10
   177  
   178  # deriv should return the same as rate in simple cases.
   179  eval instant at 50m rate(http_requests{group="canary", instance="1", job="app-server"}[50m])
   180  	{group="canary", instance="1", job="app-server"} 0.26666666666666666
   181  
   182  eval instant at 50m deriv(http_requests{group="canary", instance="1", job="app-server"}[50m])
   183  	{group="canary", instance="1", job="app-server"} 0.26666666666666666
   184  
   185  # deriv should return correct result.
   186  eval instant at 50m deriv(testcounter_reset_middle[100m])
   187  	{} 0.010606060606060607
   188  
   189  # predict_linear should return correct result.
   190  # X/s = [  0, 300, 600, 900,1200,1500,1800,2100,2400,2700,3000]
   191  # Y   = [  0,  10,  20,  30,  40,   0,  10,  20,  30,  40,  50]
   192  # sumX  = 16500
   193  # sumY  = 250
   194  # sumXY = 480000
   195  # sumX2 = 34650000
   196  # n     = 11
   197  # covXY = 105000
   198  # varX  = 9900000
   199  # slope = 0.010606060606060607
   200  # intercept at t=0: 6.818181818181818
   201  # intercept at t=3000: 38.63636363636364
   202  # intercept at t=3000+3600: 76.81818181818181
   203  eval instant at 50m predict_linear(testcounter_reset_middle[100m], 3600)
   204  	{} 76.81818181818181
   205  
   206  # With http_requests, there is a sample value exactly at the end of
   207  # the range, and it has exactly the predicted value, so predict_linear
   208  # can be emulated with deriv.
   209  eval instant at 50m predict_linear(http_requests[50m], 3600) - (http_requests + deriv(http_requests[50m]) * 3600)
   210  	{group="canary", instance="1", job="app-server"} 0
   211  
   212  clear
   213  
   214  # Tests for label_replace.
   215  load 5m
   216    testmetric{src="source-value-10",dst="original-destination-value"} 0
   217    testmetric{src="source-value-20",dst="original-destination-value"} 1
   218  
   219  # label_replace does a full-string match and replace.
   220  eval instant at 0m label_replace(testmetric, "dst", "destination-value-$1", "src", "source-value-(.*)")
   221    testmetric{src="source-value-10",dst="destination-value-10"} 0
   222    testmetric{src="source-value-20",dst="destination-value-20"} 1
   223  
   224  # label_replace does not do a sub-string match.
   225  eval instant at 0m label_replace(testmetric, "dst", "destination-value-$1", "src", "value-(.*)")
   226    testmetric{src="source-value-10",dst="original-destination-value"} 0
   227    testmetric{src="source-value-20",dst="original-destination-value"} 1
   228  
   229  # label_replace works with multiple capture groups.
   230  eval instant at 0m label_replace(testmetric, "dst", "$1-value-$2", "src", "(.*)-value-(.*)")
   231    testmetric{src="source-value-10",dst="source-value-10"} 0
   232    testmetric{src="source-value-20",dst="source-value-20"} 1
   233  
   234  # label_replace does not overwrite the destination label if the source label
   235  # does not exist.
   236  eval instant at 0m label_replace(testmetric, "dst", "value-$1", "nonexistent-src", "source-value-(.*)")
   237    testmetric{src="source-value-10",dst="original-destination-value"} 0
   238    testmetric{src="source-value-20",dst="original-destination-value"} 1
   239  
   240  # label_replace overwrites the destination label if the source label is empty,
   241  # but matched.
   242  eval instant at 0m label_replace(testmetric, "dst", "value-$1", "nonexistent-src", "(.*)")
   243    testmetric{src="source-value-10",dst="value-"} 0
   244    testmetric{src="source-value-20",dst="value-"} 1
   245  
   246  # label_replace does not overwrite the destination label if the source label
   247  # is not matched.
   248  eval instant at 0m label_replace(testmetric, "dst", "value-$1", "src", "non-matching-regex")
   249    testmetric{src="source-value-10",dst="original-destination-value"} 0
   250    testmetric{src="source-value-20",dst="original-destination-value"} 1
   251  
   252  eval instant at 0m label_replace((((testmetric))), (("dst")), (("value-$1")), (("src")), (("non-matching-regex")))
   253    testmetric{src="source-value-10",dst="original-destination-value"} 0
   254    testmetric{src="source-value-20",dst="original-destination-value"} 1
   255  
   256  # label_replace drops labels that are set to empty values.
   257  eval instant at 0m label_replace(testmetric, "dst", "", "dst", ".*")
   258    testmetric{src="source-value-10"} 0
   259    testmetric{src="source-value-20"} 1
   260  
   261  # label_replace fails when the regex is invalid.
   262  eval_fail instant at 0m label_replace(testmetric, "dst", "value-$1", "src", "(.*")
   263  
   264  # label_replace fails when the destination label name is not a valid Prometheus label name.
   265  eval_fail instant at 0m label_replace(testmetric, "invalid-label-name", "", "src", "(.*)")
   266  
   267  # label_replace fails when there would be duplicated identical output label sets.
   268  eval_fail instant at 0m label_replace(testmetric, "src", "", "", "")
   269  
   270  clear
   271  
   272  # Tests for vector, time and timestamp.
   273  load 10s
   274    metric 1 1
   275  
   276  eval instant at 0s timestamp(metric)
   277    {} 0
   278  
   279  eval instant at 5s timestamp(metric)
   280    {} 0
   281  
   282  eval instant at 5s timestamp(((metric)))
   283    {} 0
   284  
   285  eval instant at 10s timestamp(metric)
   286    {} 10
   287  
   288  eval instant at 10s timestamp(((metric)))
   289    {} 10
   290  
   291  # Tests for label_join.
   292  load 5m
   293    testmetric{src="a",src1="b",src2="c",dst="original-destination-value"} 0
   294    testmetric{src="d",src1="e",src2="f",dst="original-destination-value"} 1
   295  
   296  # label_join joins all src values in order.
   297  eval instant at 0m label_join(testmetric, "dst", "-", "src", "src1", "src2")
   298    testmetric{src="a",src1="b",src2="c",dst="a-b-c"} 0
   299    testmetric{src="d",src1="e",src2="f",dst="d-e-f"} 1
   300  
   301  # label_join treats non existent src labels as empty strings.
   302  eval instant at 0m label_join(testmetric, "dst", "-", "src", "src3", "src1")
   303    testmetric{src="a",src1="b",src2="c",dst="a--b"} 0
   304    testmetric{src="d",src1="e",src2="f",dst="d--e"} 1
   305  
   306  # label_join overwrites the destination label even if the resulting dst label is empty string
   307  eval instant at 0m label_join(testmetric, "dst", "", "emptysrc", "emptysrc1", "emptysrc2")
   308    testmetric{src="a",src1="b",src2="c"} 0
   309    testmetric{src="d",src1="e",src2="f"} 1
   310  
   311  # test without src label for label_join
   312  eval instant at 0m label_join(testmetric, "dst", ", ")
   313  	  testmetric{src="a",src1="b",src2="c"} 0
   314  	  testmetric{src="d",src1="e",src2="f"} 1
   315  
   316  # test without dst label for label_join
   317  load 5m
   318    testmetric1{src="foo",src1="bar",src2="foobar"} 0
   319    testmetric1{src="fizz",src1="buzz",src2="fizzbuzz"} 1
   320  
   321  # label_join creates dst label if not present.
   322  eval instant at 0m label_join(testmetric1, "dst", ", ", "src", "src1", "src2")
   323    testmetric1{src="foo",src1="bar",src2="foobar",dst="foo, bar, foobar"} 0
   324    testmetric1{src="fizz",src1="buzz",src2="fizzbuzz",dst="fizz, buzz, fizzbuzz"} 1
   325  
   326  clear
   327  
   328  # Tests for vector.
   329  eval instant at 0m vector(1)
   330    {} 1
   331  
   332  eval instant at 0s vector(time())
   333    {} 0
   334  
   335  eval instant at 5s vector(time())
   336    {} 5
   337  
   338  eval instant at 60m vector(time())
   339    {} 3600
   340  
   341  
   342  # Tests for clamp_max and clamp_min().
   343  load 5m
   344  	test_clamp{src="clamp-a"}	-50
   345  	test_clamp{src="clamp-b"}	0
   346  	test_clamp{src="clamp-c"}	100
   347  
   348  eval instant at 0m clamp_max(test_clamp, 75)
   349  	{src="clamp-a"}	-50
   350  	{src="clamp-b"}	0
   351  	{src="clamp-c"}	75
   352  
   353  eval instant at 0m clamp_min(test_clamp, -25)
   354  	{src="clamp-a"}	-25
   355  	{src="clamp-b"}	0
   356  	{src="clamp-c"}	100
   357  
   358  eval instant at 0m clamp_max(clamp_min(test_clamp, -20), 70)
   359  	{src="clamp-a"}	-20
   360  	{src="clamp-b"}	0
   361  	{src="clamp-c"}	70
   362  
   363  eval instant at 0m clamp_max((clamp_min(test_clamp, (-20))), (70))
   364  	{src="clamp-a"}	-20
   365  	{src="clamp-b"}	0
   366  	{src="clamp-c"}	70
   367  
   368  
   369  # Tests for sort/sort_desc.
   370  clear
   371  load 5m
   372  	http_requests{job="api-server", instance="0", group="production"}	0+10x10
   373  	http_requests{job="api-server", instance="1", group="production"}	0+20x10
   374  	http_requests{job="api-server", instance="0", group="canary"}		0+30x10
   375  	http_requests{job="api-server", instance="1", group="canary"}		0+40x10
   376  	http_requests{job="api-server", instance="2", group="canary"}		NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
   377  	http_requests{job="app-server", instance="0", group="production"}	0+50x10
   378  	http_requests{job="app-server", instance="1", group="production"}	0+60x10
   379  	http_requests{job="app-server", instance="0", group="canary"}		0+70x10
   380  	http_requests{job="app-server", instance="1", group="canary"}		0+80x10
   381  
   382  eval_ordered instant at 50m sort(http_requests)
   383  	http_requests{group="production", instance="0", job="api-server"} 100
   384  	http_requests{group="production", instance="1", job="api-server"} 200
   385  	http_requests{group="canary", instance="0", job="api-server"} 300
   386  	http_requests{group="canary", instance="1", job="api-server"} 400
   387  	http_requests{group="production", instance="0", job="app-server"} 500
   388  	http_requests{group="production", instance="1", job="app-server"} 600
   389  	http_requests{group="canary", instance="0", job="app-server"} 700
   390  	http_requests{group="canary", instance="1", job="app-server"} 800
   391  	http_requests{group="canary", instance="2", job="api-server"} NaN
   392  
   393  eval_ordered instant at 50m sort_desc(http_requests)
   394  	http_requests{group="canary", instance="1", job="app-server"} 800
   395  	http_requests{group="canary", instance="0", job="app-server"} 700
   396  	http_requests{group="production", instance="1", job="app-server"} 600
   397  	http_requests{group="production", instance="0", job="app-server"} 500
   398  	http_requests{group="canary", instance="1", job="api-server"} 400
   399  	http_requests{group="canary", instance="0", job="api-server"} 300
   400  	http_requests{group="production", instance="1", job="api-server"} 200
   401  	http_requests{group="production", instance="0", job="api-server"} 100
   402  	http_requests{group="canary", instance="2", job="api-server"} NaN
   403  
   404  # Tests for holt_winters
   405  clear
   406  
   407  # positive trends
   408  load 10s
   409  	http_requests{job="api-server", instance="0", group="production"}	0+10x1000 100+30x1000
   410  	http_requests{job="api-server", instance="1", group="production"}	0+20x1000 200+30x1000
   411  	http_requests{job="api-server", instance="0", group="canary"}		0+30x1000 300+80x1000
   412  	http_requests{job="api-server", instance="1", group="canary"}		0+40x2000
   413  
   414  eval instant at 8000s holt_winters(http_requests[1m], 0.01, 0.1)
   415  	{job="api-server", instance="0", group="production"} 8000
   416  	{job="api-server", instance="1", group="production"} 16000
   417  	{job="api-server", instance="0", group="canary"} 24000
   418  	{job="api-server", instance="1", group="canary"} 32000
   419  
   420  # negative trends
   421  clear
   422  load 10s
   423  	http_requests{job="api-server", instance="0", group="production"}	8000-10x1000
   424  	http_requests{job="api-server", instance="1", group="production"}	0-20x1000
   425  	http_requests{job="api-server", instance="0", group="canary"}		0+30x1000 300-80x1000
   426  	http_requests{job="api-server", instance="1", group="canary"}		0-40x1000 0+40x1000
   427  
   428  eval instant at 8000s holt_winters(http_requests[1m], 0.01, 0.1)
   429  	{job="api-server", instance="0", group="production"} 0
   430  	{job="api-server", instance="1", group="production"} -16000
   431  	{job="api-server", instance="0", group="canary"} 24000
   432  	{job="api-server", instance="1", group="canary"} -32000
   433  
   434  # Tests for avg_over_time
   435  clear
   436  load 10s
   437    metric 1 2 3 4 5
   438    metric2 1 2 3 4 Inf
   439    metric3 1 2 3 4 -Inf
   440    metric4 1 2 3 Inf -Inf
   441    metric5 Inf 0 Inf
   442    metric5b Inf 0 Inf
   443    metric5c Inf Inf Inf -Inf
   444    metric6 1 2 3 -Inf -Inf
   445    metric6b -Inf 0 -Inf
   446    metric6c -Inf -Inf -Inf Inf
   447    metric7 1 2 -Inf -Inf Inf
   448    metric8 9.988465674311579e+307 9.988465674311579e+307
   449    metric9 -9.988465674311579e+307 -9.988465674311579e+307 -9.988465674311579e+307
   450    metric10 -9.988465674311579e+307 9.988465674311579e+307
   451  
   452  eval instant at 1m avg_over_time(metric[1m])
   453    {} 3
   454  
   455  eval instant at 1m sum_over_time(metric[1m])/count_over_time(metric[1m])
   456    {} 3
   457  
   458  eval instant at 1m avg_over_time(metric2[1m])
   459    {} Inf
   460  
   461  eval instant at 1m sum_over_time(metric2[1m])/count_over_time(metric2[1m])
   462    {} Inf
   463  
   464  eval instant at 1m avg_over_time(metric3[1m])
   465    {} -Inf
   466  
   467  eval instant at 1m sum_over_time(metric3[1m])/count_over_time(metric3[1m])
   468    {} -Inf
   469  
   470  eval instant at 1m avg_over_time(metric4[1m])
   471    {} NaN
   472  
   473  eval instant at 1m sum_over_time(metric4[1m])/count_over_time(metric4[1m])
   474    {} NaN
   475  
   476  eval instant at 1m avg_over_time(metric5[1m])
   477    {} Inf
   478  
   479  eval instant at 1m sum_over_time(metric5[1m])/count_over_time(metric5[1m])
   480    {} Inf
   481  
   482  eval instant at 1m avg_over_time(metric5b[1m])
   483    {} Inf
   484  
   485  eval instant at 1m sum_over_time(metric5b[1m])/count_over_time(metric5b[1m])
   486    {} Inf
   487  
   488  eval instant at 1m avg_over_time(metric5c[1m])
   489    {} NaN
   490  
   491  eval instant at 1m sum_over_time(metric5c[1m])/count_over_time(metric5c[1m])
   492    {} NaN
   493  
   494  eval instant at 1m avg_over_time(metric6[1m])
   495    {} -Inf
   496  
   497  eval instant at 1m sum_over_time(metric6[1m])/count_over_time(metric6[1m])
   498    {} -Inf
   499  
   500  eval instant at 1m avg_over_time(metric6b[1m])
   501    {} -Inf
   502  
   503  eval instant at 1m sum_over_time(metric6b[1m])/count_over_time(metric6b[1m])
   504    {} -Inf
   505  
   506  eval instant at 1m avg_over_time(metric6c[1m])
   507    {} NaN
   508  
   509  eval instant at 1m sum_over_time(metric6c[1m])/count_over_time(metric6c[1m])
   510    {} NaN
   511  
   512  
   513  eval instant at 1m avg_over_time(metric7[1m])
   514    {} NaN
   515  
   516  eval instant at 1m sum_over_time(metric7[1m])/count_over_time(metric7[1m])
   517    {} NaN
   518  
   519  eval instant at 1m avg_over_time(metric8[1m])
   520    {} 9.988465674311579e+307
   521  
   522  # This overflows float64.
   523  eval instant at 1m sum_over_time(metric8[1m])/count_over_time(metric8[1m])
   524    {} Inf
   525  
   526  eval instant at 1m avg_over_time(metric9[1m])
   527    {} -9.988465674311579e+307
   528  
   529  # This overflows float64.
   530  eval instant at 1m sum_over_time(metric9[1m])/count_over_time(metric9[1m])
   531    {} -Inf
   532  
   533  eval instant at 1m avg_over_time(metric10[1m])
   534    {} 0
   535  
   536  eval instant at 1m sum_over_time(metric10[1m])/count_over_time(metric10[1m])
   537    {} 0
   538  
   539  # Tests for stddev_over_time and stdvar_over_time.
   540  clear
   541  load 10s
   542    metric 0 8 8 2 3
   543  
   544  eval instant at 1m stdvar_over_time(metric[1m])
   545    {} 10.56
   546  
   547  eval instant at 1m stddev_over_time(metric[1m])
   548    {} 3.249615
   549  
   550  eval instant at 1m stddev_over_time((metric[1m]))
   551    {} 3.249615
   552  
   553  # Tests for stddev_over_time and stdvar_over_time #4927.
   554  clear
   555  load 10s
   556    metric 1.5990505637277868 1.5990505637277868 1.5990505637277868
   557  
   558  eval instant at 1m stdvar_over_time(metric[1m])
   559    {} 0
   560  
   561  eval instant at 1m stddev_over_time(metric[1m])
   562    {} 0
   563  
   564  # Tests for quantile_over_time
   565  clear
   566  
   567  load 10s
   568  	data{test="two samples"} 0 1
   569  	data{test="three samples"} 0 1 2
   570  	data{test="uneven samples"} 0 1 4
   571  
   572  eval instant at 1m quantile_over_time(0, data[1m])
   573  	{test="two samples"} 0
   574  	{test="three samples"} 0
   575  	{test="uneven samples"} 0
   576  
   577  eval instant at 1m quantile_over_time(0.5, data[1m])
   578  	{test="two samples"} 0.5
   579  	{test="three samples"} 1
   580  	{test="uneven samples"} 1
   581  
   582  eval instant at 1m quantile_over_time(0.75, data[1m])
   583  	{test="two samples"} 0.75
   584  	{test="three samples"} 1.5
   585  	{test="uneven samples"} 2.5
   586  
   587  eval instant at 1m quantile_over_time(0.8, data[1m])
   588  	{test="two samples"} 0.8
   589  	{test="three samples"} 1.6
   590  	{test="uneven samples"} 2.8
   591  
   592  eval instant at 1m quantile_over_time(1, data[1m])
   593  	{test="two samples"} 1
   594  	{test="three samples"} 2
   595  	{test="uneven samples"} 4
   596  
   597  eval instant at 1m quantile_over_time(-1, data[1m])
   598  	{test="two samples"} -Inf
   599  	{test="three samples"} -Inf
   600  	{test="uneven samples"} -Inf
   601  
   602  eval instant at 1m quantile_over_time(2, data[1m])
   603  	{test="two samples"} +Inf
   604  	{test="three samples"} +Inf
   605  	{test="uneven samples"} +Inf
   606  
   607  eval instant at 1m (quantile_over_time(2, (data[1m])))
   608  	{test="two samples"} +Inf
   609  	{test="three samples"} +Inf
   610  	{test="uneven samples"} +Inf
   611  
   612  clear
   613  
   614  # Test time-related functions.
   615  eval instant at 0m year()
   616    {} 1970
   617  
   618  eval instant at 1ms time()
   619    0.001
   620  
   621  eval instant at 50m time()
   622    3000
   623  
   624  eval instant at 0m year(vector(1136239445))
   625    {} 2006
   626  
   627  eval instant at 0m month()
   628    {} 1
   629  
   630  eval instant at 0m month(vector(1136239445))
   631    {} 1
   632  
   633  eval instant at 0m day_of_month()
   634    {} 1
   635  
   636  eval instant at 0m day_of_month(vector(1136239445))
   637    {} 2
   638  
   639  # Thursday.
   640  eval instant at 0m day_of_week()
   641    {} 4
   642  
   643  eval instant at 0m day_of_week(vector(1136239445))
   644    {} 1
   645  
   646  eval instant at 0m hour()
   647    {} 0
   648  
   649  eval instant at 0m hour(vector(1136239445))
   650    {} 22
   651  
   652  eval instant at 0m minute()
   653    {} 0
   654  
   655  eval instant at 0m minute(vector(1136239445))
   656    {} 4
   657  
   658  # 2008-12-31 23:59:59 just before leap second.
   659  eval instant at 0m year(vector(1230767999))
   660    {} 2008
   661  
   662  # 2009-01-01 00:00:00 just after leap second.
   663  eval instant at 0m year(vector(1230768000))
   664    {} 2009
   665  
   666  # 2016-02-29 23:59:59 February 29th in leap year.
   667  eval instant at 0m month(vector(1456790399)) + day_of_month(vector(1456790399)) / 100
   668    {} 2.29
   669  
   670  # 2016-03-01 00:00:00 March 1st in leap year.
   671  eval instant at 0m month(vector(1456790400)) + day_of_month(vector(1456790400)) / 100
   672    {} 3.01
   673  
   674  # February 1st 2016 in leap year.
   675  eval instant at 0m days_in_month(vector(1454284800))
   676    {} 29
   677  
   678  # February 1st 2017 not in leap year.
   679  eval instant at 0m days_in_month(vector(1485907200))
   680    {} 28
   681  
   682  clear
   683  
   684  # Test duplicate labelset in promql output.
   685  load 5m
   686    testmetric1{src="a",dst="b"} 0
   687    testmetric2{src="a",dst="b"} 1
   688  
   689  eval_fail instant at 0m changes({__name__=~'testmetric1|testmetric2'}[5m])
   690  
   691  # Tests for *_over_time
   692  clear
   693  
   694  load 10s
   695  	data{type="numbers"} 2 0 3
   696  	data{type="some_nan"} 2 0 NaN
   697  	data{type="some_nan2"} 2 NaN 1
   698  	data{type="some_nan3"} NaN 0 1
   699  	data{type="only_nan"} NaN NaN NaN
   700  
   701  eval instant at 1m min_over_time(data[1m])
   702  	{type="numbers"} 0
   703  	{type="some_nan"} 0
   704  	{type="some_nan2"} 1
   705  	{type="some_nan3"} 0
   706  	{type="only_nan"} NaN
   707  
   708  eval instant at 1m max_over_time(data[1m])
   709  	{type="numbers"} 3
   710  	{type="some_nan"} 2
   711  	{type="some_nan2"} 2
   712  	{type="some_nan3"} 1
   713  	{type="only_nan"} NaN
   714  
   715  clear
   716  
   717  # Test for absent()
   718  eval instant at 50m absent(nonexistent)
   719  	{} 1
   720  
   721  eval instant at 50m absent(nonexistent{job="testjob", instance="testinstance", method=~".x"})
   722  	{instance="testinstance", job="testjob"} 1
   723  
   724  eval instant at 50m absent(nonexistent{job="testjob",job="testjob2",foo="bar"})
   725  	{foo="bar"} 1
   726  
   727  eval instant at 50m absent(nonexistent{job="testjob",job="testjob2",job="three",foo="bar"})
   728  	{foo="bar"} 1
   729  
   730  eval instant at 50m absent(nonexistent{job="testjob",job=~"testjob2",foo="bar"})
   731  	{foo="bar"} 1
   732  
   733  clear
   734  
   735  # Don't return anything when there's something there.
   736  load 5m
   737  	http_requests{job="api-server", instance="0", group="production"}	0+10x10
   738  
   739  eval instant at 50m absent(http_requests)
   740  
   741  eval instant at 50m absent(sum(http_requests))
   742  
   743  clear
   744  
   745  eval instant at 50m absent(sum(nonexistent{job="testjob", instance="testinstance"}))
   746  	{} 1
   747  
   748  eval instant at 50m absent(max(nonexistant))
   749  	{} 1
   750  
   751  eval instant at 50m absent(nonexistant > 1)
   752  	{} 1
   753  
   754  eval instant at 50m absent(a + b)
   755  	{} 1
   756  
   757  eval instant at 50m absent(a and b)
   758  	{} 1
   759  
   760  eval instant at 50m absent(rate(nonexistant[5m]))
   761  	{} 1
   762  
   763  clear
   764  
   765  # Testdata for absent_over_time()
   766  eval instant at 1m absent_over_time(http_requests[5m])
   767      {} 1
   768  
   769  eval instant at 1m absent_over_time(http_requests{handler="/foo"}[5m])
   770      {handler="/foo"} 1
   771  
   772  eval instant at 1m absent_over_time(http_requests{handler!="/foo"}[5m])
   773      {} 1
   774  
   775  eval instant at 1m absent_over_time(http_requests{handler="/foo", handler="/bar", handler="/foobar"}[5m])
   776      {} 1
   777  
   778  eval instant at 1m absent_over_time(rate(nonexistant[5m])[5m:])
   779      {} 1
   780  
   781  eval instant at 1m absent_over_time(http_requests{handler="/foo", handler="/bar", instance="127.0.0.1"}[5m])
   782      {instance="127.0.0.1"} 1
   783  
   784  load 1m
   785  	http_requests{path="/foo",instance="127.0.0.1",job="httpd"}	1+1x10
   786  	http_requests{path="/bar",instance="127.0.0.1",job="httpd"}	1+1x10
   787  	httpd_handshake_failures_total{instance="127.0.0.1",job="node"}	1+1x15
   788  	httpd_log_lines_total{instance="127.0.0.1",job="node"}	1
   789  	ssl_certificate_expiry_seconds{job="ingress"} NaN NaN NaN NaN NaN
   790  
   791  eval instant at 5m absent_over_time(http_requests[5m])
   792  
   793  eval instant at 5m absent_over_time(rate(http_requests[5m])[5m:1m])
   794  
   795  eval instant at 0m absent_over_time(httpd_log_lines_total[30s])
   796  
   797  eval instant at 1m absent_over_time(httpd_log_lines_total[30s])
   798      {} 1
   799  
   800  eval instant at 15m absent_over_time(http_requests[5m])
   801  
   802  eval instant at 16m absent_over_time(http_requests[5m])
   803      {} 1
   804  
   805  eval instant at 16m absent_over_time(http_requests[6m])
   806  
   807  eval instant at 16m absent_over_time(httpd_handshake_failures_total[1m])
   808  
   809  eval instant at 16m absent_over_time({instance="127.0.0.1"}[5m])
   810  
   811  eval instant at 16m absent_over_time({instance="127.0.0.1"}[5m])
   812  
   813  eval instant at 21m absent_over_time({instance="127.0.0.1"}[5m])
   814      {instance="127.0.0.1"} 1
   815  
   816  eval instant at 21m absent_over_time({instance="127.0.0.1"}[20m])
   817  
   818  eval instant at 21m absent_over_time({job="grok"}[20m])
   819      {job="grok"} 1
   820  
   821  eval instant at 30m absent_over_time({instance="127.0.0.1"}[5m:5s])
   822      {} 1
   823  
   824  eval instant at 5m absent_over_time({job="ingress"}[4m])
   825  
   826  eval instant at 10m absent_over_time({job="ingress"}[4m])
   827  	{job="ingress"} 1
   828  
   829  clear
   830  
   831  # Testing exp() sqrt() log2() log10() ln()
   832  load 5m
   833  	exp_root_log{l="x"} 10
   834  	exp_root_log{l="y"} 20
   835  
   836  eval instant at 5m exp(exp_root_log)
   837  	{l="x"} 22026.465794806718
   838  	{l="y"} 485165195.4097903
   839  
   840  eval instant at 5m exp(exp_root_log - 10)
   841  	{l="y"} 22026.465794806718
   842  	{l="x"} 1
   843  
   844  eval instant at 5m exp(exp_root_log - 20)
   845  	{l="x"} 4.5399929762484854e-05
   846  	{l="y"} 1
   847  
   848  eval instant at 5m ln(exp_root_log)
   849  	{l="x"} 2.302585092994046
   850  	{l="y"} 2.995732273553991
   851  
   852  eval instant at 5m ln(exp_root_log - 10)
   853  	{l="y"} 2.302585092994046
   854  	{l="x"} -Inf
   855  
   856  eval instant at 5m ln(exp_root_log - 20)
   857  	{l="y"} -Inf
   858  	{l="x"} NaN
   859  
   860  eval instant at 5m exp(ln(exp_root_log))
   861  	{l="y"} 20
   862  	{l="x"} 10
   863  
   864  eval instant at 5m sqrt(exp_root_log)
   865  	{l="x"} 3.1622776601683795
   866  	{l="y"} 4.47213595499958
   867  
   868  eval instant at 5m log2(exp_root_log)
   869  	{l="x"} 3.3219280948873626
   870  	{l="y"} 4.321928094887363
   871  
   872  eval instant at 5m log2(exp_root_log - 10)
   873  	{l="y"} 3.3219280948873626
   874  	{l="x"} -Inf
   875  
   876  eval instant at 5m log2(exp_root_log - 20)
   877  	{l="x"} NaN
   878  	{l="y"} -Inf
   879  
   880  eval instant at 5m log10(exp_root_log)
   881  	{l="x"} 1
   882  	{l="y"} 1.301029995663981
   883  
   884  eval instant at 5m log10(exp_root_log - 10)
   885  	{l="y"} 1
   886  	{l="x"} -Inf
   887  
   888  eval instant at 5m log10(exp_root_log - 20)
   889  	{l="x"} NaN
   890  	{l="y"} -Inf
   891  
   892  clear