Skip to content

Commit

Permalink
QueryFrontend: pre-compile regexp (thanos-io#5383)
Browse files Browse the repository at this point in the history
* pre compile regexp

Signed-off-by: Jin Dong <djdongjin95@gmail.com>

* rename oppattern to labelvaluespattern

Signed-off-by: Jin Dong <djdongjin95@gmail.com>
  • Loading branch information
djdongjin authored and GiedriusS committed May 25, 2022
1 parent 6c07dd9 commit 7898fb2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/queryfrontend/roundtrip.go
Expand Up @@ -27,6 +27,8 @@ const (
seriesOp = "series"
)

var labelValuesPattern = regexp.MustCompile("/api/v1/label/.+/values$")

// NewTripperware returns a Tripperware which sends requests to different sub tripperwares based on the query type.
func NewTripperware(config Config, reg prometheus.Registerer, logger log.Logger) (queryrange.Tripperware, error) {
var (
Expand Down Expand Up @@ -120,8 +122,7 @@ func getOperation(r *http.Request) string {
case strings.HasSuffix(r.URL.Path, "/api/v1/series"):
return seriesOp
default:
matched, err := regexp.MatchString("/api/v1/label/.+/values$", r.URL.Path)
if err == nil && matched {
if labelValuesPattern.MatchString(r.URL.Path) {
return labelValuesOp
}
}
Expand Down

0 comments on commit 7898fb2

Please sign in to comment.