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
Add support for condition on bool type #5954
Changes from 4 commits
9ca4dd2
5af5ad6
665a1be
7645f81
e4512aa
72c7eec
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 |
---|---|---|
|
@@ -21,8 +21,9 @@ type RangeValue struct { | |
} | ||
|
||
type EqualsValue struct { | ||
Int uint64 | ||
Str string | ||
Int uint64 | ||
Str string | ||
Bool bool | ||
} | ||
|
||
type Condition struct { | ||
|
@@ -118,13 +119,22 @@ func (c *Condition) setEquals(cfg *ConditionFields) error { | |
uintValue, err := extractInt(value) | ||
if err == nil { | ||
c.equals[field] = EqualsValue{Int: uintValue} | ||
} else { | ||
sValue, err := extractString(value) | ||
if err != nil { | ||
return err | ||
} | ||
continue | ||
} | ||
|
||
sValue, err := extractString(value) | ||
if err == nil { | ||
c.equals[field] = EqualsValue{Str: sValue} | ||
continue | ||
} | ||
|
||
bValue, err := extractBool(value) | ||
if err == nil { | ||
c.equals[field] = EqualsValue{Bool: bValue} | ||
continue | ||
} | ||
|
||
return err | ||
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. I wonder if we should create our "own" error here to describe better what happened. Otherwise just return the 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. Done Have the same thought, just don't know how far changes can be. |
||
} | ||
|
||
return nil | ||
|
@@ -257,16 +267,32 @@ func (c *Condition) checkEquals(event ValuesMap) bool { | |
if intValue != equalValue.Int { | ||
return false | ||
} | ||
} else { | ||
sValue, err := extractString(value) | ||
if err != nil { | ||
logp.Warn("unexpected type %T in equals condition as it accepts only integers and strings. ", value) | ||
|
||
continue | ||
} | ||
|
||
sValue, err := extractString(value) | ||
|
||
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. nit: remove new line 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. Done in both cases. Can you give explanations? Is there coding style agreements/convention and how it looks like? I think would be nice to add this to "make fmt" for example, anyway, would be nice to give this work to some script. If you give me explanations, I will try to prepare PR that made such checks automatically as part of CI process. 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. This is more a beats team convention that we normally check an error directly on the next line. Not sure if this can be covered with a script as it's pretty specific to the error case. Don't think too much about it. 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. Is it possible to publish beats team convention in Dev Guide? And perhaps it is possible to automate, with parser, or ast, we just need to check that it is "if" and in expression there is value with type "error", but I'm not sure, haven't so much experience with ast and parser. 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. Ok, looks like for fixing coding style we can start looking for something similar as https://github.com/golang/go/tree/master/src/cmd/fix or gofix. I pretty sure there is a possibility to do desired. I think I will try later. 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. @ewgRa All the code rules we require are covered by |
||
if err == nil { | ||
if sValue != equalValue.Str { | ||
return false | ||
} | ||
if sValue != equalValue.Str { | ||
|
||
continue | ||
} | ||
|
||
bValue, err := extractBool(value) | ||
|
||
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. Remove newline |
||
if err == nil { | ||
if bValue != equalValue.Bool { | ||
return false | ||
} | ||
|
||
continue | ||
} | ||
|
||
logp.Warn("unexpected type %T in equals condition as it accepts only integers, strings or bools. ", value) | ||
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. Can we change this to 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. Done |
||
return false | ||
} | ||
|
||
return true | ||
|
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.
Perhaps we should use
continue
in the code to have less nested if / else? Same on line 125.