scout_apm 3.0.0.pre6 → 3.0.0.pre7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a17bfe8d072cc469eafdaf6f5d9a53e29282ea6a
4
- data.tar.gz: 39707f4cfacb744879297744928c038fe1a1c8aa
3
+ metadata.gz: 622bc9489b9add4f80ca65cd3b12e54e30eea269
4
+ data.tar.gz: ef00b8380eb4e163cf9b991b826287d63ba27819
5
5
  SHA512:
6
- metadata.gz: e9d208abf69daf67b5ca3bf487117e58cd434b445cd43126d9ec6ba90242b2179b1f4913aff3e3d8a38d89c6e0c2940d559059509baab072b7d0aac1899a936f
7
- data.tar.gz: 91e4143528147d48c5eec703002cfd783579e89fca9c48806e0ec9745a57b622f660f9a7acd5186e6fc0ac5aef0c61f3e69bcc8a1bd5e29fd6ed94c5270e90d2
6
+ metadata.gz: 2057aaca2029567dd1a7ce09fb8b359cc2819566e0a03ef528f91b051e00170be7fef66dfe339186bc77d030c7e738be2bc3517b8306e874ce38c662988c46a2
7
+ data.tar.gz: 4e45127ed587dd0e86782d357f1916de915acff6698682f2b6920448ba63245a5412549d27efe7fff1e270b8bfc0e57d36cc7273ae94f1af4f83a348b525b9aa
data/CHANGELOG.markdown CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  * ScoutProf BETA
4
4
 
5
+ # 2.1.18
6
+
7
+ * Max layaway file threshold limit
8
+
9
+
5
10
  # 2.1.17
6
11
 
7
12
  * Additional logging around file system usage
data/lib/scout_apm.rb CHANGED
@@ -134,7 +134,6 @@ require 'scout_apm/slow_job_policy'
134
134
  require 'scout_apm/job_record'
135
135
  require 'scout_apm/request_histograms'
136
136
 
137
- require 'scout_apm/capacity'
138
137
  require 'scout_apm/attribute_arranger'
139
138
  require 'scout_apm/git_revision'
140
139
 
@@ -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,3 +1,3 @@
1
1
  module ScoutApm
2
- VERSION = "3.0.0.pre6"
2
+ VERSION = "3.0.0.pre7"
3
3
  end
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: 3.0.0.pre6
4
+ version: 3.0.0.pre7
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
@@ -146,7 +146,6 @@ files:
146
146
  - lib/scout_apm/background_worker.rb
147
147
  - lib/scout_apm/bucket_name_splitter.rb
148
148
  - lib/scout_apm/call_set.rb
149
- - lib/scout_apm/capacity.rb
150
149
  - lib/scout_apm/config.rb
151
150
  - lib/scout_apm/context.rb
152
151
  - lib/scout_apm/environment.rb
@@ -293,34 +292,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
293
292
  version: 1.3.1
294
293
  requirements: []
295
294
  rubyforge_project: scout_apm
296
- rubygems_version: 2.5.1
295
+ rubygems_version: 2.2.2
297
296
  signing_key:
298
297
  specification_version: 4
299
298
  summary: Ruby application performance monitoring
300
- test_files:
301
- - test/data/config_test_1.yml
302
- - test/test_helper.rb
303
- - test/unit/agent_test.rb
304
- - test/unit/background_job_integrations/sidekiq_test.rb
305
- - test/unit/config_test.rb
306
- - test/unit/context_test.rb
307
- - test/unit/environment_test.rb
308
- - test/unit/git_revision_test.rb
309
- - test/unit/histogram_test.rb
310
- - test/unit/ignored_uris_test.rb
311
- - test/unit/instruments/active_record_instruments_test.rb
312
- - test/unit/instruments/net_http_test.rb
313
- - test/unit/instruments/percentile_sampler_test.rb
314
- - test/unit/layaway_test.rb
315
- - test/unit/layer_children_set_test.rb
316
- - test/unit/limited_layer_test.rb
317
- - test/unit/metric_set_test.rb
318
- - test/unit/scored_item_set_test.rb
319
- - test/unit/serializers/payload_serializer_test.rb
320
- - test/unit/slow_job_policy_test.rb
321
- - test/unit/slow_request_policy_test.rb
322
- - test/unit/sql_sanitizer_test.rb
323
- - test/unit/store_test.rb
324
- - test/unit/utils/active_record_metric_name_test.rb
325
- - test/unit/utils/backtrace_parser_test.rb
326
- - test/unit/utils/numbers_test.rb
299
+ 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