Skip to content

Commit

Permalink
Add group_left to mixed metrics tests
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskorn committed Dec 10, 2024
1 parent c94cc48 commit 7214a8e
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions pkg/streamingpromql/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7214a8e

Please sign in to comment.