-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track number of optimised regexp label matchers (#4813)
* Track number of optimised regexp label matchers Signed-off-by: dhanu <andreasdhanu@gmail.com> * track-number-of-optimised-regexp-label-matchers - add changelog * track-number-of-optimised-regexp-label-matchers - revert * track-number-of-optimised-regexp-label-matchers - fix review * track-number-of-optimised-regexp-label-matchers - fix * track-number-of-optimised-regexp-label-matchers - rebase main * track-number-of-optimised-regexp-label-matchers - rebase main --------- Signed-off-by: dhanu <andreasdhanu@gmail.com> Co-authored-by: Marco Pracucci <marco@pracucci.com>
- Loading branch information
1 parent
bdd80b6
commit 3543b63
Showing
3 changed files
with
118 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
package querymiddleware | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/weaveworks/common/user" | ||
|
||
"github.com/grafana/mimir/pkg/util" | ||
) | ||
|
||
func Test_queryStatsMiddleware_Do(t *testing.T) { | ||
type args struct { | ||
req Request | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
expectedMetrics *strings.Reader | ||
}{ | ||
{ | ||
name: "happy path", | ||
args: args{ | ||
req: &PrometheusRangeQueryRequest{ | ||
Path: "/query_range", | ||
Start: util.TimeToMillis(start), | ||
End: util.TimeToMillis(end), | ||
Step: step.Milliseconds(), | ||
Query: `sum(sum_over_time(metric{app="test",namespace=~"short"}[5m]))`, | ||
}, | ||
}, | ||
expectedMetrics: strings.NewReader(` | ||
# HELP cortex_query_frontend_non_step_aligned_queries_total Total queries sent that are not step aligned. | ||
# TYPE cortex_query_frontend_non_step_aligned_queries_total counter | ||
cortex_query_frontend_non_step_aligned_queries_total 1 | ||
# HELP cortex_query_frontend_regexp_matcher_count Total number of regexp matchers | ||
# TYPE cortex_query_frontend_regexp_matcher_count counter | ||
cortex_query_frontend_regexp_matcher_count 1 | ||
# HELP cortex_query_frontend_regexp_matcher_optimized_count Total number of optimized regexp matchers | ||
# TYPE cortex_query_frontend_regexp_matcher_optimized_count counter | ||
cortex_query_frontend_regexp_matcher_optimized_count 1 | ||
`), | ||
}, | ||
{ | ||
name: "parseExpr failed", | ||
args: args{ | ||
req: &PrometheusRangeQueryRequest{ | ||
Path: "/query_range", | ||
Start: util.TimeToMillis(start), | ||
End: util.TimeToMillis(end), | ||
Step: step.Milliseconds(), | ||
Query: `?`, | ||
}, | ||
}, | ||
expectedMetrics: strings.NewReader(` | ||
# HELP cortex_query_frontend_non_step_aligned_queries_total Total queries sent that are not step aligned. | ||
# TYPE cortex_query_frontend_non_step_aligned_queries_total counter | ||
cortex_query_frontend_non_step_aligned_queries_total 1 | ||
# HELP cortex_query_frontend_regexp_matcher_count Total number of regexp matchers | ||
# TYPE cortex_query_frontend_regexp_matcher_count counter | ||
cortex_query_frontend_regexp_matcher_count 0 | ||
# HELP cortex_query_frontend_regexp_matcher_optimized_count Total number of optimized regexp matchers | ||
# TYPE cortex_query_frontend_regexp_matcher_optimized_count counter | ||
cortex_query_frontend_regexp_matcher_optimized_count 0 | ||
`), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
reg := prometheus.NewPedanticRegistry() | ||
mw := newQueryStatsMiddleware(reg) | ||
_, err := mw.Wrap(mockHandlerWith(nil, nil)).Do(user.InjectOrgID(context.Background(), "test"), tt.args.req) | ||
require.NoError(t, err) | ||
assert.NoError(t, testutil.GatherAndCompare(reg, tt.expectedMetrics)) | ||
}) | ||
} | ||
} |