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 no. 2 for 4444: Too verbose deprecations warnings #4473

Closed
wants to merge 1 commit into from

Conversation

guyboertje
Copy link
Contributor

Better method of ensuring that args are not mutated by plugin initialize.

NOTE:

  • I had to introduce LogStash::Util.deep_clone as Marshal.load(Marshal.dump(o)) does not work directly on args because there is logger instance in args and Marshal can't dump IO.
  • I had to alter all the codec, filter, input and output base.rb initialize to deep_clone params, as well as the plugin.rb initialize to do config_init(@params).

@guyboertje guyboertje force-pushed the fix/4444a branch 2 times, most recently from acb5dca to 10dcddc Compare January 13, 2016 15:51
@guyboertje
Copy link
Contributor Author

Added specs
fixes #4444

@andrewvc
Copy link
Contributor

I believe this will also fix logstash-plugins/logstash-output-tcp#13 (comment)

@andrewvc
Copy link
Contributor

LGTM and tests pass (incl. plugin tests)

when Fixnum, Symbol, IO, TrueClass, FalseClass, NilClass
o
when LogStash::Codecs::Base
o.clone
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@purbon
Copy link
Contributor

purbon commented Jan 14, 2016

Small comments about unit test location and clone, but for the rest it looks good to me.

I tested manually with

input {
  generator { 
    message => "foobar"
    count => 1
  }
}

output {
  stdout { codec => rubydebug }
  elasticsearch {
    hosts => [ "127.0.0.1:9200" ]
    workers => 3
  }
}

and see

skywalker% ./bin/logstash -f ../manual_testing/2.2/output-es.config 
Settings: Default pipeline workers: 4
Logstash startup completed
{
       "message" => "foobar",
      "@version" => "1",
    "@timestamp" => "2016-01-14T08:46:47.604Z",
          "host" => "0.0.0.0",
      "sequence" => 0
}
Logstash shutdown completed

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
@elasticsearch-bot
Copy link

Guy Boertje merged this into the following branches!

Branch Commits
master 1a4032b
2.2 88e3992
2.x 681719b

elasticsearch-bot pushed a commit that referenced this pull request Jan 14, 2016
add test for subclasses of codec, filter, input and output

Register codec clone, use String clone not dup so frozen strings stay so

Fixes #4444

Fixes #4473
elasticsearch-bot pushed a commit that referenced this pull request Jan 14, 2016
add test for subclasses of codec, filter, input and output

Register codec clone, use String clone not dup so frozen strings stay so

Fixes #4444

Fixes #4473
@guyboertje guyboertje deleted the fix/4444a branch January 14, 2016 14:35
@driverpt
Copy link

driverpt commented Jun 6, 2016

@guyboertje , does this closes #5211 ?

@guyboertje
Copy link
Contributor Author

@driverpt - No, not until the Event#clone method uses LogStash::Util.deep_clone - the PR has stalled.

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.

6 participants