mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-26 13:11:11 -08:00
Fix absent output where two label matchers are identical (#6493)
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
a48acbcb23
commit
4b3bab890d
|
@ -480,15 +480,26 @@ func funcAbsent(vals []Value, args Expressions, enh *EvalNodeHelper) Vector {
|
|||
if len(vals[0].(Vector)) > 0 {
|
||||
return enh.out
|
||||
}
|
||||
m := []labels.Label{}
|
||||
m := labels.Labels{}
|
||||
empty := []string{}
|
||||
|
||||
if vs, ok := args[0].(*VectorSelector); ok {
|
||||
for _, ma := range vs.LabelMatchers {
|
||||
if ma.Type == labels.MatchEqual && ma.Name != labels.MetricName {
|
||||
m = append(m, labels.Label{Name: ma.Name, Value: ma.Value})
|
||||
if ma.Name == labels.MetricName {
|
||||
continue
|
||||
}
|
||||
if ma.Type == labels.MatchEqual && !m.Has(ma.Name) {
|
||||
m = labels.NewBuilder(m).Set(ma.Name, ma.Value).Labels()
|
||||
} else {
|
||||
empty = append(empty, ma.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range empty {
|
||||
m = labels.NewBuilder(m).Set(v, "").Labels()
|
||||
}
|
||||
|
||||
return append(enh.out,
|
||||
Sample{
|
||||
Metric: labels.New(m...),
|
||||
|
|
11
promql/testdata/legacy.test
vendored
11
promql/testdata/legacy.test
vendored
|
@ -264,6 +264,15 @@ eval instant at 50m absent(nonexistent)
|
|||
eval instant at 50m absent(nonexistent{job="testjob", instance="testinstance", method=~".x"})
|
||||
{instance="testinstance", job="testjob"} 1
|
||||
|
||||
eval instant at 50m absent(nonexistent{job="testjob",job="testjob2",foo="bar"})
|
||||
{foo="bar"} 1
|
||||
|
||||
eval instant at 50m absent(nonexistent{job="testjob",job="testjob2",job="three",foo="bar"})
|
||||
{foo="bar"} 1
|
||||
|
||||
eval instant at 50m absent(nonexistent{job="testjob",job=~"testjob2",foo="bar"})
|
||||
{foo="bar"} 1
|
||||
|
||||
eval instant at 50m absent(http_requests)
|
||||
|
||||
eval instant at 50m absent(sum(http_requests))
|
||||
|
@ -365,4 +374,4 @@ load 5m
|
|||
testmetric1{src="a",dst="b"} 0
|
||||
testmetric2{src="a",dst="b"} 1
|
||||
|
||||
eval_fail instant at 0m ceil({__name__=~'testmetric1|testmetric2'})
|
||||
eval_fail instant at 0m ceil({__name__=~'testmetric1|testmetric2'})
|
||||
|
|
Loading…
Reference in a new issue