mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-31 15:06:26 +00:00
wip
This commit is contained in:
parent
2a1cede9f7
commit
22615889a7
4 changed files with 398 additions and 398 deletions
|
@ -72,25 +72,25 @@ func (fs *streamFilter) apply(bs *blockSearch, bm *bitmap) {
|
|||
}
|
||||
}
|
||||
|
||||
// ipv4RangeFilter matches the given ipv4 range [minValue..maxValue].
|
||||
// filterIPv4Range matches the given ipv4 range [minValue..maxValue].
|
||||
//
|
||||
// Example LogsQL: `fieldName:ipv4_range(127.0.0.1, 127.0.0.255)`
|
||||
type ipv4RangeFilter struct {
|
||||
type filterIPv4Range struct {
|
||||
fieldName string
|
||||
minValue uint32
|
||||
maxValue uint32
|
||||
}
|
||||
|
||||
func (rf *ipv4RangeFilter) String() string {
|
||||
minValue := string(encoding.MarshalUint32(nil, rf.minValue))
|
||||
maxValue := string(encoding.MarshalUint32(nil, rf.maxValue))
|
||||
return fmt.Sprintf("%sipv4_range(%s, %s)", quoteFieldNameIfNeeded(rf.fieldName), toIPv4String(nil, minValue), toIPv4String(nil, maxValue))
|
||||
func (fr *filterIPv4Range) String() string {
|
||||
minValue := string(encoding.MarshalUint32(nil, fr.minValue))
|
||||
maxValue := string(encoding.MarshalUint32(nil, fr.maxValue))
|
||||
return fmt.Sprintf("%sipv4_range(%s, %s)", quoteFieldNameIfNeeded(fr.fieldName), toIPv4String(nil, minValue), toIPv4String(nil, maxValue))
|
||||
}
|
||||
|
||||
func (rf *ipv4RangeFilter) apply(bs *blockSearch, bm *bitmap) {
|
||||
fieldName := rf.fieldName
|
||||
minValue := rf.minValue
|
||||
maxValue := rf.maxValue
|
||||
func (fr *filterIPv4Range) apply(bs *blockSearch, bm *bitmap) {
|
||||
fieldName := fr.fieldName
|
||||
minValue := fr.minValue
|
||||
maxValue := fr.maxValue
|
||||
|
||||
if minValue > maxValue {
|
||||
bm.resetBits()
|
||||
|
@ -149,14 +149,14 @@ type stringRangeFilter struct {
|
|||
maxValue string
|
||||
}
|
||||
|
||||
func (rf *stringRangeFilter) String() string {
|
||||
return fmt.Sprintf("%sstring_range(%s, %s)", quoteFieldNameIfNeeded(rf.fieldName), quoteTokenIfNeeded(rf.minValue), quoteTokenIfNeeded(rf.maxValue))
|
||||
func (fr *stringRangeFilter) String() string {
|
||||
return fmt.Sprintf("%sstring_range(%s, %s)", quoteFieldNameIfNeeded(fr.fieldName), quoteTokenIfNeeded(fr.minValue), quoteTokenIfNeeded(fr.maxValue))
|
||||
}
|
||||
|
||||
func (rf *stringRangeFilter) apply(bs *blockSearch, bm *bitmap) {
|
||||
fieldName := rf.fieldName
|
||||
minValue := rf.minValue
|
||||
maxValue := rf.maxValue
|
||||
func (fr *stringRangeFilter) apply(bs *blockSearch, bm *bitmap) {
|
||||
fieldName := fr.fieldName
|
||||
minValue := fr.minValue
|
||||
maxValue := fr.maxValue
|
||||
|
||||
if minValue > maxValue {
|
||||
bm.resetBits()
|
||||
|
@ -215,14 +215,14 @@ type lenRangeFilter struct {
|
|||
stringRepr string
|
||||
}
|
||||
|
||||
func (rf *lenRangeFilter) String() string {
|
||||
return quoteFieldNameIfNeeded(rf.fieldName) + "len_range" + rf.stringRepr
|
||||
func (fr *lenRangeFilter) String() string {
|
||||
return quoteFieldNameIfNeeded(fr.fieldName) + "len_range" + fr.stringRepr
|
||||
}
|
||||
|
||||
func (rf *lenRangeFilter) apply(bs *blockSearch, bm *bitmap) {
|
||||
fieldName := rf.fieldName
|
||||
minLen := rf.minLen
|
||||
maxLen := rf.maxLen
|
||||
func (fr *lenRangeFilter) apply(bs *blockSearch, bm *bitmap) {
|
||||
fieldName := fr.fieldName
|
||||
minLen := fr.minLen
|
||||
maxLen := fr.maxLen
|
||||
|
||||
if minLen > maxLen {
|
||||
bm.resetBits()
|
||||
|
@ -282,14 +282,14 @@ type rangeFilter struct {
|
|||
stringRepr string
|
||||
}
|
||||
|
||||
func (rf *rangeFilter) String() string {
|
||||
return quoteFieldNameIfNeeded(rf.fieldName) + "range" + rf.stringRepr
|
||||
func (fr *rangeFilter) String() string {
|
||||
return quoteFieldNameIfNeeded(fr.fieldName) + "range" + fr.stringRepr
|
||||
}
|
||||
|
||||
func (rf *rangeFilter) apply(bs *blockSearch, bm *bitmap) {
|
||||
fieldName := rf.fieldName
|
||||
minValue := rf.minValue
|
||||
maxValue := rf.maxValue
|
||||
func (fr *rangeFilter) apply(bs *blockSearch, bm *bitmap) {
|
||||
fieldName := fr.fieldName
|
||||
minValue := fr.minValue
|
||||
maxValue := fr.maxValue
|
||||
|
||||
if minValue > maxValue {
|
||||
bm.resetBits()
|
||||
|
@ -344,13 +344,13 @@ type regexpFilter struct {
|
|||
re *regexp.Regexp
|
||||
}
|
||||
|
||||
func (rf *regexpFilter) String() string {
|
||||
return fmt.Sprintf("%sre(%q)", quoteFieldNameIfNeeded(rf.fieldName), rf.re.String())
|
||||
func (fr *regexpFilter) String() string {
|
||||
return fmt.Sprintf("%sre(%q)", quoteFieldNameIfNeeded(fr.fieldName), fr.re.String())
|
||||
}
|
||||
|
||||
func (rf *regexpFilter) apply(bs *blockSearch, bm *bitmap) {
|
||||
fieldName := rf.fieldName
|
||||
re := rf.re
|
||||
func (fr *regexpFilter) apply(bs *blockSearch, bm *bitmap) {
|
||||
fieldName := fr.fieldName
|
||||
re := fr.re
|
||||
|
||||
// Verify whether filter matches const column
|
||||
v := bs.csh.getConstColumnValue(fieldName)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -328,7 +328,7 @@ func parseGenericFilter(lex *lexer, fieldName string) (filter, error) {
|
|||
case lex.isKeyword("in"):
|
||||
return parseFilterIn(lex, fieldName)
|
||||
case lex.isKeyword("ipv4_range"):
|
||||
return parseIPv4RangeFilter(lex, fieldName)
|
||||
return parseFilterIPv4Range(lex, fieldName)
|
||||
case lex.isKeyword("len_range"):
|
||||
return parseLenRangeFilter(lex, fieldName)
|
||||
case lex.isKeyword("range"):
|
||||
|
@ -531,14 +531,14 @@ func parseLenRangeFilter(lex *lexer, fieldName string) (filter, error) {
|
|||
return nil, fmt.Errorf("cannot parse maxLen at %s(): %w", funcName, err)
|
||||
}
|
||||
stringRepr := "(" + args[0] + ", " + args[1] + ")"
|
||||
rf := &lenRangeFilter{
|
||||
fr := &lenRangeFilter{
|
||||
fieldName: fieldName,
|
||||
minLen: minLen,
|
||||
maxLen: maxLen,
|
||||
|
||||
stringRepr: stringRepr,
|
||||
}
|
||||
return rf, nil
|
||||
return fr, nil
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -548,16 +548,16 @@ func parseStringRangeFilter(lex *lexer, fieldName string) (filter, error) {
|
|||
if len(args) != 2 {
|
||||
return nil, fmt.Errorf("unexpected number of args for %s(); got %d; want 2", funcName, len(args))
|
||||
}
|
||||
rf := &stringRangeFilter{
|
||||
fr := &stringRangeFilter{
|
||||
fieldName: fieldName,
|
||||
minValue: args[0],
|
||||
maxValue: args[1],
|
||||
}
|
||||
return rf, nil
|
||||
return fr, nil
|
||||
})
|
||||
}
|
||||
|
||||
func parseIPv4RangeFilter(lex *lexer, fieldName string) (filter, error) {
|
||||
func parseFilterIPv4Range(lex *lexer, fieldName string) (filter, error) {
|
||||
funcName := lex.token
|
||||
return parseFuncArgs(lex, fieldName, func(args []string) (filter, error) {
|
||||
if len(args) == 1 {
|
||||
|
@ -565,12 +565,12 @@ func parseIPv4RangeFilter(lex *lexer, fieldName string) (filter, error) {
|
|||
if !ok {
|
||||
return nil, fmt.Errorf("cannot parse IPv4 address or IPv4 CIDR %q at %s()", args[0], funcName)
|
||||
}
|
||||
rf := &ipv4RangeFilter{
|
||||
fr := &filterIPv4Range{
|
||||
fieldName: fieldName,
|
||||
minValue: minValue,
|
||||
maxValue: maxValue,
|
||||
}
|
||||
return rf, nil
|
||||
return fr, nil
|
||||
}
|
||||
if len(args) != 2 {
|
||||
return nil, fmt.Errorf("unexpected number of args for %s(); got %d; want 2", funcName, len(args))
|
||||
|
@ -583,12 +583,12 @@ func parseIPv4RangeFilter(lex *lexer, fieldName string) (filter, error) {
|
|||
if !ok {
|
||||
return nil, fmt.Errorf("cannot parse upper bound ip %q in %s()", funcName, args[1])
|
||||
}
|
||||
rf := &ipv4RangeFilter{
|
||||
fr := &filterIPv4Range{
|
||||
fieldName: fieldName,
|
||||
minValue: minValue,
|
||||
maxValue: maxValue,
|
||||
}
|
||||
return rf, nil
|
||||
return fr, nil
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -656,11 +656,11 @@ func parseRegexpFilter(lex *lexer, fieldName string) (filter, error) {
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid regexp %q for %s(): %w", arg, funcName, err)
|
||||
}
|
||||
rf := ®expFilter{
|
||||
fr := ®expFilter{
|
||||
fieldName: fieldName,
|
||||
re: re,
|
||||
}
|
||||
return rf, nil
|
||||
return fr, nil
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -726,14 +726,14 @@ func parseRangeFilter(lex *lexer, fieldName string) (filter, error) {
|
|||
maxValue = math.Nextafter(maxValue, math.Inf(-1))
|
||||
}
|
||||
|
||||
rf := &rangeFilter{
|
||||
fr := &rangeFilter{
|
||||
fieldName: fieldName,
|
||||
minValue: minValue,
|
||||
maxValue: maxValue,
|
||||
|
||||
stringRepr: stringRepr,
|
||||
}
|
||||
return rf, nil
|
||||
return fr, nil
|
||||
}
|
||||
|
||||
func parseFloat64(lex *lexer) (float64, string, error) {
|
||||
|
|
|
@ -325,16 +325,16 @@ func TestParseFilterIn(t *testing.T) {
|
|||
f(`foo-bar:in(foo,bar-baz.aa"bb","c,)d")`, `foo-bar`, []string{"foo", `bar-baz.aa"bb"`, "c,)d"})
|
||||
}
|
||||
|
||||
func TestParseIPv4RangeFilter(t *testing.T) {
|
||||
func TestParseFilterIPv4Range(t *testing.T) {
|
||||
f := func(s, fieldNameExpected string, minValueExpected, maxValueExpected uint32) {
|
||||
t.Helper()
|
||||
q, err := ParseQuery(s)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
rf, ok := q.f.(*ipv4RangeFilter)
|
||||
rf, ok := q.f.(*filterIPv4Range)
|
||||
if !ok {
|
||||
t.Fatalf("unexpected filter type; got %T; want *ipv4RangeFilter; filter: %s", q.f, q.f)
|
||||
t.Fatalf("unexpected filter type; got %T; want *filterIPv4Range; filter: %s", q.f, q.f)
|
||||
}
|
||||
if rf.fieldName != fieldNameExpected {
|
||||
t.Fatalf("unexpected fieldName; got %q; want %q", rf.fieldName, fieldNameExpected)
|
||||
|
@ -519,7 +519,7 @@ func TestParseRangeFilter(t *testing.T) {
|
|||
}
|
||||
rf, ok := q.f.(*rangeFilter)
|
||||
if !ok {
|
||||
t.Fatalf("unexpected filter type; got %T; want *ipv4RangeFilter; filter: %s", q.f, q.f)
|
||||
t.Fatalf("unexpected filter type; got %T; want *filterIPv4Range; filter: %s", q.f, q.f)
|
||||
}
|
||||
if rf.fieldName != fieldNameExpected {
|
||||
t.Fatalf("unexpected fieldName; got %q; want %q", rf.fieldName, fieldNameExpected)
|
||||
|
|
Loading…
Reference in a new issue