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

To support ES 6.0 #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lokanadham100
Copy link

Adding Header fields

Adding Header fields
@lokanadham100
Copy link
Author

lokanadham100 commented Nov 28, 2018 via email

statement[:scope] = resolver.scope
statement[:additional_parameters] = resolver.operands

NewRelic::Agent::Datastores.notice_statement(statement.inspect, elapsed) if statement
end

NewRelic::Agent::Datastores.wrap('Elasticsearch', resolver.operation_name, resolver.index, callback) do
perform_request_without_new_relic(method, path, params, body)
if @@old_version
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is probably not the right way to do this. Pretty sure the Elasticsearch gem we're monkey patching has a VERSION constant. Interrogate that constant with Gem::Version from the Stdlib and I think we can merge this.

Choose a reason for hiding this comment

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

Yeah I think in this case we could reference ::Elasticsearch::Transport::VERSION. This would make it clearer what "old version" actually means.

Could also consider moving the conditional into the metaprogramming level to avoid having to check the boolean on every single elasticsearch query.

Copy link

@lulessa lulessa Dec 12, 2018

Choose a reason for hiding this comment

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

I don't see a need for @@old_version class var, at all. Adds unnecessary complexity. Also, is it thread-safe?

Simplest backward-compat is to not pass headers through if it's nil.

Suggested change
if @@old_version
if headers.nil?

Benchmark: having a conditional, at all, is likely going to add 40% overhead to this block, but is (0.3744 - 0.6155) / 10_000_000 = 0.0000000241 seconds per call enough to warrant another solution?

null = nil
obj = { abc: 123 }.freeze
Benchmark.bm(3) do |b|
  b.report('direct') { 10_000_000.times { true } }
  b.report('if_nil')   { 10_000_000.times { if null.nil? then true else false end } }
  b.report('if_obj')   { 10_000_000.times { if obj.nil? then true else false end } }
end
          user     system      total        real
direct  0.372937   0.000791   0.373728 (  0.374498)
if_nil  0.612204   0.001569   0.613773 (  0.615512)
if_obj  0.622998   0.002316   0.625314 (  0.627959)

Copy link

@dbackeus dbackeus Dec 13, 2018

Choose a reason for hiding this comment

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

With regards to thread safety you can't have more than one gem version installed at a time so the value of @@old_version will never mutate (ie. it's thread safe).

That said - if we compare using the VERSION constant we don't need it anyway.

@stephenprater
Copy link
Collaborator

Go ahead and bump the minor in your PR please.

@Goltergaul
Copy link
Contributor

@lokanadham100 could you finish up the last requested changes for the pr? That would be super nice? :)

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

Successfully merging this pull request may close these issues.

5 participants