Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pkg/frontend/querymiddleware/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@ import (
"github.com/grafana/mimir/pkg/util"
)

func Test_queryStatsMiddleware_trackRegexpMatchers_NilExpr(t *testing.T) {
// This test verifies that trackRegexpMatchers does not panic when
// GetParsedQuery() returns nil (e.g., when query parsing failed).
reg := prometheus.NewPedanticRegistry()
mw := newQueryStatsMiddleware(reg, promql.EngineOpts{})

// Create a request with a nil queryExpr to simulate a failed parse.
req := &PrometheusRangeQueryRequest{
path: "/query_range",
start: util.TimeToMillis(start),
end: util.TimeToMillis(end),
step: step.Milliseconds(),
queryExpr: nil, // Simulates a query that failed to parse
}

ctx := user.InjectOrgID(context.Background(), "test")
_, ctx = ContextWithEmptyDetails(ctx)

// This should not panic.
require.NotPanics(t, func() {
_, _ = mw.Wrap(mockHandlerWith(nil, nil)).Do(ctx, req)
})
}

func Test_queryStatsMiddleware_Do(t *testing.T) {
const tenantID = "test"
type args struct {
Expand Down
Loading