Fix up a merge conflict on log filter (#4815)

* Fix up a merge conflict on log filter

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* use the same parameter order as the stdlib

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
pull/4823/head
Cyril Tovena 4 years ago committed by GitHub
parent 09f5a90710
commit 45ed6d560d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      pkg/logql/log/filter.go
  2. 4
      pkg/logql/log/ip.go

@ -83,6 +83,7 @@ func NewAndFilter(left Filterer, right Filterer) Filterer {
func (a andFilter) Filter(line []byte) bool {
return a.left.Filter(line) && a.right.Filter(line)
}
func (a andFilter) ToStage() Stage {
return StageFunc{
process: func(line []byte, _ *LabelsBuilder) ([]byte, bool) {
@ -245,22 +246,30 @@ type containsFilter struct {
}
func (l *containsFilter) Filter(line []byte) bool {
if !l.caseInsensitive {
return bytes.Contains(line, l.match)
return contains(line, l.match, l.caseInsensitive)
}
func contains(line, substr []byte, caseInsensitive bool) bool {
if !caseInsensitive {
return bytes.Contains(line, substr)
}
if len(l.match) == 0 {
return containsLower(line, substr)
}
func containsLower(line, substr []byte) bool {
if len(substr) == 0 {
return true
}
if len(l.match) > len(line) {
if len(substr) > len(line) {
return false
}
j := 0
for len(line) > 0 {
// ascii fast case
if c := line[0]; c < utf8.RuneSelf {
if c == l.match[j] || c+'a'-'A' == l.match[j] {
if c == substr[j] || c+'a'-'A' == substr[j] {
j++
if j == len(l.match) {
if j == len(substr) {
return true
}
line = line[1:]
@ -272,10 +281,10 @@ func (l *containsFilter) Filter(line []byte) bool {
}
// unicode slow case
lr, lwid := utf8.DecodeRune(line)
mr, mwid := utf8.DecodeRune(l.match[j:])
mr, mwid := utf8.DecodeRune(substr[j:])
if lr == mr || mr == unicode.To(unicode.LowerCase, lr) {
j += mwid
if j == len(l.match) {
if j == len(substr) {
return true
}
line = line[lwid:]
@ -327,10 +336,7 @@ func (f *containsAllFilter) Empty() bool {
func (f containsAllFilter) Filter(line []byte) bool {
for _, m := range f.matches {
if m.caseInsensitive {
line = bytes.ToLower(line)
}
if !bytes.Contains(line, m.match) {
if !contains(line, m.match, m.caseInsensitive) {
return false
}
}

@ -192,7 +192,7 @@ func (f *ipFilter) filter(line []byte) bool {
}
ip, err := netaddr.ParseIP(string(line[start : start+iplen]))
if err == nil {
if contains(f.matcher, ip) {
if containsIP(f.matcher, ip) {
return true, 0
}
}
@ -223,7 +223,7 @@ func (f *ipFilter) filter(line []byte) bool {
return false
}
func contains(matcher IPMatcher, ip netaddr.IP) bool {
func containsIP(matcher IPMatcher, ip netaddr.IP) bool {
switch m := matcher.(type) {
case netaddr.IP:
return m.Compare(ip) == 0

Loading…
Cancel
Save