mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/logstorage: avoid panic when parsing regex with stream filter (#5897)
This commit is contained in:
parent
f2266f40b7
commit
a5795f533d
2 changed files with 9 additions and 13 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue