-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance contains condition to work on fields that are arrays of string #2248
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,26 +269,36 @@ func (c *Condition) checkEquals(event common.MapStr) bool { | |
} | ||
|
||
func (c *Condition) checkContains(event common.MapStr) bool { | ||
|
||
outer: | ||
for field, equalValue := range c.contains { | ||
|
||
value, err := event.GetValue(field) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
sValue, err := extractString(value) | ||
if err != nil { | ||
logp.Warn("unexpected type %T in contains condition as it accepts only strings. ", value) | ||
switch value.(type) { | ||
case string: | ||
if !strings.Contains(value.(string), equalValue) { | ||
return false | ||
} | ||
case *string: | ||
if !strings.Contains(*value.(*string), equalValue) { | ||
return false | ||
} | ||
case []string: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andrewkroh why not ?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are equivalent if you add the required |
||
for _, s := range value.([]string) { | ||
if strings.Contains(s, equalValue) { | ||
continue outer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be changing the behavior of the method. This method returns true iff all the When I was adding this, I initially did There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Other option would be to package the second for loop into a function/method so "standard" continue could be used. I just think it makes it somehow harder to read. |
||
} | ||
} | ||
return false | ||
} | ||
if !strings.Contains(sValue, equalValue) { | ||
default: | ||
logp.Warn("unexpected type %T in contains condition as it accepts only strings.", value) | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
|
||
} | ||
|
||
func (c *Condition) checkRegexp(event common.MapStr) bool { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argh :-(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no love for the label? Naming?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not supported in my brain :-D