Skip to content

Commit

Permalink
fix(filters): KVFilter process one field source
Browse files Browse the repository at this point in the history
KVFilter do not process one field source like 'foo=bar', now it split it
into {"foo":"bar"}
  • Loading branch information
childe committed Dec 16, 2024
1 parent 8ed115e commit 7409d60
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
3 changes: 0 additions & 3 deletions filter/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ func (p *KVFilter) Filter(event map[string]interface{}) (map[string]interface{},
return event, false
}
A := strings.Split(msg.(string), p.field_split)
if len(A) == 1 {
return event, false
}

var o map[string]interface{} = event
if p.target != "" {
Expand Down
21 changes: 21 additions & 0 deletions filter/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,24 @@ func TestKVFilter(t *testing.T) {
t.Error("kv failed")
}
}
func TestKVFilterOneField(t *testing.T) {
config := make(map[interface{}]interface{})
config["field_split"] = " "
config["value_split"] = "="
config["src"] = "message"
f := BuildFilter("KV", config)

event := make(map[string]interface{})
event["message"] = "a=aaa"
t.Log(event)

event, ok := f.Filter(event)
if !ok {
t.Error("kv failed")
}
t.Log(event)

if event["a"] != "aaa" {
t.Error("kv failed")
}
}

0 comments on commit 7409d60

Please sign in to comment.