|
| 1 | +# Run this with: |
| 2 | +# |
| 3 | +# git clone https://github.com/prometheus/prometheus |
| 4 | +# cd prometheus |
| 5 | +# |
| 6 | +# then copy it into ./promql/promqltest/testdata/blog_example_1.test |
| 7 | +# |
| 8 | +# and run: |
| 9 | +# |
| 10 | +# go test -v -run 'TestEvaluations/testdata/blog_example_1.test' --count=1 ./promql |
| 11 | + |
| 12 | + |
| 13 | +load 1m |
| 14 | + requests_total{instance="foo", endpoint="/api/v1/status"} 1000x5 |
| 15 | + requests_total{instance="foo", endpoint="/api/v1/query"} 2000x5 |
| 16 | + requests_total{instance="bar", endpoint="/api/v1/status"} 2500x5 |
| 17 | + requests_total{instance="ownermissing", endpoint="/api/v1/status"} 3000x5 |
| 18 | + component_price_multiplier{instance="foo", owner="internaluser1"} 1x5 |
| 19 | + component_price_multiplier{instance="bar", owner="ushealthcare"} 20x5 |
| 20 | + component_price_multiplier{instance="baz", owner="idleandunused"} 0x5 |
| 21 | + |
| 22 | +# 1:1 label matching; fails because requests_total{instance="foo"} has 2 matching series on LHS |
| 23 | +eval instant at 1m requests_total{} * on (instance) (component_price_multiplier) |
| 24 | + expect fail msg:multiple matches for labels: many-to-one matching must be explicit (group_left/group_right) |
| 25 | + |
| 26 | +# 1:m matching; fails because requests_total{instance="foo"} has 2 matching series on LHS |
| 27 | +# |
| 28 | +# Fails with |
| 29 | +# |
| 30 | +# found duplicate series for the match group {instance="foo"} on the left hand-side of the operation: [{__name__="requests_total", endpoint="/api/v1/query", instance="foo"}, {__name__="requests_total", endpoint="/api/v1/status", instance="foo"}];many-to-many matching not allowed: matching labels must be unique on one side |
| 31 | +# |
| 32 | +eval instant at 1m requests_total{} * on (instance) group_right(owner) (component_price_multiplier) |
| 33 | + expect fail regex:found duplicate series for the match group \{instance="foo"\} on the left hand-side of the operation: \[.*\];many-to-many matching not allowed: matching labels must be unique on one side |
| 34 | + |
| 35 | +# n:1 matching |
| 36 | +# |
| 37 | +# Works; acts like an inner join, dropping the unmatched requests_total{instance="ownermissing"} series |
| 38 | +# |
| 39 | +eval instant at 1m requests_total{} * on (instance) group_left(owner) (component_price_multiplier) |
| 40 | + {endpoint="/api/v1/status", instance="foo", owner="internaluser1"} 1000 |
| 41 | + {endpoint="/api/v1/query", instance="foo", owner="internaluser1"} 2000 |
| 42 | + {endpoint="/api/v1/status", instance="bar", owner="ushealthcare"} 50000 |
| 43 | + |
| 44 | +# n:1 matching with unmatched values kept (emulated left join) |
| 45 | +# |
| 46 | +# Works. The * 1 is just there to drop the __name__ label. |
| 47 | +# |
| 48 | +eval instant at 1m requests_total{} * on (instance) group_left(owner) (component_price_multiplier) or on (instance) (requests_total{} * 1) |
| 49 | + {endpoint="/api/v1/status", instance="foo", owner="internaluser1"} 1000 |
| 50 | + {endpoint="/api/v1/query", instance="foo", owner="internaluser1"} 2000 |
| 51 | + {endpoint="/api/v1/status", instance="bar", owner="ushealthcare"} 50000 |
| 52 | + {endpoint="/api/v1/status", instance="ownermissing"} 3000 |
0 commit comments