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

Fix processor failure in Filebeat when using regex, contain, or equals #2209

Merged
merged 1 commit into from
Aug 10, 2016

Conversation

andrewkroh
Copy link
Member

When using any of those conditions with the message field in Filebeat a warning would occur and no processor would be applied. The warning message was:

WARN unexpected type *string in contains condition as it accepts only strings.

This occurred because Filebeat was passing the message field as a *string (string pointer). The processor code only expected to receive string values.

This PR contains three changes:

  • Enhance the processor code to accept *string and string.
  • Make filebeat pass the message field as a string rather than *string.
  • Modify a test case to work against the message field rather than the source field.

Fixes #2178

When using any of those conditions with the `message` field in Filebeat a warning would occur and no processor would be applied. The warning message was:

    WARN unexpected type *string in contains condition as it accepts only strings.

This occurred because Filebeat was passing the message field as a *string (string pointer). The processor code only expected to receive string values.

This PR contains three changes:

- Enhance the processor code to accept *string and string.
- Make filebeat pass the message field as a string rather than *string.
- Modify a test case to work against the message field rather than the source field.

Fixes elastic#2178
@andrewkroh andrewkroh added bug Filebeat Filebeat needs_backport PR is waiting to be backported to other branches. labels Aug 9, 2016
@ruflin ruflin merged commit 0725db1 into elastic:master Aug 10, 2016
@andrewkroh andrewkroh deleted the bugfix/filebeat-processors branch August 11, 2016 21:57
@@ -125,8 +125,10 @@ func extractInt(unk interface{}) (uint64, error) {
func extractString(unk interface{}) (string, error) {
switch s := unk.(type) {
case string:
return string(s), nil
return s, nil
case *string:
Copy link
Contributor

Choose a reason for hiding this comment

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

@andrewkroh I think we need to tackle this problem in the event, and make sure that the event we are exporting doesn't contain any pointers. We shouldn't allow pointers in the condition of the processor.

Copy link
Member Author

Choose a reason for hiding this comment

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

I fixed the code that was producing the event containing the string pointer too. I added this code to just make it work in case someone makes this mistake in a community Beat.

We shouldn't allow pointers in the condition of the processor.

How do we enforce this? Logging a warning isn't really strong enforcement. Ideally we could prevent a *string values from ever being written to the event, but this would require an actual event type with an API that's not a MapStr.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was expecting that ConvertToGenericEvent should fix that after marshalling & unmarshalling a pointer to string, becomes string: https://github.com/elastic/beats/blob/master/libbeat/common/event.go#L70. But I assume it doesn't do that.
Ideally, it would be nice if we can restrict somehow the type of the fields in the event, but for now an warning should be enough.

@andrewkroh andrewkroh removed the needs_backport PR is waiting to be backported to other branches. label Nov 1, 2016
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.

3 participants