Skip to content
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

Merged
merged 6 commits into from Jan 25, 2018
Merged

Add support for condition on bool type #5954

merged 6 commits into from Jan 25, 2018

Conversation

ewgRa
Copy link
Contributor

@ewgRa ewgRa commented Dec 23, 2017

Pull request that add ability to use bool in processor conditions, related to #5659

@elasticmachine
Copy link
Collaborator

Can one of the admins verify this patch?

@ewgRa ewgRa changed the title Add support for condition on bool type (#5659) [WIP] Add support for condition on bool type (#5659) Dec 23, 2017
@ewgRa ewgRa changed the title [WIP] Add support for condition on bool type (#5659) Add support for condition on bool type (#5659) Dec 24, 2017
@ewgRa ewgRa changed the title Add support for condition on bool type (#5659) Add support for condition on bool type Dec 24, 2017
@@ -120,10 +121,17 @@ func (c *Condition) setEquals(cfg *ConditionFields) error {
c.equals[field] = EqualsValue{Int: uintValue}
Copy link
Member

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.

if sValue != equalValue.Str {
return false

if err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above, use continue to make the code more readable and less nested.

@@ -93,6 +93,18 @@ func TestEqualsCondition(t *testing.T) {
"proc.cpu.total_p.gt": 0.5,
}},
},

{
Equals: &ConditionFields{fields: map[string]interface{}{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #5960 to make adding tests cleaner. I realised when reading this that the way tests are written at the moment is not optimal for diffs.

@ruflin
Copy link
Member

ruflin commented Dec 27, 2017

jenkins, test it

ruflin added a commit to ruflin/beats that referenced this pull request Jan 4, 2018
This simplifies part of the condition tests to use table tests. Like this the expected result and the condition itself are close together in the code which makes it easier to read.

Cleanup was triggered when looking at elastic#5954 and realised it hard to follow in a diff.
exekias pushed a commit that referenced this pull request Jan 4, 2018
This simplifies part of the condition tests to use table tests. Like this the expected result and the condition itself are close together in the code which makes it easier to read.

Cleanup was triggered when looking at #5954 and realised it hard to follow in a diff.
@ewgRa
Copy link
Contributor Author

ewgRa commented Jan 14, 2018

@ruflin done

About "continue", for me both ways looks not so good, since "continue" also like "goto" here, but it is definitely better than X levels of if-else. I also thinking about extract this part to "extractValue" function, "NewEqualsValue(unk...)", or introduce "BoolCondition", but hard to say for me will be this better, or worse, so, I think current implementation also will work.

Please review

@ruflin
Copy link
Member

ruflin commented Jan 16, 2018

jenkins, test it

Copy link
Member

@ruflin ruflin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ewgRa Sorry for the delay. Finally had a look at the implementation and it looks good to me. Left a few nit pick comments.

}

bValue, err := extractBool(value)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove newline

}

sValue, err := extractString(value)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove new line

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to publish beats team convention in Dev Guide?
There is only one mention of coding style related to EditorConfig, but looks like there is another. I think it save a lot of time to you and contributors.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ewgRa All the code rules we require are covered by make fmt. The other ones like no new line to check the error and I'm sure there are a few others, are not very strict. We should add them to the Dev Guide but TBH we as a team would also have to think about which these actually are. It would be great if all of them could be checked by a tool

continue
}

return err
Copy link
Member

Choose a reason for hiding this comment

The 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 err from extractBool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

}

logp.Warn("unexpected type %T in equals condition as it accepts only integers, strings or bools. ", value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to logp.Err? In general we prefer not to use Warn and make things either Info or Err.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@ruflin
Copy link
Member

ruflin commented Jan 22, 2018

jenkins, test it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants