mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-11 15:34:56 +00:00
lib/logstorage: avoid panic when parsing regex with stream filter (#5897)
This commit is contained in:
parent
7310605c27
commit
88b9088499
2 changed files with 9 additions and 13 deletions
|
@ -12,6 +12,7 @@ import (
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
|
||||||
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/regexutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type lexer struct {
|
type lexer struct {
|
||||||
|
@ -1070,6 +1071,13 @@ func parseStreamTagFilter(lex *lexer) (*streamTagFilter, error) {
|
||||||
op: op,
|
op: op,
|
||||||
value: value,
|
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
|
return stf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,9 @@ package logstorage
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/encoding"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/encoding"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/regexutil"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/regexutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -68,23 +66,13 @@ type streamTagFilter struct {
|
||||||
// value is the value
|
// value is the value
|
||||||
value string
|
value string
|
||||||
|
|
||||||
regexpOnce sync.Once
|
regexp *regexutil.PromRegex
|
||||||
regexp *regexutil.PromRegex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tf *streamTagFilter) getRegexp() *regexutil.PromRegex {
|
func (tf *streamTagFilter) getRegexp() *regexutil.PromRegex {
|
||||||
tf.regexpOnce.Do(tf.initRegexp)
|
|
||||||
return tf.regexp
|
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 {
|
func (tf *streamTagFilter) String() string {
|
||||||
return quoteTokenIfNeeded(tf.tagName) + tf.op + strconv.Quote(tf.value)
|
return quoteTokenIfNeeded(tf.tagName) + tf.op + strconv.Quote(tf.value)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue