github.com/thanos-io/thanos@v0.32.5/pkg/query/testdata/promql/prometheus/operators.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 vector_matching_a{l="x"} 0+1x100 13 vector_matching_a{l="y"} 0+2x50 14 vector_matching_b{l="x"} 0+4x25 15 16 17 eval instant at 50m SUM(http_requests) BY (job) - COUNT(http_requests) BY (job) 18 {job="api-server"} 996 19 {job="app-server"} 2596 20 21 eval instant at 50m 2 - SUM(http_requests) BY (job) 22 {job="api-server"} -998 23 {job="app-server"} -2598 24 25 eval instant at 50m -http_requests{job="api-server",instance="0",group="production"} 26 {job="api-server",instance="0",group="production"} -100 27 28 eval instant at 50m +http_requests{job="api-server",instance="0",group="production"} 29 http_requests{job="api-server",instance="0",group="production"} 100 30 31 eval instant at 50m - - - SUM(http_requests) BY (job) 32 {job="api-server"} -1000 33 {job="app-server"} -2600 34 35 eval instant at 50m - - - 1 36 -1 37 38 eval instant at 50m -2^---1*3 39 -1.5 40 41 eval instant at 50m 2/-2^---1*3+2 42 -10 43 44 eval instant at 50m -10^3 * - SUM(http_requests) BY (job) ^ -1 45 {job="api-server"} 1 46 {job="app-server"} 0.38461538461538464 47 48 eval instant at 50m 1000 / SUM(http_requests) BY (job) 49 {job="api-server"} 1 50 {job="app-server"} 0.38461538461538464 51 52 eval instant at 50m SUM(http_requests) BY (job) - 2 53 {job="api-server"} 998 54 {job="app-server"} 2598 55 56 eval instant at 50m SUM(http_requests) BY (job) % 3 57 {job="api-server"} 1 58 {job="app-server"} 2 59 60 eval instant at 50m SUM(http_requests) BY (job) % 0.3 61 {job="api-server"} 0.1 62 {job="app-server"} 0.2 63 64 eval instant at 50m SUM(http_requests) BY (job) ^ 2 65 {job="api-server"} 1000000 66 {job="app-server"} 6760000 67 68 eval instant at 50m SUM(http_requests) BY (job) % 3 ^ 2 69 {job="api-server"} 1 70 {job="app-server"} 8 71 72 eval instant at 50m SUM(http_requests) BY (job) % 2 ^ (3 ^ 2) 73 {job="api-server"} 488 74 {job="app-server"} 40 75 76 eval instant at 50m SUM(http_requests) BY (job) % 2 ^ 3 ^ 2 77 {job="api-server"} 488 78 {job="app-server"} 40 79 80 eval instant at 50m SUM(http_requests) BY (job) % 2 ^ 3 ^ 2 ^ 2 81 {job="api-server"} 1000 82 {job="app-server"} 2600 83 84 eval instant at 50m COUNT(http_requests) BY (job) ^ COUNT(http_requests) BY (job) 85 {job="api-server"} 256 86 {job="app-server"} 256 87 88 eval instant at 50m SUM(http_requests) BY (job) / 0 89 {job="api-server"} +Inf 90 {job="app-server"} +Inf 91 92 eval instant at 50m http_requests{group="canary", instance="0", job="api-server"} / 0 93 {group="canary", instance="0", job="api-server"} +Inf 94 95 eval instant at 50m -1 * http_requests{group="canary", instance="0", job="api-server"} / 0 96 {group="canary", instance="0", job="api-server"} -Inf 97 98 eval instant at 50m 0 * http_requests{group="canary", instance="0", job="api-server"} / 0 99 {group="canary", instance="0", job="api-server"} NaN 100 101 eval instant at 50m 0 * http_requests{group="canary", instance="0", job="api-server"} % 0 102 {group="canary", instance="0", job="api-server"} NaN 103 104 eval instant at 50m SUM(http_requests) BY (job) + SUM(http_requests) BY (job) 105 {job="api-server"} 2000 106 {job="app-server"} 5200 107 108 eval instant at 50m (SUM((http_requests)) BY (job)) + SUM(http_requests) BY (job) 109 {job="api-server"} 2000 110 {job="app-server"} 5200 111 112 eval instant at 50m http_requests{job="api-server", group="canary"} 113 http_requests{group="canary", instance="0", job="api-server"} 300 114 http_requests{group="canary", instance="1", job="api-server"} 400 115 116 eval instant at 50m http_requests{job="api-server", group="canary"} + rate(http_requests{job="api-server"}[5m]) * 5 * 60 117 {group="canary", instance="0", job="api-server"} 330 118 {group="canary", instance="1", job="api-server"} 440 119 120 eval instant at 50m rate(http_requests[25m]) * 25 * 60 121 {group="canary", instance="0", job="api-server"} 150 122 {group="canary", instance="0", job="app-server"} 350 123 {group="canary", instance="1", job="api-server"} 200 124 {group="canary", instance="1", job="app-server"} 400 125 {group="production", instance="0", job="api-server"} 50 126 {group="production", instance="0", job="app-server"} 249.99999999999997 127 {group="production", instance="1", job="api-server"} 100 128 {group="production", instance="1", job="app-server"} 300 129 130 eval instant at 50m (rate((http_requests[25m])) * 25) * 60 131 {group="canary", instance="0", job="api-server"} 150 132 {group="canary", instance="0", job="app-server"} 350 133 {group="canary", instance="1", job="api-server"} 200 134 {group="canary", instance="1", job="app-server"} 400 135 {group="production", instance="0", job="api-server"} 50 136 {group="production", instance="0", job="app-server"} 249.99999999999997 137 {group="production", instance="1", job="api-server"} 100 138 {group="production", instance="1", job="app-server"} 300 139 140 141 eval instant at 50m http_requests{group="canary"} and http_requests{instance="0"} 142 http_requests{group="canary", instance="0", job="api-server"} 300 143 http_requests{group="canary", instance="0", job="app-server"} 700 144 145 eval instant at 50m (http_requests{group="canary"} + 1) and http_requests{instance="0"} 146 {group="canary", instance="0", job="api-server"} 301 147 {group="canary", instance="0", job="app-server"} 701 148 149 eval instant at 50m (http_requests{group="canary"} + 1) and on(instance, job) http_requests{instance="0", group="production"} 150 {group="canary", instance="0", job="api-server"} 301 151 {group="canary", instance="0", job="app-server"} 701 152 153 eval instant at 50m (http_requests{group="canary"} + 1) and on(instance) http_requests{instance="0", group="production"} 154 {group="canary", instance="0", job="api-server"} 301 155 {group="canary", instance="0", job="app-server"} 701 156 157 eval instant at 50m (http_requests{group="canary"} + 1) and ignoring(group) http_requests{instance="0", group="production"} 158 {group="canary", instance="0", job="api-server"} 301 159 {group="canary", instance="0", job="app-server"} 701 160 161 eval instant at 50m (http_requests{group="canary"} + 1) and ignoring(group, job) http_requests{instance="0", group="production"} 162 {group="canary", instance="0", job="api-server"} 301 163 {group="canary", instance="0", job="app-server"} 701 164 165 eval instant at 50m http_requests{group="canary"} or http_requests{group="production"} 166 http_requests{group="canary", instance="0", job="api-server"} 300 167 http_requests{group="canary", instance="0", job="app-server"} 700 168 http_requests{group="canary", instance="1", job="api-server"} 400 169 http_requests{group="canary", instance="1", job="app-server"} 800 170 http_requests{group="production", instance="0", job="api-server"} 100 171 http_requests{group="production", instance="0", job="app-server"} 500 172 http_requests{group="production", instance="1", job="api-server"} 200 173 http_requests{group="production", instance="1", job="app-server"} 600 174 175 # On overlap the rhs samples must be dropped. 176 eval instant at 50m (http_requests{group="canary"} + 1) or http_requests{instance="1"} 177 {group="canary", instance="0", job="api-server"} 301 178 {group="canary", instance="0", job="app-server"} 701 179 {group="canary", instance="1", job="api-server"} 401 180 {group="canary", instance="1", job="app-server"} 801 181 http_requests{group="production", instance="1", job="api-server"} 200 182 http_requests{group="production", instance="1", job="app-server"} 600 183 184 185 # Matching only on instance excludes everything that has instance=0/1 but includes 186 # entries without the instance label. 187 eval instant at 50m (http_requests{group="canary"} + 1) or on(instance) (http_requests or cpu_count or vector_matching_a) 188 {group="canary", instance="0", job="api-server"} 301 189 {group="canary", instance="0", job="app-server"} 701 190 {group="canary", instance="1", job="api-server"} 401 191 {group="canary", instance="1", job="app-server"} 801 192 vector_matching_a{l="x"} 10 193 vector_matching_a{l="y"} 20 194 195 eval instant at 50m (http_requests{group="canary"} + 1) or ignoring(l, group, job) (http_requests or cpu_count or vector_matching_a) 196 {group="canary", instance="0", job="api-server"} 301 197 {group="canary", instance="0", job="app-server"} 701 198 {group="canary", instance="1", job="api-server"} 401 199 {group="canary", instance="1", job="app-server"} 801 200 vector_matching_a{l="x"} 10 201 vector_matching_a{l="y"} 20 202 203 eval instant at 50m http_requests{group="canary"} unless http_requests{instance="0"} 204 http_requests{group="canary", instance="1", job="api-server"} 400 205 http_requests{group="canary", instance="1", job="app-server"} 800 206 207 eval instant at 50m http_requests{group="canary"} unless on(job) http_requests{instance="0"} 208 209 eval instant at 50m http_requests{group="canary"} unless on(job, instance) http_requests{instance="0"} 210 http_requests{group="canary", instance="1", job="api-server"} 400 211 http_requests{group="canary", instance="1", job="app-server"} 800 212 213 eval instant at 50m http_requests{group="canary"} / on(instance,job) http_requests{group="production"} 214 {instance="0", job="api-server"} 3 215 {instance="0", job="app-server"} 1.4 216 {instance="1", job="api-server"} 2 217 {instance="1", job="app-server"} 1.3333333333333333 218 219 eval instant at 50m http_requests{group="canary"} unless ignoring(group, instance) http_requests{instance="0"} 220 221 eval instant at 50m http_requests{group="canary"} unless ignoring(group) http_requests{instance="0"} 222 http_requests{group="canary", instance="1", job="api-server"} 400 223 http_requests{group="canary", instance="1", job="app-server"} 800 224 225 eval instant at 50m http_requests{group="canary"} / ignoring(group) http_requests{group="production"} 226 {instance="0", job="api-server"} 3 227 {instance="0", job="app-server"} 1.4 228 {instance="1", job="api-server"} 2 229 {instance="1", job="app-server"} 1.3333333333333333 230 231 # https://github.com/prometheus/prometheus/issues/1489 232 eval instant at 50m http_requests AND ON (dummy) vector(1) 233 http_requests{group="canary", instance="0", job="api-server"} 300 234 http_requests{group="canary", instance="0", job="app-server"} 700 235 http_requests{group="canary", instance="1", job="api-server"} 400 236 http_requests{group="canary", instance="1", job="app-server"} 800 237 http_requests{group="production", instance="0", job="api-server"} 100 238 http_requests{group="production", instance="0", job="app-server"} 500 239 http_requests{group="production", instance="1", job="api-server"} 200 240 http_requests{group="production", instance="1", job="app-server"} 600 241 242 eval instant at 50m http_requests AND IGNORING (group, instance, job) vector(1) 243 http_requests{group="canary", instance="0", job="api-server"} 300 244 http_requests{group="canary", instance="0", job="app-server"} 700 245 http_requests{group="canary", instance="1", job="api-server"} 400 246 http_requests{group="canary", instance="1", job="app-server"} 800 247 http_requests{group="production", instance="0", job="api-server"} 100 248 http_requests{group="production", instance="0", job="app-server"} 500 249 http_requests{group="production", instance="1", job="api-server"} 200 250 http_requests{group="production", instance="1", job="app-server"} 600 251 252 253 # Comparisons. 254 eval instant at 50m SUM(http_requests) BY (job) > 1000 255 {job="app-server"} 2600 256 257 eval instant at 50m 1000 < SUM(http_requests) BY (job) 258 {job="app-server"} 2600 259 260 eval instant at 50m SUM(http_requests) BY (job) <= 1000 261 {job="api-server"} 1000 262 263 eval instant at 50m SUM(http_requests) BY (job) != 1000 264 {job="app-server"} 2600 265 266 eval instant at 50m SUM(http_requests) BY (job) == 1000 267 {job="api-server"} 1000 268 269 eval instant at 50m SUM(http_requests) BY (job) == bool 1000 270 {job="api-server"} 1 271 {job="app-server"} 0 272 273 eval instant at 50m SUM(http_requests) BY (job) == bool SUM(http_requests) BY (job) 274 {job="api-server"} 1 275 {job="app-server"} 1 276 277 eval instant at 50m SUM(http_requests) BY (job) != bool SUM(http_requests) BY (job) 278 {job="api-server"} 0 279 {job="app-server"} 0 280 281 eval instant at 50m 0 == bool 1 282 0 283 284 eval instant at 50m 1 == bool 1 285 1 286 287 eval instant at 50m http_requests{job="api-server", instance="0", group="production"} == bool 100 288 {job="api-server", instance="0", group="production"} 1 289 290 # group_left/group_right. 291 292 clear 293 294 load 5m 295 node_var{instance="abc",job="node"} 2 296 node_role{instance="abc",job="node",role="prometheus"} 1 297 298 load 5m 299 node_cpu{instance="abc",job="node",mode="idle"} 3 300 node_cpu{instance="abc",job="node",mode="user"} 1 301 node_cpu{instance="def",job="node",mode="idle"} 8 302 node_cpu{instance="def",job="node",mode="user"} 2 303 304 load 5m 305 random{foo="bar"} 1 306 307 load 5m 308 threshold{instance="abc",job="node",target="a@b.com"} 0 309 310 # Copy machine role to node variable. 311 eval instant at 5m node_role * on (instance) group_right (role) node_var 312 {instance="abc",job="node",role="prometheus"} 2 313 314 eval instant at 5m node_var * on (instance) group_left (role) node_role 315 {instance="abc",job="node",role="prometheus"} 2 316 317 eval instant at 5m node_var * ignoring (role) group_left (role) node_role 318 {instance="abc",job="node",role="prometheus"} 2 319 320 eval instant at 5m node_role * ignoring (role) group_right (role) node_var 321 {instance="abc",job="node",role="prometheus"} 2 322 323 # Copy machine role to node variable with instrumentation labels. 324 eval instant at 5m node_cpu * ignoring (role, mode) group_left (role) node_role 325 {instance="abc",job="node",mode="idle",role="prometheus"} 3 326 {instance="abc",job="node",mode="user",role="prometheus"} 1 327 328 eval instant at 5m node_cpu * on (instance) group_left (role) node_role 329 {instance="abc",job="node",mode="idle",role="prometheus"} 3 330 {instance="abc",job="node",mode="user",role="prometheus"} 1 331 332 333 # Ratio of total. 334 eval instant at 5m node_cpu / on (instance) group_left sum by (instance,job)(node_cpu) 335 {instance="abc",job="node",mode="idle"} .75 336 {instance="abc",job="node",mode="user"} .25 337 {instance="def",job="node",mode="idle"} .80 338 {instance="def",job="node",mode="user"} .20 339 340 eval instant at 5m sum by (mode, job)(node_cpu) / on (job) group_left sum by (job)(node_cpu) 341 {job="node",mode="idle"} 0.7857142857142857 342 {job="node",mode="user"} 0.21428571428571427 343 344 eval instant at 5m sum(sum by (mode, job)(node_cpu) / on (job) group_left sum by (job)(node_cpu)) 345 {} 1.0 346 347 348 eval instant at 5m node_cpu / ignoring (mode) group_left sum without (mode)(node_cpu) 349 {instance="abc",job="node",mode="idle"} .75 350 {instance="abc",job="node",mode="user"} .25 351 {instance="def",job="node",mode="idle"} .80 352 {instance="def",job="node",mode="user"} .20 353 354 eval instant at 5m node_cpu / ignoring (mode) group_left(dummy) sum without (mode)(node_cpu) 355 {instance="abc",job="node",mode="idle"} .75 356 {instance="abc",job="node",mode="user"} .25 357 {instance="def",job="node",mode="idle"} .80 358 {instance="def",job="node",mode="user"} .20 359 360 eval instant at 5m sum without (instance)(node_cpu) / ignoring (mode) group_left sum without (instance, mode)(node_cpu) 361 {job="node",mode="idle"} 0.7857142857142857 362 {job="node",mode="user"} 0.21428571428571427 363 364 eval instant at 5m sum(sum without (instance)(node_cpu) / ignoring (mode) group_left sum without (instance, mode)(node_cpu)) 365 {} 1.0 366 367 368 # Copy over label from metric with no matching labels, without having to list cross-job target labels ('job' here). 369 eval instant at 5m node_cpu + on(dummy) group_left(foo) random*0 370 {instance="abc",job="node",mode="idle",foo="bar"} 3 371 {instance="abc",job="node",mode="user",foo="bar"} 1 372 {instance="def",job="node",mode="idle",foo="bar"} 8 373 {instance="def",job="node",mode="user",foo="bar"} 2 374 375 376 # Use threshold from metric, and copy over target. 377 eval instant at 5m node_cpu > on(job, instance) group_left(target) threshold 378 node_cpu{instance="abc",job="node",mode="idle",target="a@b.com"} 3 379 node_cpu{instance="abc",job="node",mode="user",target="a@b.com"} 1 380 381 # Use threshold from metric, and a default (1) if it's not present. 382 eval instant at 5m node_cpu > on(job, instance) group_left(target) (threshold or on (job, instance) (sum by (job, instance)(node_cpu) * 0 + 1)) 383 node_cpu{instance="abc",job="node",mode="idle",target="a@b.com"} 3 384 node_cpu{instance="abc",job="node",mode="user",target="a@b.com"} 1 385 node_cpu{instance="def",job="node",mode="idle"} 8 386 node_cpu{instance="def",job="node",mode="user"} 2 387 388 389 # Check that binops drop the metric name. 390 eval instant at 5m node_cpu + 2 391 {instance="abc",job="node",mode="idle"} 5 392 {instance="abc",job="node",mode="user"} 3 393 {instance="def",job="node",mode="idle"} 10 394 {instance="def",job="node",mode="user"} 4 395 396 eval instant at 5m node_cpu - 2 397 {instance="abc",job="node",mode="idle"} 1 398 {instance="abc",job="node",mode="user"} -1 399 {instance="def",job="node",mode="idle"} 6 400 {instance="def",job="node",mode="user"} 0 401 402 eval instant at 5m node_cpu / 2 403 {instance="abc",job="node",mode="idle"} 1.5 404 {instance="abc",job="node",mode="user"} 0.5 405 {instance="def",job="node",mode="idle"} 4 406 {instance="def",job="node",mode="user"} 1 407 408 eval instant at 5m node_cpu * 2 409 {instance="abc",job="node",mode="idle"} 6 410 {instance="abc",job="node",mode="user"} 2 411 {instance="def",job="node",mode="idle"} 16 412 {instance="def",job="node",mode="user"} 4 413 414 eval instant at 5m node_cpu ^ 2 415 {instance="abc",job="node",mode="idle"} 9 416 {instance="abc",job="node",mode="user"} 1 417 {instance="def",job="node",mode="idle"} 64 418 {instance="def",job="node",mode="user"} 4 419 420 eval instant at 5m node_cpu % 2 421 {instance="abc",job="node",mode="idle"} 1 422 {instance="abc",job="node",mode="user"} 1 423 {instance="def",job="node",mode="idle"} 0 424 {instance="def",job="node",mode="user"} 0 425 426 427 clear 428 429 load 5m 430 random{foo="bar"} 2 431 metricA{baz="meh"} 3 432 metricB{baz="meh"} 4 433 434 # On with no labels, for metrics with no common labels. 435 eval instant at 5m random + on() metricA 436 {} 5 437 438 # Ignoring with no labels is the same as no ignoring. 439 eval instant at 5m metricA + ignoring() metricB 440 {baz="meh"} 7 441 442 eval instant at 5m metricA + metricB 443 {baz="meh"} 7 444 445 clear 446 447 # Test duplicate labelset in promql output. 448 load 5m 449 testmetric1{src="a",dst="b"} 0 450 testmetric2{src="a",dst="b"} 1 451 452 eval_fail instant at 0m -{__name__=~'testmetric1|testmetric2'} 453 454 clear 455 456 load 5m 457 test_total{instance="localhost"} 50 458 test_smaller{instance="localhost"} 10 459 460 eval instant at 5m test_total > bool test_smaller 461 {instance="localhost"} 1 462 463 eval instant at 5m test_total > test_smaller 464 test_total{instance="localhost"} 50 465 466 eval instant at 5m test_total < bool test_smaller 467 {instance="localhost"} 0 468 469 eval instant at 5m test_total < test_smaller