Skip to content

Commit 6044ec7

Browse files
committed
Skip regex compile if it is match all
Signed-off-by: Justin Jung <[email protected]>
1 parent e8bd7d0 commit 6044ec7

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

pkg/frontend/transport/roundtripper.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ package transport
33
import (
44
"bytes"
55
"context"
6-
"fmt"
76
"io"
87
"net/http"
98
"net/url"
10-
"regexp"
119
"strings"
1210
"time"
1311

@@ -39,12 +37,10 @@ func (b *buffer) Bytes() []byte {
3937
}
4038

4139
func (a *grpcRoundTripperAdapter) RoundTrip(r *http.Request) (*http.Response, error) {
42-
regexp.MustCompile("str")
4340
req, err := server.HTTPRequest(r)
4441
if err != nil {
4542
return nil, err
4643
}
47-
fmt.Println(r.URL.Path)
4844

4945
var (
5046
resp *httpgrpc.HTTPResponse

pkg/scheduler/queue/user_queues.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Limits interface {
1616
// of outstanding requests per tenant per request queue.
1717
MaxOutstandingPerTenant(user string) int
1818

19-
// QueryPriority returns query priority config for the tenant, including different priorities,
19+
// QueryPriority returns query priority config for the tenant, including priority level,
2020
// their attributes, and how many reserved queriers each priority has.
2121
QueryPriority(user string) validation.QueryPriority
2222
}

pkg/util/query/priority.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func GetPriority(requestParams url.Values, now time.Time, queryPriority validati
2525
for _, attribute := range priority.QueryAttributes {
2626
compiledRegex := attribute.CompiledRegex
2727

28-
if compiledRegex == nil || !compiledRegex.MatchString(queryParam) {
28+
if compiledRegex != nil && !compiledRegex.MatchString(queryParam) {
2929
continue
3030
}
3131

pkg/util/validation/limits.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ type DisabledRuleGroup struct {
4848
type DisabledRuleGroups []DisabledRuleGroup
4949

5050
type QueryPriority struct {
51-
Enabled bool `yaml:"enabled" doc:"nocli|description=Whether queries are assigned with priorities."`
52-
DefaultPriority int64 `yaml:"default_priority" doc:"nocli|description=Priority assigned to all queries by default. Use this as a baseline to make certain queries higher/lower priority.|default=1"`
51+
Enabled bool `yaml:"enabled" doc:"nocli|description=Whether queries are assigned with priorities.|default=false"`
52+
DefaultPriority int64 `yaml:"default_priority" doc:"nocli|description=Priority assigned to all queries by default. Must be a unique value. Use this as a baseline to make certain queries higher/lower priority.|default=1"`
5353
Priorities []PriorityDef `yaml:"priorities" doc:"nocli|description=List of priority definitions."`
5454
RegexCompiled bool `yaml:"-" doc:"nocli"`
5555
}
5656

5757
type PriorityDef struct {
58-
Priority int64 `yaml:"priority" doc:"nocli|description=Priority level."`
59-
ReservedQueriers float64 `yaml:"reserved_queriers" doc:"nocli|description=Number of reserved queriers to handle this priority only. Value between 0 and 1 will be used as a percentage."`
58+
Priority int64 `yaml:"priority" doc:"nocli|description=Priority level. Must be a unique value.|default=2"`
59+
ReservedQueriers float64 `yaml:"reserved_queriers" doc:"nocli|description=Number of reserved queriers to handle this priority only. Value between 0 and 1 will be used as a percentage.|default=0"`
6060
QueryAttributes []QueryAttribute `yaml:"query_attributes" doc:"nocli|description=List of query attributes to assign the priority."`
6161
}
6262

6363
type QueryAttribute struct {
64-
Regex string `yaml:"regex" doc:"nocli|description=Query string regex. If evaluated true (on top of meeting all other criteria), query is treated as a high priority."`
64+
Regex string `yaml:"regex" doc:"nocli|description=Query string regex. If evaluated true (on top of meeting all other criteria), query is treated as a high priority.|default=.*"`
6565
CompiledRegex *regexp.Regexp `yaml:"-" doc:"nocli"`
6666
StartTime time.Duration `yaml:"start_time" doc:"nocli|description=If query range falls between the start_time and end_time (on top of meeting all other criteria), query is treated as a high priority.|default=0s"`
6767
EndTime time.Duration `yaml:"end_time" doc:"nocli|description=If query range falls between the start_time and end_time (on top of meeting all other criteria), query is treated as a high priority.|default=0s"`
@@ -520,6 +520,9 @@ func (o *Overrides) QueryPriority(userID string) QueryPriority {
520520
priorities := o.GetOverridesForUser(userID).QueryPriority.Priorities
521521
for i, priority := range priorities {
522522
for j, attributes := range priority.QueryAttributes {
523+
if attributes.Regex == "" || attributes.Regex == ".*" || attributes.Regex == ".+" {
524+
continue // don't use regex at all, if it is match all
525+
}
523526
o.GetOverridesForUser(userID).QueryPriority.Priorities[i].QueryAttributes[j].CompiledRegex, _ = regexp.Compile(attributes.Regex)
524527
}
525528
}

0 commit comments

Comments
 (0)