mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
all: use metricsql.CompileRegexp instead of regexp.Compile for compiling regexps used in graphite queries
This should speed up repeated queries, since metricsql.CompileRegexp returns regexps from the cache on subsequent calls for the same input regexp.
This commit is contained in:
parent
3d2cae9d75
commit
b7a4650ab0
3 changed files with 6 additions and 4 deletions
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/storage"
|
||||
"github.com/VictoriaMetrics/metrics"
|
||||
"github.com/VictoriaMetrics/metricsql"
|
||||
)
|
||||
|
||||
var maxTagValueSuffixes = flag.Int("search.maxTagValueSuffixesPerSearch", 100e3, "The maximum number of tag value suffixes returned from /metrics/find")
|
||||
|
@ -361,7 +362,7 @@ func getRegexpForQuery(query string, delimiter byte) (*regexp.Regexp, error) {
|
|||
if len(tail) > 0 {
|
||||
return nil, fmt.Errorf("unexpected tail left after parsing query %q; tail: %q", query, tail)
|
||||
}
|
||||
re, err := regexp.Compile(rs)
|
||||
re, err := metricsql.CompileRegexp(rs)
|
||||
regexpCache[k] = ®expCacheEntry{
|
||||
re: re,
|
||||
err: err,
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -30,6 +29,7 @@ import (
|
|||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/querytracer"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/storage"
|
||||
"github.com/VictoriaMetrics/metrics"
|
||||
"github.com/VictoriaMetrics/metricsql"
|
||||
"github.com/cespare/xxhash/v2"
|
||||
"github.com/valyala/fastrand"
|
||||
)
|
||||
|
@ -2674,7 +2674,7 @@ func applyGraphiteRegexpFilter(filter string, ss []string) ([]string, error) {
|
|||
// Anchor filter regexp to the beginning of the string as Graphite does.
|
||||
// See https://github.com/graphite-project/graphite-web/blob/3ad279df5cb90b211953e39161df416e54a84948/webapp/graphite/tags/localdatabase.py#L157
|
||||
filter = "^(?:" + filter + ")"
|
||||
re, err := regexp.Compile(filter)
|
||||
re, err := metricsql.CompileRegexp(filter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot parse regexp filter=%q: %w", filter, err)
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/uint64set"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/workingsetcache"
|
||||
"github.com/VictoriaMetrics/fastcache"
|
||||
"github.com/VictoriaMetrics/metricsql"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -1430,7 +1431,7 @@ func getRegexpForGraphiteQuery(q string) (*regexp.Regexp, error) {
|
|||
return nil, fmt.Errorf("unexpected tail left after parsing %q: %q", q, tail)
|
||||
}
|
||||
reStr := "^" + strings.Join(parts, "") + "$"
|
||||
return regexp.Compile(reStr)
|
||||
return metricsql.CompileRegexp(reStr)
|
||||
}
|
||||
|
||||
func getRegexpPartsForGraphiteQuery(q string) ([]string, string) {
|
||||
|
|
Loading…
Reference in a new issue