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 Event method_missing to give better error messages for #[] and #[]= #6045

Closed

Conversation

guyboertje
Copy link
Contributor

@guyboertje guyboertje commented Oct 13, 2016

Reviewer:

I elected to add a method_missing handler for the Event class.

I chose not to do this in the JRuby Extension because IMO it will be easier to remove it later.

If it seems like we need to keep it for all time, we can move it to the JRuby Extension.

@jsvd
Copy link
Member

jsvd commented Oct 13, 2016

I like this idea. Since it's a debatable thing, I vote for getting a second or third LGTM.

That said, LGTM

end
if /^\[\]=$/.match(method_name.to_s)
raise NoMethodError.new("Direct event field references (i.e. event['field'] = 'value') have been disabled in favor of using event get and set methods (e.g. event.set('field', 'value')). Please consult the Logstash 5.0 breaking changes documentation for more details.")
Copy link
Contributor

Choose a reason for hiding this comment

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

we are using an almost identical duplicate string, maybe create a string const?

Copy link
Contributor Author

@guyboertje guyboertje Oct 13, 2016

Choose a reason for hiding this comment

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

OK - a frozen set, perhaps.

@colinsurprenant
Copy link
Contributor

I am good with this approach, solves the problem and will not interfere in normal operation.
But, I think this should be added in logstash/logstash-core-event-java/lib/logstash/event.rb no? any reason for adding it in logstash-core-event-java/lib/logstash-core-event-java/logstash-core-event-java.rb ?

@guyboertje
Copy link
Contributor Author

@colinsurprenant
My logic was to add the method missing after the jar was loaded (or failed trying) - so I added it in the current place.
It occurs to me now that I can still achieve this by adding it after the require "logstash-core-event" in the event.rb.
Will move it.

@colinsurprenant
Copy link
Contributor

Is is actually not important to have the jar loaded or not ... this is in the Ruby Event ... this is the purpose of event.rb, to add Ruby stuff to the Event class.

@@ -31,7 +31,24 @@ def shutdown?; false; end;
SHUTDOWN = ShutdownEvent.new
end

module LogStash class Event
Copy link
Contributor

Choose a reason for hiding this comment

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

this is nitpicking but why not define the class Event in the previous module LogStash definition ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true

@colinsurprenant
Copy link
Contributor

Great! :D if all tests are passing I'm LGTM

@guyboertje
Copy link
Contributor Author

got 2 LGTM - squashing

Change strings and regexs to CONSTANTS.

move method missing code to event.rb

doh - put Event class in already defined Logstash module
@elasticsearch-bot
Copy link

Guy Boertje merged this into the following branches!

Branch Commits
master 054dee9
5.0 0672f51
5.x 8cec4fa

elasticsearch-bot pushed a commit that referenced this pull request Oct 13, 2016
Change strings and regexs to CONSTANTS.

move method missing code to event.rb

doh - put Event class in already defined Logstash module

Fixes #6045
elasticsearch-bot pushed a commit that referenced this pull request Oct 13, 2016
Change strings and regexs to CONSTANTS.

move method missing code to event.rb

doh - put Event class in already defined Logstash module

Fixes #6045
@guyboertje guyboertje deleted the fix/logstash-filter-ruby/29 branch October 13, 2016 15:09
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

4 participants