newrelic_rpm 6.3.0.355 → 6.4.0.356

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -5
  3. data/CHANGELOG.md +44 -0
  4. data/lib/new_relic/agent/commands/agent_command_router.rb +2 -21
  5. data/lib/new_relic/agent/configuration/default_source.rb +1 -29
  6. data/lib/new_relic/agent/configuration/environment_source.rb +4 -2
  7. data/lib/new_relic/agent/configuration/high_security_source.rb +1 -0
  8. data/lib/new_relic/agent/connect/request_builder.rb +5 -0
  9. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +24 -42
  10. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +45 -69
  11. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +70 -53
  12. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +29 -8
  13. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +33 -47
  14. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +2 -2
  15. data/lib/new_relic/agent/instrumentation/grape.rb +2 -3
  16. data/lib/new_relic/agent/instrumentation/{evented_subscriber.rb → notifications_subscriber.rb} +7 -66
  17. data/lib/new_relic/agent/new_relic_service.rb +0 -4
  18. data/lib/new_relic/agent/threading/backtrace_service.rb +3 -3
  19. data/lib/new_relic/agent/threading/thread_profile.rb +9 -23
  20. data/lib/new_relic/agent/transaction.rb +0 -2
  21. data/lib/new_relic/agent/transaction/trace.rb +3 -8
  22. data/lib/new_relic/agent/transaction/trace_builder.rb +0 -1
  23. data/lib/new_relic/agent/transaction_sampler.rb +1 -5
  24. data/lib/new_relic/rack/browser_monitoring.rb +10 -8
  25. data/lib/new_relic/version.rb +1 -1
  26. data/lib/tasks/config.rake +1 -2
  27. metadata +3 -6
  28. data/lib/new_relic/agent/commands/xray_session.rb +0 -55
  29. data/lib/new_relic/agent/commands/xray_session_collection.rb +0 -161
  30. data/lib/new_relic/agent/transaction/xray_sample_buffer.rb +0 -64
@@ -163,10 +163,6 @@ module NewRelic
163
163
  invoke_remote(:agent_command_results, [@agent_id, results])
164
164
  end
165
165
 
166
- def get_xray_metadata(xray_ids)
167
- invoke_remote(:get_xray_metadata, [@agent_id, *xray_ids])
168
- end
169
-
170
166
  def analytic_event_data(data)
171
167
  _, items = data
172
168
  invoke_remote(:analytic_event_data, [@agent_id, *data],
@@ -36,8 +36,8 @@ module NewRelic
36
36
  @worker_loop = NewRelic::Agent::WorkerLoop.new
37
37
 
38
38
  # Memoize overhead % to avoid getting stale OR looked up every poll
39
- @overhead_percent_threshold = NewRelic::Agent.config[:'xray_session.max_profile_overhead']
40
- NewRelic::Agent.config.register_callback(:'xray_session.max_profile_overhead') do |new_value|
39
+ @overhead_percent_threshold = NewRelic::Agent.config[:'thread_profiler.max_profile_overhead']
40
+ NewRelic::Agent.config.register_callback(:'thread_profiler.max_profile_overhead') do |new_value|
41
41
  @overhead_percent_threshold = new_value
42
42
  end
43
43
 
@@ -213,7 +213,7 @@ module NewRelic
213
213
  if @buffer[thread].length < MAX_BUFFER_LENGTH
214
214
  @buffer[thread] << [timestamp, backtrace]
215
215
  else
216
- NewRelic::Agent.increment_metric('Supportability/XraySessions/DroppedBacktraces')
216
+ NewRelic::Agent.increment_metric('Supportability/ThreadProfiler/DroppedBacktraces')
217
217
  end
218
218
  end
219
219
  end
@@ -16,7 +16,7 @@ module NewRelic
16
16
 
17
17
  attr_reader :profile_id, :traces, :sample_period,
18
18
  :duration, :poll_count, :backtrace_count, :failure_count,
19
- :created_at, :xray_id, :command_arguments, :profile_agent_code
19
+ :created_at, :command_arguments, :profile_agent_code
20
20
  attr_accessor :finished_at
21
21
 
22
22
  def initialize(command_arguments={})
@@ -25,7 +25,6 @@ module NewRelic
25
25
  @duration = command_arguments.fetch('duration', 120)
26
26
  @sample_period = command_arguments.fetch('sample_period', 0.1)
27
27
  @profile_agent_code = command_arguments.fetch('profile_agent_code', false)
28
- @xray_id = command_arguments.fetch('x_ray_id', nil)
29
28
  @finished = false
30
29
 
31
30
  @traces = {
@@ -51,14 +50,6 @@ module NewRelic
51
50
  @poll_count += 1
52
51
  end
53
52
 
54
- def sample_count
55
- xray? ? @backtrace_count : @poll_count
56
- end
57
-
58
- def xray?
59
- !!@xray_id
60
- end
61
-
62
53
  def empty?
63
54
  @backtrace_count == 0
64
55
  end
@@ -121,26 +112,21 @@ module NewRelic
121
112
  def to_collector_array(encoder)
122
113
  encoded_trace_tree = encoder.encode(generate_traces, :skip_normalization => true)
123
114
  result = [
124
- int(self.profile_id),
125
- float(self.created_at),
126
- float(self.finished_at),
127
- int(self.sample_count),
115
+ int(profile_id),
116
+ float(created_at),
117
+ float(finished_at),
118
+ int(poll_count),
128
119
  encoded_trace_tree,
129
- int(self.unique_thread_count),
120
+ int(unique_thread_count),
130
121
  0 # runnable thread count, which we don't track
131
122
  ]
132
- result << int(@xray_id) if xray?
133
123
  result
134
124
  end
135
125
 
136
126
  def to_log_description
137
- id = if xray?
138
- "@xray_id: #{xray_id}"
139
- else
140
- "@profile_id: #{profile_id}"
141
- end
142
-
143
- "#<ThreadProfile:#{object_id} #{id} @command_arguments=#{@command_arguments.inspect}>"
127
+ "#<ThreadProfile:#{object_id} "\
128
+ "@profile_id: #{profile_id} "\
129
+ "@command_arguments=#{@command_arguments.inspect}>"
144
130
  end
145
131
 
146
132
  end
@@ -355,8 +355,6 @@ module NewRelic
355
355
 
356
356
  # For common interface with Trace
357
357
  alias_method :transaction_name, :best_name
358
-
359
- attr_accessor :xray_session_id
360
358
  # End common interface
361
359
 
362
360
  def promoted_transaction_name(name)
@@ -11,7 +11,7 @@ module NewRelic
11
11
  class FinishedTraceError < StandardError; end
12
12
 
13
13
  attr_reader :start_time, :root_node
14
- attr_accessor :transaction_name, :guid, :xray_session_id, :attributes,
14
+ attr_accessor :transaction_name, :guid, :attributes,
15
15
  :node_count, :finished, :threshold, :profile
16
16
 
17
17
  ROOT = "ROOT".freeze
@@ -40,11 +40,6 @@ module NewRelic
40
40
  self.root_node.duration
41
41
  end
42
42
 
43
- def forced?
44
- return true if NewRelic::Coerce.int_or_nil(xray_session_id)
45
- false
46
- end
47
-
48
43
  def synthetics_resource_id
49
44
  intrinsic_attributes = attributes.intrinsic_attributes_for(NewRelic::Agent::AttributeFilter::DST_TRANSACTION_TRACER)
50
45
  intrinsic_attributes[:synthetics_resource_id]
@@ -148,8 +143,8 @@ module NewRelic
148
143
  encoder.encode(trace_tree(attributes_hash)),
149
144
  NewRelic::Coerce.string(self.guid),
150
145
  nil,
151
- forced?,
152
- NewRelic::Coerce.int_or_nil(xray_session_id),
146
+ false, # forced?,
147
+ nil, # NewRelic::Coerce.int_or_nil(xray_session_id),
153
148
  NewRelic::Coerce.string(self.synthetics_resource_id)
154
149
  ]
155
150
  end
@@ -48,7 +48,6 @@ module NewRelic
48
48
  trace.guid = transaction.guid
49
49
  trace.attributes = transaction.attributes
50
50
  trace.threshold = transaction.threshold
51
- trace.xray_session_id = transaction.xray_session_id
52
51
  trace.finished = true
53
52
  end
54
53
  end
@@ -4,7 +4,6 @@
4
4
 
5
5
  require 'new_relic/agent/transaction/slowest_sample_buffer'
6
6
  require 'new_relic/agent/transaction/synthetics_sample_buffer'
7
- require 'new_relic/agent/transaction/xray_sample_buffer'
8
7
  require 'new_relic/agent/transaction/trace_builder'
9
8
 
10
9
  module NewRelic
@@ -19,13 +18,10 @@ module NewRelic
19
18
  #
20
19
  # @api public
21
20
  class TransactionSampler
22
- attr_reader :last_sample, :xray_sample_buffer
21
+ attr_reader :last_sample
23
22
 
24
23
  def initialize
25
- @xray_sample_buffer = NewRelic::Agent::Transaction::XraySampleBuffer.new
26
-
27
24
  @sample_buffers = []
28
- @sample_buffers << @xray_sample_buffer
29
25
  @sample_buffers << NewRelic::Agent::Transaction::SlowestSampleBuffer.new
30
26
  @sample_buffers << NewRelic::Agent::Transaction::SyntheticsSampleBuffer.new
31
27
 
@@ -29,15 +29,16 @@ module NewRelic::Rack
29
29
  GT = ">".freeze
30
30
 
31
31
  def traced_call(env)
32
- result = @app.call(env) # [status, headers, response]
32
+ result = @app.call(env)
33
+ (status, headers, response) = result
33
34
 
34
35
  js_to_inject = NewRelic::Agent.browser_timing_header
35
- if (js_to_inject != "") && should_instrument?(env, result[0], result[1])
36
- response_string = autoinstrument_source(result[2], result[1], js_to_inject)
36
+ if (js_to_inject != "") && should_instrument?(env, status, headers)
37
+ response_string = autoinstrument_source(response, headers, js_to_inject)
37
38
 
38
39
  env[ALREADY_INSTRUMENTED_KEY] = true
39
40
  if response_string
40
- response = Rack::Response.new(response_string, result[0], result[1])
41
+ response = Rack::Response.new(response_string, status, headers)
41
42
  response.finish
42
43
  else
43
44
  result
@@ -55,7 +56,7 @@ module NewRelic::Rack
55
56
  !env[ALREADY_INSTRUMENTED_KEY] &&
56
57
  is_html?(headers) &&
57
58
  !is_attachment?(headers) &&
58
- !is_streaming?(env)
59
+ !is_streaming?(env, headers)
59
60
  end
60
61
 
61
62
  def is_html?(headers)
@@ -66,10 +67,11 @@ module NewRelic::Rack
66
67
  headers[CONTENT_DISPOSITION] && headers[CONTENT_DISPOSITION].include?(ATTACHMENT)
67
68
  end
68
69
 
69
- def is_streaming?(env)
70
- return false unless defined?(ActionController::Live)
70
+ def is_streaming?(env, headers)
71
+ return true if headers && headers['Transfer-Encoding'] == 'chunked'
71
72
 
72
- env['action_controller.instance'].class.included_modules.include?(ActionController::Live)
73
+ defined?(ActionController::Live) &&
74
+ env['action_controller.instance'].class.included_modules.include?(ActionController::Live)
73
75
  end
74
76
 
75
77
  CHARSET_RE = /<\s*meta[^>]+charset\s*=[^>]*>/im.freeze
@@ -11,7 +11,7 @@ module NewRelic
11
11
  end
12
12
 
13
13
  MAJOR = 6
14
- MINOR = 3
14
+ MINOR = 4
15
15
  TINY = 0
16
16
 
17
17
  begin
@@ -17,8 +17,7 @@ namespace :newrelic do
17
17
  }
18
18
 
19
19
  NAME_OVERRIDES = {
20
- "slow_sql" => "Slow SQL",
21
- "xray_session" => "X-Ray Session"
20
+ "slow_sql" => "Slow SQL"
22
21
  }
23
22
 
24
23
  def output(format)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newrelic_rpm
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.3.0.355
4
+ version: 6.4.0.356
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Wear
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-04-25 00:00:00.000000000 Z
14
+ date: 2019-05-21 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
@@ -178,8 +178,6 @@ files:
178
178
  - lib/new_relic/agent/commands/agent_command.rb
179
179
  - lib/new_relic/agent/commands/agent_command_router.rb
180
180
  - lib/new_relic/agent/commands/thread_profiler_session.rb
181
- - lib/new_relic/agent/commands/xray_session.rb
182
- - lib/new_relic/agent/commands/xray_session_collection.rb
183
181
  - lib/new_relic/agent/configuration.rb
184
182
  - lib/new_relic/agent/configuration/default_source.rb
185
183
  - lib/new_relic/agent/configuration/dotted_hash.rb
@@ -256,7 +254,6 @@ files:
256
254
  - lib/new_relic/agent/instrumentation/curb.rb
257
255
  - lib/new_relic/agent/instrumentation/data_mapper.rb
258
256
  - lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb
259
- - lib/new_relic/agent/instrumentation/evented_subscriber.rb
260
257
  - lib/new_relic/agent/instrumentation/excon.rb
261
258
  - lib/new_relic/agent/instrumentation/excon/connection.rb
262
259
  - lib/new_relic/agent/instrumentation/excon/middleware.rb
@@ -273,6 +270,7 @@ files:
273
270
  - lib/new_relic/agent/instrumentation/mongo.rb
274
271
  - lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb
275
272
  - lib/new_relic/agent/instrumentation/net.rb
273
+ - lib/new_relic/agent/instrumentation/notifications_subscriber.rb
276
274
  - lib/new_relic/agent/instrumentation/padrino.rb
277
275
  - lib/new_relic/agent/instrumentation/passenger_instrumentation.rb
278
276
  - lib/new_relic/agent/instrumentation/queue_time.rb
@@ -360,7 +358,6 @@ files:
360
358
  - lib/new_relic/agent/transaction/trace_node.rb
361
359
  - lib/new_relic/agent/transaction/tracing.rb
362
360
  - lib/new_relic/agent/transaction/transaction_sample_buffer.rb
363
- - lib/new_relic/agent/transaction/xray_sample_buffer.rb
364
361
  - lib/new_relic/agent/transaction_error_primitive.rb
365
362
  - lib/new_relic/agent/transaction_event_aggregator.rb
366
363
  - lib/new_relic/agent/transaction_event_primitive.rb
@@ -1,55 +0,0 @@
1
- # encoding: utf-8
2
- # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
-
5
- require 'forwardable'
6
-
7
- module NewRelic
8
- module Agent
9
- module Commands
10
- class XraySession
11
- extend Forwardable
12
-
13
- attr_reader :id, :command_arguments
14
- attr_reader :xray_session_name, :key_transaction_name,
15
- :requested_trace_count, :duration, :sample_period
16
-
17
- def initialize(command_arguments)
18
- @command_arguments = command_arguments
19
- @id = command_arguments.fetch("x_ray_id", nil)
20
- @xray_session_name = command_arguments.fetch("xray_session_name", "")
21
- @key_transaction_name = command_arguments.fetch("key_transaction_name", "")
22
- @requested_trace_count = command_arguments.fetch("requested_trace_count", 100)
23
- @duration = command_arguments.fetch("duration", 86400)
24
- @sample_period = command_arguments.fetch("sample_period", 0.1)
25
- @run_profiler = command_arguments.fetch("run_profiler", true)
26
- end
27
-
28
- def active?
29
- @active
30
- end
31
-
32
- def run_profiler?
33
- @run_profiler && NewRelic::Agent.config[:'xray_session.allow_profiles']
34
- end
35
-
36
- def activate
37
- @active = true
38
- @start_time = Time.now
39
- end
40
-
41
- def deactivate
42
- @active = false
43
- end
44
-
45
- def requested_period
46
- @sample_period
47
- end
48
-
49
- def finished?
50
- @start_time + @duration < Time.now
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,161 +0,0 @@
1
- # encoding: utf-8
2
- # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
-
5
- require 'forwardable'
6
- require 'thread'
7
- require 'new_relic/agent/commands/xray_session'
8
-
9
- module NewRelic
10
- module Agent
11
- module Commands
12
- class XraySessionCollection
13
- extend Forwardable
14
-
15
- def initialize(backtrace_service, event_listener)
16
- @backtrace_service = backtrace_service
17
-
18
- # This lock protects access to the sessions hash, but it's expected
19
- # that individual session objects within the hash will be manipulated
20
- # outside the lock. This is safe because manipulation of the session
21
- # objects is expected from only a single thread (the harvest thread)
22
- @sessions_lock = Mutex.new
23
- @sessions = {}
24
-
25
- if event_listener
26
- event_listener.subscribe(:before_harvest, &method(:cleanup_finished_sessions))
27
- end
28
- end
29
-
30
- def handle_active_xray_sessions(agent_command)
31
- # If X-Rays are disabled, just be quiet about it and don't start the
32
- # command. Other hosts might be running the X-Ray, so we don't need
33
- # to bark on every get_agent_commands.
34
- if !NewRelic::Agent.config[:'xray_session.enabled']
35
- NewRelic::Agent.logger.debug("Not responding to X-Ray command because of config 'xray_session.enabled' = #{NewRelic::Agent.config[:'xray_session.enabled']}")
36
- return
37
- end
38
-
39
- incoming_ids = agent_command.arguments["xray_ids"]
40
- deactivate_for_incoming_sessions(incoming_ids)
41
- activate_sessions(incoming_ids)
42
- end
43
-
44
- def session_id_for_transaction_name(name)
45
- @sessions_lock.synchronize do
46
- @sessions.each do |id, session|
47
- return id if session.key_transaction_name == name
48
- end
49
- end
50
- nil
51
- end
52
-
53
- NO_PROFILES = [].freeze
54
-
55
- def harvest_thread_profiles
56
- return NO_PROFILES unless NewRelic::Agent::Threading::BacktraceService.is_supported?
57
-
58
- profiles = active_thread_profiling_sessions.map do |session|
59
- NewRelic::Agent.logger.debug("Harvesting profile for X-Ray session #{session.inspect}")
60
- @backtrace_service.harvest(session.key_transaction_name)
61
- end
62
- profiles.reject! {|p| p.empty?}
63
- profiles.compact
64
- end
65
-
66
- def stop_all_sessions
67
- deactivate_for_incoming_sessions([])
68
- end
69
-
70
- def cleanup_finished_sessions
71
- finished_session_ids.each do |id|
72
- NewRelic::Agent.logger.debug("Finished X-Ray session #{id} by duration. Removing it from active sessions.")
73
- remove_session_by_id(id)
74
- end
75
- end
76
-
77
-
78
- ### Internals
79
-
80
- def new_relic_service
81
- NewRelic::Agent.instance.service
82
- end
83
-
84
- # These are unsynchonized and should only be used for testing
85
- def_delegators :@sessions, :[], :include?
86
-
87
- def active_thread_profiling_sessions
88
- @sessions_lock.synchronize do
89
- @sessions.values.select { |s| s.active? && s.run_profiler? }
90
- end
91
- end
92
-
93
- ### Session activation
94
-
95
- def activate_sessions(incoming_ids)
96
- lookup_metadata_for(ids_to_activate(incoming_ids)).each do |raw|
97
- add_session(XraySession.new(raw))
98
- end
99
- end
100
-
101
- def ids_to_activate(incoming_ids)
102
- @sessions_lock.synchronize { incoming_ids - @sessions.keys }
103
- end
104
-
105
- # Please don't hold the @sessions_lock across me! Calling the service
106
- # is time-consuming, and will block request threads. Which is rude.
107
- def lookup_metadata_for(ids_to_activate)
108
- return [] if ids_to_activate.empty?
109
-
110
- NewRelic::Agent.logger.debug("Retrieving metadata for X-Ray sessions #{ids_to_activate.inspect}")
111
- new_relic_service.get_xray_metadata(ids_to_activate)
112
- end
113
-
114
- def add_session(session)
115
- NewRelic::Agent.logger.debug("Adding X-Ray session #{session.inspect}")
116
- NewRelic::Agent.increment_metric("Supportability/XraySessions/Starts")
117
-
118
- @sessions_lock.synchronize { @sessions[session.id] = session }
119
-
120
- session.activate
121
- if session.run_profiler?
122
- @backtrace_service.subscribe(session.key_transaction_name, session.command_arguments)
123
- end
124
- end
125
-
126
- ### Session deactivation
127
-
128
- def deactivate_for_incoming_sessions(incoming_ids)
129
- ids_to_remove(incoming_ids).each do |session_id|
130
- remove_session_by_id(session_id)
131
- end
132
- end
133
-
134
- def ids_to_remove(incoming_ids)
135
- @sessions_lock.synchronize { @sessions.keys - incoming_ids }
136
- end
137
-
138
- def remove_session_by_id(id)
139
- session = @sessions_lock.synchronize { @sessions.delete(id) }
140
-
141
- if session
142
- NewRelic::Agent.logger.debug("Removing X-Ray session #{session.inspect}")
143
- NewRelic::Agent.increment_metric("Supportability/XraySessions/Stops")
144
-
145
- if session.run_profiler?
146
- @backtrace_service.unsubscribe(session.key_transaction_name)
147
- end
148
- session.deactivate
149
- end
150
- end
151
-
152
- def finished_session_ids
153
- @sessions_lock.synchronize do
154
- @sessions.map{|k, s| k if s.finished?}.compact
155
- end
156
- end
157
-
158
- end
159
- end
160
- end
161
- end