From ba161f5eb3c0c96f4ef486a6c15f6721895172fe Mon Sep 17 00:00:00 2001 From: rabbitstack Date: Sat, 28 Mar 2026 22:41:50 +0100 Subject: [PATCH] fix(filter): Include field argument in valuer If the field supports arguments, the name of the field passed to the valuer must include the argument as well. --- pkg/filter/filter.go | 21 +++++++++++++++++---- pkg/filter/ql/ast.go | 9 +++++---- pkg/filter/ql/literal.go | 11 ++++++++++- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/pkg/filter/filter.go b/pkg/filter/filter.go index 9c662361e..eb6eb2e5e 100644 --- a/pkg/filter/filter.go +++ b/pkg/filter/filter.go @@ -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 @@ -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 } } @@ -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 } } diff --git a/pkg/filter/ql/ast.go b/pkg/filter/ql/ast.go index ba8147122..a47df43ed 100644 --- a/pkg/filter/ql/ast.go +++ b/pkg/filter/ql/ast.go @@ -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. @@ -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 } diff --git a/pkg/filter/ql/literal.go b/pkg/filter/ql/literal.go index 99aac363a..65140dea1 100644 --- a/pkg/filter/ql/literal.go +++ b/pkg/filter/ql/literal.go @@ -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 }