scout_apm 1.2.7 → 1.2.8.pre1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9efb3b04bdfcd19df6d60a358e8b30abe48be29b
4
- data.tar.gz: b53820b59423029619cef843ba6887bbc0f61118
3
+ metadata.gz: 648de873df09b8d7419abd803d9180fb67e1595d
4
+ data.tar.gz: 61cf23bc15c91ba74022f8390348cf4896bfd9d5
5
5
  SHA512:
6
- metadata.gz: 65a5694303ce81df40aa755877732b98fa5e849f51849ab37e96b3ea22ad3bc38f0ed8a29ed2c1c98e6e8107b252aff6d0319f875da25151470758e1a0445789
7
- data.tar.gz: 4222de374831297d9a6bd87b167324b7d5d542086296bb6213f1a53c3c3d2cdfc8521217d98dfca5d546845be97809bd80b37f9b7f93c143100704f2f3864169
6
+ metadata.gz: 8856fc5d888b1a6243b16e2b04d1d4d60f84167d1dea79032e504d6b21f2fb43292df433cb6c5b99454c39fa529529d5f534880b8867d7a3446834228c164366
7
+ data.tar.gz: c7142c814ad6c572381688dea1baf5fdcd6f968bd6d79dff59fb7bfe68fb1e6822abf22d3ff8e0ec8d24e9bc6e1cfca748cb91e7091914ea65fe1cf0897678c1
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,8 @@
1
+ # 1.2.8
2
+
3
+ * Enhance shutdown code to be sure we save current-minute metrics and minimize
4
+ the amount of work necessary.
5
+
1
6
  # 1.2.7
2
7
 
3
8
  * Clarifying that Rails3 instrumentation also supports Rails4
@@ -152,15 +152,21 @@ module ScoutApm
152
152
  end
153
153
  end
154
154
 
155
- # Called via an at_exit handler, it (1) stops the background worker and (2) runs it a final time.
156
- # The final run ensures metrics are stored locally to the layaway / reported to scoutapp.com. Otherwise,
157
- # in-memory metrics would be lost and a gap would appear on restarts.
155
+ # Called via an at_exit handler, it:
156
+ # (1) Stops the background worker
157
+ # (2) Stores metrics locally (forcing current-minute metrics to be written)
158
+ # It does not attempt to actually report metrics.
158
159
  def shutdown
160
+ logger.info "Shutting down ScoutApm"
159
161
  return if !started?
160
162
  if @background_worker
161
163
  @background_worker.stop
162
- @background_worker.run_once
164
+ store.write_to_layaway(layaway, :force)
163
165
  end
166
+
167
+ # Make sure we don't exit the process while the background worker is running its task.
168
+ logger.debug "Joining background worker thread"
169
+ @background_worker_thread.join if @background_worker_thread
164
170
  end
165
171
 
166
172
  def started?
@@ -23,20 +23,33 @@ module ScoutApm
23
23
  # Starts running the passed block every 60 seconds (starting now).
24
24
  def start(&block)
25
25
  @task = block
26
+
26
27
  begin
27
28
  ScoutApm::Agent.instance.logger.debug "Starting Background Worker, running every #{period} seconds"
28
- next_time = Time.now
29
- while @keep_running do
29
+
30
+ # The first run should be 1 period of time from now
31
+ next_time = Time.now + period
32
+
33
+ loop do
30
34
  now = Time.now
35
+
36
+ # Sleep the correct amount of time to reach next_time
31
37
  while now < next_time
32
38
  sleep_time = next_time - now
33
39
  sleep(sleep_time) if sleep_time > 0
34
40
  now = Time.now
35
41
  end
42
+
43
+ # Bail out if @keep_running is false
44
+ break unless @keep_running
45
+
36
46
  @task.call
47
+
48
+ # Adjust the next time to run forward by @periods until it is in the future
37
49
  while next_time <= now
38
50
  next_time += period
39
51
  end
52
+
40
53
  end
41
54
  rescue
42
55
  ScoutApm::Agent.instance.logger.debug "Background Worker Exception!"
@@ -11,9 +11,18 @@ module ScoutApm
11
11
  def add_reporting_period(time, reporting_period)
12
12
  file.read_and_write do |existing_data|
13
13
  existing_data ||= Hash.new
14
- existing_data.merge(time => reporting_period) {|key, old_val, new_val|
14
+ ScoutApm::Agent.instance.logger.debug("AddReportingPeriod: Adding a reporting_period with timestamp: #{reporting_period.timestamp.to_s}, and #{reporting_period.request_count} requests")
15
+
16
+ existing_data = existing_data.merge(time => reporting_period) {|key, old_val, new_val|
17
+ old_req = old_val.request_count
18
+ new_req = new_val.request_count
19
+ ScoutApm::Agent.instance.logger.debug("Merging Two reporting periods (#{old_val.timestamp.to_s}, #{new_val.timestamp.to_s}): old req #{old_req}, new req #{new_req}")
20
+
15
21
  old_val.merge_metrics!(new_val.metrics_payload).merge_slow_transactions!(new_val.slow_transactions)
16
22
  }
23
+
24
+ ScoutApm::Agent.instance.logger.debug("AddReportingPeriod: AfterMerge Timestamps: #{existing_data.keys.map(&:to_s).inspect}")
25
+ existing_data
17
26
  end
18
27
  end
19
28
 
@@ -24,6 +33,9 @@ module ScoutApm
24
33
  ready_for_delivery = []
25
34
  file.read_and_write do |existing_data|
26
35
  existing_data ||= {}
36
+
37
+ ScoutApm::Agent.instance.logger.debug("PeriodsReadyForDeliver: All Timestamps: #{existing_data.keys.map(&:to_s).inspect}")
38
+
27
39
  ready_for_delivery = existing_data.to_a.select {|time, rp| should_send?(rp) } # Select off the values we want. to_a is needed for compatibility with Ruby 1.8.7.
28
40
 
29
41
  # Rewrite anything not plucked out back to the file
@@ -38,14 +38,21 @@ module ScoutApm
38
38
  end
39
39
 
40
40
  # Take each completed reporting_period, and write it to the layaway passed
41
- def write_to_layaway(layaway)
41
+ #
42
+ # force - a boolean argument that forces this function to write
43
+ # current-minute metrics. Useful when we are shutting down the agent
44
+ # during a restart.
45
+ def write_to_layaway(layaway, force=false)
46
+ ScoutApm::Agent.instance.logger.debug("Writing to layaway#{" (Forced)" if force}")
47
+
42
48
  @mutex.synchronize {
43
- reporting_periods.select { |time, rp| time.timestamp < current_timestamp.timestamp}.
49
+ reporting_periods.select { |time, rp| force || time.timestamp < current_timestamp.timestamp}.
44
50
  each { |time, rp|
45
51
  layaway.add_reporting_period(time, rp)
46
52
  reporting_periods.delete(time)
47
53
  }
48
54
  }
55
+ ScoutApm::Agent.instance.logger.debug("Finished writing to layaway")
49
56
  end
50
57
  end
51
58
 
@@ -60,7 +67,7 @@ module ScoutApm
60
67
  end
61
68
 
62
69
  def to_s
63
- @raw_time.iso8601
70
+ Time.at(@timestamp).iso8601
64
71
  end
65
72
 
66
73
  def eql?(o)
@@ -123,6 +130,16 @@ module ScoutApm
123
130
  @slow_transactions.to_a
124
131
  end
125
132
 
133
+ #################################
134
+ # Debug Helpers
135
+ #################################
136
+
137
+ def request_count
138
+ metrics_payload.
139
+ select { |meta,stats| meta.metric_name =~ /\AController/ }.
140
+ inject(0) {|sum, (_, stat)| sum + stat.call_count }
141
+ end
142
+
126
143
  private
127
144
 
128
145
  # Removes payloads from slow transactions that exceed +SlowRequestPolicy::MAX_DETAIL_PER_MINUTE+ to avoid
@@ -139,6 +139,8 @@ module ScoutApm
139
139
 
140
140
  queue_time_metrics = RequestQueueTime.new(self).call
141
141
  ScoutApm::Agent.instance.store.track!(queue_time_metrics)
142
+
143
+ # ScoutApm::Agent.instance.logger.debug("Finished recording request") if metrics.any?
142
144
  end
143
145
 
144
146
  # Have we already persisted this request?
@@ -1,4 +1,4 @@
1
1
  module ScoutApm
2
- VERSION = "1.2.7"
2
+ VERSION = "1.2.8.pre1"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout_apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.2.8.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Haynes
@@ -170,12 +170,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
170
  version: '0'
171
171
  required_rubygems_version: !ruby/object:Gem::Requirement
172
172
  requirements:
173
- - - ">="
173
+ - - ">"
174
174
  - !ruby/object:Gem::Version
175
- version: '0'
175
+ version: 1.3.1
176
176
  requirements: []
177
177
  rubyforge_project: scout_apm
178
- rubygems_version: 2.4.8
178
+ rubygems_version: 2.2.2
179
179
  signing_key:
180
180
  specification_version: 4
181
181
  summary: Ruby application performance monitoring