promql: Fix printing of empty without() (#3719)
* promql: Fix printing of empty without() Fixes https://github.com/prometheus/prometheus/issues/3704 * Test cleanup fixup
This commit is contained in:
parent
85f23d82a0
commit
1e943fc10a
|
@ -139,15 +139,15 @@ func (node *AggregateExpr) String() string {
|
||||||
aggrString += fmt.Sprintf("%s, ", node.Param)
|
aggrString += fmt.Sprintf("%s, ", node.Param)
|
||||||
}
|
}
|
||||||
aggrString += fmt.Sprintf("%s)", node.Expr)
|
aggrString += fmt.Sprintf("%s)", node.Expr)
|
||||||
if len(node.Grouping) > 0 {
|
|
||||||
var format string
|
|
||||||
if node.Without {
|
if node.Without {
|
||||||
format = "%s WITHOUT (%s)"
|
aggrString = fmt.Sprintf("%s WITHOUT (%s)", aggrString, strings.Join(node.Grouping, ", "))
|
||||||
} else {
|
} else {
|
||||||
format = "%s BY (%s)"
|
if len(node.Grouping) > 0 {
|
||||||
|
aggrString = fmt.Sprintf("%s BY (%s)", aggrString, strings.Join(node.Grouping, ", "))
|
||||||
}
|
}
|
||||||
aggrString = fmt.Sprintf(format, aggrString, strings.Join(node.Grouping, ", "))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return aggrString
|
return aggrString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,9 @@ func TestExprString(t *testing.T) {
|
||||||
{
|
{
|
||||||
in: `sum(task:errors:rate10s{job="s"}) BY (code)`,
|
in: `sum(task:errors:rate10s{job="s"}) BY (code)`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
in: `sum(task:errors:rate10s{job="s"}) WITHOUT ()`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
in: `sum(task:errors:rate10s{job="s"}) WITHOUT (instance)`,
|
in: `sum(task:errors:rate10s{job="s"}) WITHOUT (instance)`,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue