-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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 no. 2 for 4444: Too verbose deprecations warnings #4473
Conversation
acb5dca
to
10dcddc
Compare
Added specs |
I believe this will also fix logstash-plugins/logstash-output-tcp#13 (comment) |
LGTM and tests pass (incl. plugin tests) |
when Fixnum, Symbol, IO, TrueClass, FalseClass, NilClass | ||
o | ||
when LogStash::Codecs::Base | ||
o.clone |
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.
should we do a clone here or instantiate a new codec?
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.
some question here? do we want to keep internal state, as I could read from the docs:
In general, clone and dup may have different semantics in descendant classes. While clone is used to duplicate an object, including its internal state, dup typically uses the class of the descendant object to create the new instance.
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.
Codecs::Base does this
def clone
return self.class.new(params)
end
and this will call deep_clone of the params given.
BTW codec base is the only subclass that has a clone method.
If anything we should call register after clone
e.g.
def self.deep_clone(o)
case o
when Hash
o.inject({}) {|h, (k,v)| h[k] = deep_clone(v); h }
when Array
o.map {|v| deep_clone(v) }
when Fixnum, Symbol, IO, TrueClass, FalseClass, NilClass
o
when LogStash::Codecs::Base
o.clone.tap {|c| c.register }
when String
o.dup
else
Marshal.load(Marshal.dump(o))
end
end
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.
@colinsurprenant @purbon - we definitely do want to call clone here. IMO this exactly what this clone method is for.
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.
seeing what clone is doing for codecs, makes sense for me.
@guyboertje calling register makes sense too.
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.
👍
Small comments about unit test location and clone, but for the rest it looks good to me. I tested manually with
and see
what means works as expected. Thanks @guyboertje for putting this fix in place. |
add test for subclasses of codec, filter, input and output Register codec clone, use String clone not dup so frozen strings stay so Fixes elastic#4444
@guyboertje , does this closes #5211 ? |
@driverpt - No, not until the Event#clone method uses |
Better method of ensuring that args are not mutated by plugin initialize.
NOTE:
LogStash::Util.deep_clone
asMarshal.load(Marshal.dump(o))
does not work directly on args because there is logger instance in args and Marshal can't dump IO.initialize
to deep_clone params, as well as the plugin.rbinitialize
to doconfig_init(@params)
.