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 {
|
if len(vals[0].(Vector)) > 0 {
|
||||||
return enh.out
|
return enh.out
|
||||||
}
|
}
|
||||||
m := []labels.Label{}
|
m := labels.Labels{}
|
||||||
|
empty := []string{}
|
||||||
|
|
||||||
if vs, ok := args[0].(*VectorSelector); ok {
|
if vs, ok := args[0].(*VectorSelector); ok {
|
||||||
for _, ma := range vs.LabelMatchers {
|
for _, ma := range vs.LabelMatchers {
|
||||||
if ma.Type == labels.MatchEqual && ma.Name != labels.MetricName {
|
if ma.Name == labels.MetricName {
|
||||||
m = append(m, labels.Label{Name: ma.Name, Value: ma.Value})
|
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,
|
return append(enh.out,
|
||||||
Sample{
|
Sample{
|
||||||
Metric: labels.New(m...),
|
Metric: labels.New(m...),
|
||||||
|
|
|
@ -264,6 +264,15 @@ eval instant at 50m absent(nonexistent)
|
||||||
eval instant at 50m absent(nonexistent{job="testjob", instance="testinstance", method=~".x"})
|
eval instant at 50m absent(nonexistent{job="testjob", instance="testinstance", method=~".x"})
|
||||||
{instance="testinstance", job="testjob"} 1
|
{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(http_requests)
|
||||||
|
|
||||||
eval instant at 50m absent(sum(http_requests))
|
eval instant at 50m absent(sum(http_requests))
|
||||||
|
|
Loading…
Reference in New Issue