From 2ef8706c275bf06dcf482605abcd4def9e2d3af5 Mon Sep 17 00:00:00 2001 From: Giuliano Panzironi <45801466+giulianopz@users.noreply.github.com> Date: Mon, 3 Mar 2025 10:03:45 +0100 Subject: [PATCH] fix: format float to avoid overflow (#16083) Signed-off-by: giulianopz --- promql/parser/printer.go | 2 +- promql/parser/printer_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/promql/parser/printer.go b/promql/parser/printer.go index afe755e7dd..6f234a0290 100644 --- a/promql/parser/printer.go +++ b/promql/parser/printer.go @@ -232,7 +232,7 @@ func (node *SubqueryExpr) getSubqueryTimeSuffix() string { } func (node *NumberLiteral) String() string { - return fmt.Sprint(node.Val) + return strconv.FormatFloat(node.Val, 'f', -1, 64) } func (node *ParenExpr) String() string { diff --git a/promql/parser/printer_test.go b/promql/parser/printer_test.go index 0a557ad597..ce06d6ec4b 100644 --- a/promql/parser/printer_test.go +++ b/promql/parser/printer_test.go @@ -164,6 +164,10 @@ func TestExprString(t *testing.T) { in: "{``=\"0\"}", out: `{""="0"}`, }, + { + in: "1048576", + out: "1048576", + }, } model.NameValidationScheme = model.UTF8Validation