Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions pkg/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ type Field struct {
Arg string
}

func (f *Field) String() string {
if f.Arg != "" {
var b strings.Builder
b.Grow(len(f.Value) + len(f.Arg) + 2)
b.WriteString(f.Value)
b.WriteByte('[')
b.WriteString(f.Arg)
b.WriteByte(']')
return b.String()
}
return f.Value
}

// BoundField contains the field meta attributes in addition to bound field specific fields.
type BoundField struct {
Field Field
Expand Down Expand Up @@ -489,15 +502,15 @@ func (f *filter) mapValuer(evt *event.Event) map[string]any {
v, err := accessor.Get(field, evt)
if v == nil || err != nil {
if v == nil {
valuer[field.Value] = defaultAccessorValue(field)
valuer[field.String()] = defaultAccessorValue(field)
}
if err != nil && !errs.IsParamNotFound(err) {
valuer[field.Value] = defaultAccessorValue(field)
valuer[field.String()] = defaultAccessorValue(field)
accessorErrors.Add(err.Error(), 1)
}
continue
}
valuer[field.Value] = v
valuer[field.String()] = v
break
}
}
Expand All @@ -507,7 +520,7 @@ func (f *filter) mapValuer(evt *event.Event) map[string]any {
// addField appends a new field to the filter fields list.
func (f *filter) addField(field *ql.FieldLiteral) {
for _, f := range f.fields {
if f.Value == field.Value {
if f.String() == field.String() {
return
}
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/filter/ql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
package ql

import (
fuzzysearch "github.com/lithammer/fuzzysearch/fuzzy"
"github.com/rabbitstack/fibratus/pkg/util/sets"
"github.com/rabbitstack/fibratus/pkg/util/wildcard"
"net"
"strconv"
"strings"

fuzzysearch "github.com/lithammer/fuzzysearch/fuzzy"
"github.com/rabbitstack/fibratus/pkg/util/sets"
"github.com/rabbitstack/fibratus/pkg/util/wildcard"
)

// Eval evaluates expr against a map that contains the field values.
Expand Down Expand Up @@ -198,7 +199,7 @@ func (v *ValuerEval) Eval(expr Expr) interface{} {
case *BoolLiteral:
return expr.Value
case *FieldLiteral:
val, ok := v.Valuer.Value(expr.Value)
val, ok := v.Valuer.Value(expr.String())
if !ok {
return nil
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/filter/ql/literal.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,16 @@ func (s StringLiteral) String() string {
return s.Value
}

func (f FieldLiteral) String() string {
func (f *FieldLiteral) String() string {
if f.Arg != "" {
var b strings.Builder
b.Grow(len(f.Value) + len(f.Arg) + 2)
b.WriteString(f.Value)
b.WriteByte('[')
b.WriteString(f.Arg)
b.WriteByte(']')
return b.String()
}
return f.Value
}

Expand Down
Loading