scout_apm 2.1.17 → 2.1.18

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: 66a4cffa0669e1689fd354ca6cc1334917268580
4
- data.tar.gz: 07b7b35f971caaecce344a6a637a945df0c8523a
3
+ metadata.gz: c9fe21cd99b734190fb03448350e744c3b830b15
4
+ data.tar.gz: a3a2160d835f28ee99715887653540d5afc35326
5
5
  SHA512:
6
- metadata.gz: 4c3f3e587c1b98fd7c679b9a40fa79970c38085dda00c7524021c1caa5d51e174ada700ee2f8401292b3497b52af99e600e8cefc2e6d88e26128791e4c06dc9f
7
- data.tar.gz: 1d36607a77b765fe849e7a554db6811d3e6db22e6460862141d1ffd83d6faa20bb44fff08c52894ce2ae71fbe5ff9cbd803dc5b69138fdee62f836e6b0a0a09a
6
+ metadata.gz: bd2c9581ae948f73cf05f2f860971dcea15bc60e5702bca3da74cdcf4977d248cbd2c85174ef4ab7d22f979bfd036f506a4c00286c588f135ce3dac8f4bf57ce
7
+ data.tar.gz: 864122b7668d62d6a65b80127e70d1f87852a09b1afc5a0f8b522704b99701be4b11f57777e93b7ed18d4a3b1f5226a8362f9a63ca388fc085fdbd5ee819e197
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ # 2.1.18
2
+
3
+ * Max layaway file threshold limit
4
+
1
5
  # 2.1.17
2
6
 
3
7
  * Additional logging around file system usage
data/lib/scout_apm.rb CHANGED
@@ -126,7 +126,6 @@ require 'scout_apm/slow_job_policy'
126
126
  require 'scout_apm/job_record'
127
127
  require 'scout_apm/request_histograms'
128
128
 
129
- require 'scout_apm/capacity'
130
129
  require 'scout_apm/attribute_arranger'
131
130
  require 'scout_apm/git_revision'
132
131
 
@@ -12,7 +12,6 @@ module ScoutApm
12
12
  attr_accessor :store
13
13
  attr_accessor :layaway
14
14
  attr_accessor :config
15
- attr_accessor :capacity
16
15
  attr_accessor :logger
17
16
  attr_accessor :log_file # path to the log file
18
17
  attr_accessor :options # options passed to the agent when +#start+ is called.
@@ -58,7 +57,6 @@ module ScoutApm
58
57
  @layaway = ScoutApm::Layaway.new(config, environment)
59
58
  @metric_lookup = Hash.new
60
59
 
61
- @capacity = ScoutApm::Capacity.new
62
60
  @installed_instruments = []
63
61
  end
64
62
 
@@ -11,6 +11,9 @@ module ScoutApm
11
11
  # Letting it sit a bit may be useful for debugging
12
12
  STALE_AGE = 10 * 60
13
13
 
14
+ # Failsafe to prevent writing layaway files if for some reason they are not being cleaned up
15
+ MAX_FILES_LIMIT = 5000
16
+
14
17
  # A strftime format string for how we render timestamps in filenames.
15
18
  # Must be sortable as an integer
16
19
  TIME_FORMAT = "%Y%m%d%H%M"
@@ -45,7 +48,11 @@ module ScoutApm
45
48
  @directory = Pathname.new(found)
46
49
  end
47
50
 
48
- def write_reporting_period(reporting_period)
51
+ def write_reporting_period(reporting_period, files_limit = MAX_FILES_LIMIT)
52
+ if at_layaway_file_limit?(files_limit)
53
+ ScoutApm::Agent.instance.logger.error("Hit layaway file limit. Not writing to layaway file")
54
+ return false
55
+ end
49
56
  filename = file_for(reporting_period.timestamp)
50
57
  layaway_file = LayawayFile.new(filename)
51
58
  layaway_file.write(reporting_period)
@@ -170,6 +177,10 @@ module ScoutApm
170
177
  end
171
178
  end
172
179
 
180
+ def at_layaway_file_limit?(files_limit = MAX_FILES_LIMIT)
181
+ all_files_for(:all).count >= files_limit
182
+ end
183
+
173
184
  def log_layaway_file_information
174
185
  files_in_temp = Dir["#{directory}/*"].count
175
186
 
@@ -1,6 +1,8 @@
1
1
  module ScoutApm
2
2
  class MetricSet
3
- # We can't aggregate CPU, Memory, Capacity, or Controller, so pass through these metrics directly
3
+ # We can't aggregate a handful of things like samplers (CPU, Memory), or
4
+ # Controller, and Percentiles so pass through these metrics directly
5
+ #
4
6
  # TODO: Figure out a way to not have this duplicate what's in Samplers, and also on server's ingest
5
7
  PASSTHROUGH_METRICS = ["CPU", "Memory", "Instance", "Controller", "SlowTransaction", "Percentile", "Job"]
6
8
 
@@ -1,4 +1,4 @@
1
1
  module ScoutApm
2
- VERSION = "2.1.17"
2
+ VERSION = "2.1.18"
3
3
  end
4
4
 
data/test/test_helper.rb CHANGED
@@ -16,6 +16,14 @@ Kernel.module_eval do
16
16
  def self.const_unset(const)
17
17
  self.instance_eval { remove_const(const) }
18
18
  end
19
+
20
+ def silence_warnings(&block)
21
+ warn_level = $VERBOSE
22
+ $VERBOSE = nil
23
+ result = block.call
24
+ $VERBOSE = warn_level
25
+ result
26
+ end
19
27
  end
20
28
 
21
29
  # A test helper class to create a temporary "configuration" we can control entirely purposes
@@ -21,4 +21,24 @@ class LayawayTest < Minitest::Test
21
21
 
22
22
  assert_equal Pathname.new("/tmp/scout_apm_test/tmp"), ScoutApm::Layaway.new(config, env).directory
23
23
  end
24
+
25
+ def test_layaway_file_limit_prevents_new_writes
26
+ FileUtils.mkdir_p '/tmp/scout_apm_test/layaway_limit'
27
+ config = make_fake_config("data_file" => "/tmp/scout_apm_test/layaway_limit")
28
+ layaway = ScoutApm::Layaway.new(config, ScoutApm::Agent.instance.environment)
29
+ layaway.delete_files_for(:all)
30
+
31
+ current_time = Time.now.utc
32
+ current_rp = ScoutApm::StoreReportingPeriod.new(current_time)
33
+ stale_rp = ScoutApm::StoreReportingPeriod.new(current_time - current_time.sec - 120)
34
+
35
+ # layaway.write_reporting_period returns nil on successful write
36
+ # It should probably be changed to return true or the number of bytes written
37
+ assert_nil layaway.write_reporting_period(stale_rp, 1)
38
+
39
+ # layaway.write_reporting_period returns an explicit false class on failure
40
+ assert layaway.write_reporting_period(current_rp, 1).is_a?(FalseClass)
41
+
42
+ layaway.delete_files_for(:all)
43
+ end
24
44
  end
@@ -20,6 +20,21 @@ class StoreTest < Minitest::Test
20
20
 
21
21
  assert_equal({}, s.reporting_periods)
22
22
  end
23
+
24
+ def test_writing_layaway_removes_stale_timestamps
25
+ current_time = Time.now.utc
26
+ current_rp = ScoutApm::StoreReportingPeriod.new(current_time)
27
+ stale_rp = ScoutApm::StoreReportingPeriod.new(current_time - current_time.sec - 120)
28
+
29
+ s = ScoutApm::Store.new
30
+ ScoutApm::Instruments::Process::ProcessMemory.new(Logger.new(StringIO.new)).metrics(stale_rp.timestamp, s)
31
+ ScoutApm::Instruments::Process::ProcessMemory.new(Logger.new(StringIO.new)).metrics(current_rp.timestamp, s)
32
+ assert_equal 2, s.reporting_periods.size
33
+
34
+ s.write_to_layaway(FakeFailingLayaway.new, true)
35
+
36
+ assert_equal({}, s.reporting_periods)
37
+ end
23
38
  end
24
39
 
25
40
  class StoreReportingPeriodTest < Minitest::Test
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: 2.1.17
4
+ version: 2.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Haynes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-12-13 00:00:00.000000000 Z
12
+ date: 2016-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -142,7 +142,6 @@ files:
142
142
  - lib/scout_apm/background_worker.rb
143
143
  - lib/scout_apm/bucket_name_splitter.rb
144
144
  - lib/scout_apm/call_set.rb
145
- - lib/scout_apm/capacity.rb
146
145
  - lib/scout_apm/config.rb
147
146
  - lib/scout_apm/context.rb
148
147
  - lib/scout_apm/environment.rb
@@ -286,34 +285,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
285
  version: '0'
287
286
  requirements: []
288
287
  rubyforge_project: scout_apm
289
- rubygems_version: 2.5.1
288
+ rubygems_version: 2.2.2
290
289
  signing_key:
291
290
  specification_version: 4
292
291
  summary: Ruby application performance monitoring
293
- test_files:
294
- - test/data/config_test_1.yml
295
- - test/test_helper.rb
296
- - test/unit/agent_test.rb
297
- - test/unit/background_job_integrations/sidekiq_test.rb
298
- - test/unit/config_test.rb
299
- - test/unit/context_test.rb
300
- - test/unit/environment_test.rb
301
- - test/unit/git_revision_test.rb
302
- - test/unit/histogram_test.rb
303
- - test/unit/ignored_uris_test.rb
304
- - test/unit/instruments/active_record_instruments_test.rb
305
- - test/unit/instruments/net_http_test.rb
306
- - test/unit/instruments/percentile_sampler_test.rb
307
- - test/unit/layaway_test.rb
308
- - test/unit/layer_children_set_test.rb
309
- - test/unit/limited_layer_test.rb
310
- - test/unit/metric_set_test.rb
311
- - test/unit/scored_item_set_test.rb
312
- - test/unit/serializers/payload_serializer_test.rb
313
- - test/unit/slow_job_policy_test.rb
314
- - test/unit/slow_request_policy_test.rb
315
- - test/unit/sql_sanitizer_test.rb
316
- - test/unit/store_test.rb
317
- - test/unit/utils/active_record_metric_name_test.rb
318
- - test/unit/utils/backtrace_parser_test.rb
319
- - test/unit/utils/numbers_test.rb
292
+ test_files: []
@@ -1,57 +0,0 @@
1
- # Encapsulates logic for determining capacity utilization of the Ruby processes.
2
- module ScoutApm
3
- class Capacity
4
- attr_reader :processing_start_time, :accumulated_time, :transaction_entry_time
5
-
6
- def initialize
7
- @processing_start_time = Time.now
8
- @lock ||= Mutex.new # the transaction_entry_time could be modified while processing a request or when #process is called.
9
- @accumulated_time = 0.0
10
- end
11
-
12
- # Called when a transaction is traced.
13
- def start_transaction!
14
- @lock.synchronize do
15
- @transaction_entry_time = Time.now
16
- end
17
- end
18
-
19
- # Called when a transaction completes to record its time used.
20
- def finish_transaction!
21
- @lock.synchronize do
22
- if transaction_entry_time
23
- @accumulated_time += (Time.now - transaction_entry_time).to_f
24
- else
25
- ScoutApm::Agent.instance.logger.warn "No transaction entry time. Not recording capacity metrics for transaction."
26
- end
27
- @transaction_entry_time = nil
28
- end
29
- end
30
-
31
- # Ran when sending metrics to server. Reports capacity usage metrics.
32
- def process
33
- process_time = Time.now
34
- ScoutApm::Agent.instance.logger.debug "Processing capacity usage for [#{@processing_start_time}] to [#{process_time}]. Time Spent: #{@accumulated_time}."
35
- @lock.synchronize do
36
- time_spent = @accumulated_time
37
- @accumulated_time = 0.0
38
- # If a transaction is still running, capture its running time up to now and
39
- # reset the +transaction_entry_time+ to now.
40
- if @transaction_entry_time
41
- time_spent += (process_time - @transaction_entry_time).to_f
42
- ScoutApm::Agent.instance.logger.debug "A transaction is running while calculating capacity. Start time: [#{transaction_entry_time}]. Will update the entry time to [#{process_time}]."
43
- @transaction_entry_time = process_time # prevent from over-counting capacity usage. update the transaction start time to now.
44
- end
45
- time_spent = 0.0 if time_spent < 0.0
46
-
47
- window = (process_time - processing_start_time).to_f # time period we are evaulating capacity usage.
48
- window = 1.0 if window <= 0.0 # prevent divide-by-zero if clock adjusted.
49
- capacity = time_spent / window
50
- ScoutApm::Agent.instance.logger.debug "Instance/Capacity: #{capacity}"
51
- ScoutApm::Agent.instance.store.track_one!("Instance", "Capacity", capacity)
52
-
53
- @processing_start_time = process_time
54
- end
55
- end
56
- end
57
- end