mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Drop metric name in bool comparison between two instant vectors (#7819)
* Drop metric name in bool comparison between two instant vectors Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
88d563eb2e
commit
6f9e7ff750
|
@ -31,7 +31,7 @@ scalar that is the result of the operator applied to both scalar operands.
|
|||
**Between an instant vector and a scalar**, the operator is applied to the
|
||||
value of every data sample in the vector. E.g. if a time series instant vector
|
||||
is multiplied by 2, the result is another vector in which every sample value of
|
||||
the original vector is multiplied by 2.
|
||||
the original vector is multiplied by 2. The metric name is dropped.
|
||||
|
||||
**Between two instant vectors**, a binary arithmetic operator is applied to
|
||||
each entry in the left-hand side vector and its [matching element](#vector-matching)
|
||||
|
@ -64,7 +64,8 @@ operators result in another scalar that is either `0` (`false`) or `1`
|
|||
value of every data sample in the vector, and vector elements between which the
|
||||
comparison result is `false` get dropped from the result vector. If the `bool`
|
||||
modifier is provided, vector elements that would be dropped instead have the value
|
||||
`0` and vector elements that would be kept have the value `1`.
|
||||
`0` and vector elements that would be kept have the value `1`. The metric name
|
||||
is dropped if the `bool` modifier is provided.
|
||||
|
||||
**Between two instant vectors**, these operators behave as a filter by default,
|
||||
applied to matching entries. Vector elements for which the expression is not
|
||||
|
@ -74,6 +75,7 @@ with the grouping labels becoming the output label set.
|
|||
If the `bool` modifier is provided, vector elements that would have been
|
||||
dropped instead have the value `0` and vector elements that would be kept have
|
||||
the value `1`, with the grouping labels again becoming the output label set.
|
||||
The metric name is dropped if the `bool` modifier is provided.
|
||||
|
||||
### Logical/set binary operators
|
||||
|
||||
|
|
|
@ -1656,6 +1656,9 @@ func (ev *evaluator) VectorBinop(op parser.ItemType, lhs, rhs Vector, matching *
|
|||
continue
|
||||
}
|
||||
metric := resultMetric(ls.Metric, rs.Metric, op, matching, enh)
|
||||
if returnBool {
|
||||
metric = enh.dropMetricName(metric)
|
||||
}
|
||||
insertedSigs, exists := matchedSigs[sig]
|
||||
if matching.Card == parser.CardOneToOne {
|
||||
if exists {
|
||||
|
|
17
promql/testdata/operators.test
vendored
17
promql/testdata/operators.test
vendored
|
@ -438,3 +438,20 @@ load 5m
|
|||
testmetric2{src="a",dst="b"} 1
|
||||
|
||||
eval_fail instant at 0m -{__name__=~'testmetric1|testmetric2'}
|
||||
|
||||
clear
|
||||
|
||||
load 5m
|
||||
test_total{instance="localhost"} 50
|
||||
test_smaller{instance="localhost"} 10
|
||||
|
||||
eval instant at 5m test_total > bool test_smaller
|
||||
{instance="localhost"} 1
|
||||
|
||||
eval instant at 5m test_total > test_smaller
|
||||
test_total{instance="localhost"} 50
|
||||
|
||||
eval instant at 5m test_total < bool test_smaller
|
||||
{instance="localhost"} 0
|
||||
|
||||
eval instant at 5m test_total < test_smaller
|
||||
|
|
Loading…
Reference in a new issue