PromQL: Fix printing +min()

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
This commit is contained in:
Julien Pivotto 2025-07-01 11:57:31 +02:00
parent 3af0bdee68
commit 984c8de0da
2 changed files with 13 additions and 1 deletions

View File

@ -157,7 +157,15 @@ func (node *DurationExpr) String() string {
expr = fmt.Sprintf("max(%s, %s)", node.LHS, node.RHS)
case node.LHS == nil:
// This is a unary duration expression.
expr = fmt.Sprintf("%s%s", node.Op, node.RHS)
switch node.Op {
case SUB:
expr = fmt.Sprintf("%s%s", node.Op, node.RHS)
case ADD:
expr = node.RHS.String()
default:
// This should never happen.
panic(fmt.Sprintf("unexpected unary duration expression: %s", node.Op))
}
default:
expr = fmt.Sprintf("%s %s %s", node.LHS, node.Op, node.RHS)
}

View File

@ -199,6 +199,10 @@ func TestExprString(t *testing.T) {
in: "foo offset +(5*2)",
out: "foo offset (5 * 2)",
},
{
in: "foo offset +min(10s, 20s)",
out: "foo offset min(10s, 20s)",
},
{
in: "foo offset -min(10s, 20s)",
},