Change arithmetic binops back to old output behavior

Signed-off-by: Julius Volz <julius.volz@gmail.com>
pull/5494/head
Julius Volz 6 years ago
parent ebdf3828a3
commit e7f54b95d6
  1. 20
      promql/engine.go
  2. 18
      promql/testdata/operators.test

@ -1545,8 +1545,8 @@ func resultMetric(lhs, rhs labels.Labels, op ItemType, matching *VectorMatching,
}
var lb *labels.Builder
if matching.Card == CardOneToMany {
// Choose the rhs metric because lhs and rhs have been swapped.
if matching.Card == CardOneToMany && op.isComparisonOperator() {
// Choose the rhs metric as the one to output because lhs and rhs have been swapped.
lb = labels.NewBuilder(rhs)
} else {
lb = labels.NewBuilder(lhs)
@ -1556,6 +1556,22 @@ func resultMetric(lhs, rhs labels.Labels, op ItemType, matching *VectorMatching,
lb.Del(labels.MetricName)
}
if matching.Card == CardOneToOne && !op.isComparisonOperator() {
if matching.On {
Outer:
for _, l := range lhs {
for _, n := range matching.MatchingLabels {
if l.Name == n {
continue Outer
}
}
lb.Del(l.Name)
}
} else {
lb.Del(matching.MatchingLabels...)
}
}
for _, ln := range matching.Include {
// Included labels from the `group_x` modifier are taken from the "one"-side.
if v := rhs.Get(ln); v != "" {

@ -176,10 +176,10 @@ eval instant at 50m http_requests{group="canary"} unless on(job, instance) http_
http_requests{group="canary", instance="1", job="app-server"} 800
eval instant at 50m http_requests{group="canary"} / on(instance,job) http_requests{group="production"}
{group="canary", instance="0", job="api-server"} 3
{group="canary", instance="0", job="app-server"} 1.4
{group="canary", instance="1", job="api-server"} 2
{group="canary", instance="1", job="app-server"} 1.3333333333333333
{instance="0", job="api-server"} 3
{instance="0", job="app-server"} 1.4
{instance="1", job="api-server"} 2
{instance="1", job="app-server"} 1.3333333333333333
eval instant at 50m http_requests{group="canary"} unless ignoring(group, instance) http_requests{instance="0"}
@ -188,10 +188,10 @@ eval instant at 50m http_requests{group="canary"} unless ignoring(group) http_re
http_requests{group="canary", instance="1", job="app-server"} 800
eval instant at 50m http_requests{group="canary"} / ignoring(group) http_requests{group="production"}
{group="canary", instance="0", job="api-server"} 3
{group="canary", instance="0", job="app-server"} 1.4
{group="canary", instance="1", job="api-server"} 2
{group="canary", instance="1", job="app-server"} 1.3333333333333333
{instance="0", job="api-server"} 3
{instance="0", job="app-server"} 1.4
{instance="1", job="api-server"} 2
{instance="1", job="app-server"} 1.3333333333333333
# https://github.com/prometheus/prometheus/issues/1489
eval instant at 50m http_requests AND ON (dummy) vector(1)
@ -398,7 +398,7 @@ load 5m
# On with no labels, for metrics with no common labels.
eval instant at 5m random + on() metricA
{foo="bar"} 5
{} 5
# Ignoring with no labels is the same as no ignoring.
eval instant at 5m metricA + ignoring() metricB

Loading…
Cancel
Save