diff --git a/lib/logstorage/parser.go b/lib/logstorage/parser.go index d0f66c898..104491a01 100644 --- a/lib/logstorage/parser.go +++ b/lib/logstorage/parser.go @@ -12,6 +12,7 @@ import ( "unicode/utf8" "github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils" + "github.com/VictoriaMetrics/VictoriaMetrics/lib/regexutil" ) type lexer struct { @@ -1070,6 +1071,13 @@ func parseStreamTagFilter(lex *lexer) (*streamTagFilter, error) { op: op, value: value, } + if op == "=~" || op == "!~" { + re, err := regexutil.NewPromRegex(value) + if err != nil { + return nil, fmt.Errorf("invalid regexp %q for stream filter: %w", value, err) + } + stf.regexp = re + } return stf, nil } diff --git a/lib/logstorage/stream_filter.go b/lib/logstorage/stream_filter.go index 838e95ed0..0cce17229 100644 --- a/lib/logstorage/stream_filter.go +++ b/lib/logstorage/stream_filter.go @@ -3,11 +3,9 @@ package logstorage import ( "strconv" "strings" - "sync" "github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil" "github.com/VictoriaMetrics/VictoriaMetrics/lib/encoding" - "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" "github.com/VictoriaMetrics/VictoriaMetrics/lib/regexutil" ) @@ -68,23 +66,13 @@ type streamTagFilter struct { // value is the value value string - regexpOnce sync.Once - regexp *regexutil.PromRegex + regexp *regexutil.PromRegex } func (tf *streamTagFilter) getRegexp() *regexutil.PromRegex { - tf.regexpOnce.Do(tf.initRegexp) return tf.regexp } -func (tf *streamTagFilter) initRegexp() { - re, err := regexutil.NewPromRegex(tf.value) - if err != nil { - logger.Panicf("BUG: cannot parse regexp %q: %s", tf.value, err) - } - tf.regexp = re -} - func (tf *streamTagFilter) String() string { return quoteTokenIfNeeded(tf.tagName) + tf.op + strconv.Quote(tf.value) }