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 fieldref assignment to not assume mutable object #62

Merged
merged 2 commits into from
Dec 16, 2015

Conversation

colinsurprenant
Copy link
Contributor

this is related to problem described in elastic/logstash#4140 and also relates to elastic/logstash#4191
we cannot assume anymore that field reference getter returns a mutable object.

tracked in elastic/logstash#4264

sorry for the whitespaces diffs :(

# this assumes implementation specific feature of returning a mutable object
# from a field ref which should not be assumed and will change in the future.

tags = event["tags"] || []
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 just replace this with event.tag(tag) and change the default implementation of tag to do this?

I think this cleanup fits the whole refactoring you're doing :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh yes, good catch, I don't know why I did not correctly clean this. is can be replaced with a simple:

event.tag(tag)

@colinsurprenant
Copy link
Contributor Author

@jsvd followup review request please!

if matched
filter_matched(event)
else
# Tag this event if we can't parse it. We can use this later to
# reparse+reindex logs if we improve the patterns given.
@tag_on_failure.each do |tag|
event["tags"] ||= []
event["tags"] << tag unless event["tags"].include?(tag)
# do not replace the code below with:
Copy link
Member

Choose a reason for hiding this comment

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

I think it's safe to remove this warning, it makes sense in the example below where a developer will instinctively try to optimize/dry/refactor code, here I doubt someone would replace event.tag(tag) with 2 lines of more complex code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point :P did not really pay attention to the comment.

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!

@jsvd
Copy link
Member

jsvd commented Dec 16, 2015

minor comment otherwise LGTM

@colinsurprenant
Copy link
Contributor Author

thanks, will fix comment and merge!

fix fieldref assignment to not assume mutable object

use Event#tag

remove useless comment
@colinsurprenant colinsurprenant merged commit bc0ad81 into logstash-plugins:master Dec 16, 2015
@colinsurprenant
Copy link
Contributor Author

pushed version 2.0.3

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

Successfully merging this pull request may close these issues.

None yet

2 participants