From 7214a8eeba70f26898c71fb5f20bc4b4abb9bc05 Mon Sep 17 00:00:00 2001 From: Charles Korn Date: Tue, 10 Dec 2024 20:41:53 +1100 Subject: [PATCH] Add `group_left` to mixed metrics tests --- pkg/streamingpromql/engine_test.go | 34 +++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/pkg/streamingpromql/engine_test.go b/pkg/streamingpromql/engine_test.go index 6ee0e43efac..3556aaba4bd 100644 --- a/pkg/streamingpromql/engine_test.go +++ b/pkg/streamingpromql/engine_test.go @@ -2710,30 +2710,44 @@ func TestCompareVariousMixedMetricsBinaryOperations(t *testing.T) { for _, labels := range labelCombinations { for _, op := range []string{"+", "-", "*", "/", "and", "unless", "or"} { - binaryExpr := fmt.Sprintf(`series{label="%s"}`, labels[0]) + expr := fmt.Sprintf(`series{label="%s"}`, labels[0]) for _, label := range labels[1:] { - binaryExpr += fmt.Sprintf(` %s series{label="%s"}`, op, label) + expr += fmt.Sprintf(` %s series{label="%s"}`, op, label) } - expressions = append(expressions, binaryExpr) + expressions = append(expressions, expr) // Same thing again, this time with grouping. - binaryExpr = fmt.Sprintf(`series{label="%s"}`, labels[0]) + expr = fmt.Sprintf(`series{label="%s"}`, labels[0]) for i, label := range labels[1:] { - binaryExpr += fmt.Sprintf(` %s ignoring (label, group) `, op) + expr += fmt.Sprintf(` %s ignoring (label, group) `, op) if i == 0 && len(labels) > 2 { - binaryExpr += "(" + expr += "(" } - binaryExpr += fmt.Sprintf(`{label="%s"}`, label) + expr += fmt.Sprintf(`{label="%s"}`, label) } - if len(labels) > 2 { - binaryExpr += ")" + expr += ")" + } + expressions = append(expressions, expr) + } + + // Similar thing again, this time with group_left + expr := fmt.Sprintf(`series{label="%s"}`, labels[0]) + for i, label := range labels[1:] { + expr += ` * on(group) group_left(label) ` + + if i == 0 && len(labels) > 2 { + expr += "(" } - expressions = append(expressions, binaryExpr) + expr += fmt.Sprintf(`{label="%s"}`, label) + } + if len(labels) > 2 { + expr += ")" } + expressions = append(expressions, expr) } runMixedMetricsTests(t, expressions, pointsPerSeries, seriesData, false)