rails_autoscale_agent 0.9.0.beta.1 → 0.9.0.beta.2

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
  SHA256:
3
- metadata.gz: 37ecb709c866b3d831f79d8a15bd54cfcacfd00dc45ebf84ad5129c0d1206a3d
4
- data.tar.gz: 373474c8d84bb5cbd026f792aef4eef4028d77b666d74ac4407cd7d4c603703d
3
+ metadata.gz: 998351ab2e804fc443d63825d3a71255d6539f225ef791a4819391d735d29e51
4
+ data.tar.gz: 83df02c312d3fd2a1504c782b699c6ac5e26444145ff885ecff808ebf2a9cfc3
5
5
  SHA512:
6
- metadata.gz: cbe7b97077c907d45deba6cfa0dce814e8d5fff2339cdf8c81c7e96101d0e3cd8a1dcbcdd3474bcb8fe798ec7591f59b040a8e40d367fa11b32c4dbd6ead52f1
7
- data.tar.gz: 2677393fb16bb0fb776c2325838074ed3c0c9c4d990d296e950ad83576456ac66b15765a96e84a1fefe26ff6696ca89e419e23db78a644e01054378c7dbf3cd1
6
+ metadata.gz: 6a34893873a4fc6b926e93d89002b3527f8adce615f97d1694753995df89666cfea3c37f55d435011edbe3e6c39928f835d7594c79cd310feb2267bfc1bbb1fa
7
+ data.tar.gz: 00b6943d706c93e1d93dc01259d6982618083b0d7359b212eb0187c26edac6f979a11c0c7a387671d60f80a6eb1ef13e74f5182b9f92b814dc01cd9d0f8c5b6b
@@ -24,6 +24,10 @@ module RailsAutoscaleAgent
24
24
  post_json '/registrations', registration: registration_params
25
25
  end
26
26
 
27
+ def report_exception!(ex)
28
+ post_json '/exceptions', message: ex.inspect, backtrace: ex.backtrace.join("\n")
29
+ end
30
+
27
31
  private
28
32
 
29
33
  def post_json(path, data)
@@ -41,7 +41,7 @@ module RailsAutoscaleAgent
41
41
  # Exceptions in threads other than the main thread will fail silently
42
42
  # https://ruby-doc.org/core-2.2.0/Thread.html#class-Thread-label-Exception+handling
43
43
  logger.error "Reporter error: #{ex.inspect}"
44
- logger.error ex.backtrace.join("\n")
44
+ AutoscaleApi.new(config.api_base_url).report_exception!(ex)
45
45
  end
46
46
  end
47
47
  end
@@ -4,20 +4,17 @@ module RailsAutoscaleAgent
4
4
  class Request
5
5
  include Logger
6
6
 
7
- attr_reader :id, :entered_queue_at, :path, :method, :size
8
-
9
7
  def initialize(env, config)
10
8
  @config = config
11
9
  @id = env['HTTP_X_REQUEST_ID']
12
- @path = env['PATH_INFO']
13
- @method = env['REQUEST_METHOD'].downcase
14
10
  @size = env['rack.input'].respond_to?(:size) ? env['rack.input'].size : 0
11
+ @request_body_wait = env['puma.request_body_wait'].to_i
15
12
 
16
13
  @entered_queue_at = if unix_millis = env['HTTP_X_REQUEST_START']
17
14
  Time.at(unix_millis.to_f / 1000)
18
15
  elsif config.dev_mode?
19
16
  # In dev mode, fake a queue time of 0-1000ms
20
- Time.now - rand
17
+ Time.now - rand + @request_body_wait
21
18
  end
22
19
  end
23
20
 
@@ -26,12 +23,17 @@ module RailsAutoscaleAgent
26
23
  end
27
24
 
28
25
  def queue_time
29
- if entered_queue_at
30
- queue_time = ((Time.now - entered_queue_at) * 1000).to_i
31
- queue_time = 0 if queue_time < 0
32
- logger.debug "Collected queue_time=#{queue_time}ms request_id=#{id} request_size=#{size}"
26
+ if @entered_queue_at
27
+ queue_time = ((Time.now - @entered_queue_at) * 1000).to_i
28
+
29
+ # Subtract the time Puma spent waiting on the request body. It's irrelevant to capacity-related queue time.
30
+ # Without this, slow clients and large request payloads will skew queue time.
31
+ queue_time -= @request_body_wait
32
+
33
+ logger.debug "Request queue_time=#{queue_time}ms body_wait=#{@request_body_wait}ms request_id=#{@id} size=#{@size}"
33
34
 
34
- queue_time
35
+ # Safeguard against negative queue times (should not happen in practice)
36
+ queue_time > 0 ? queue_time : 0
35
37
  end
36
38
  end
37
39
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsAutoscaleAgent
4
- VERSION = "0.9.0.beta.1"
4
+ VERSION = "0.9.0.beta.2"
5
5
  end
@@ -28,7 +28,8 @@ module RailsAutoscaleAgent
28
28
  log_msg = String.new
29
29
  t = Time.now
30
30
 
31
- sql = 'SELECT queue, min(run_at) FROM delayed_jobs GROUP BY queue'
31
+ # Ignore failed jobs (they skew latency measurement due to the original run_at)
32
+ sql = 'SELECT queue, min(run_at) FROM delayed_jobs WHERE attempts = 0 GROUP BY queue'
32
33
  run_at_by_queue = Hash[ActiveRecord::Base.connection.select_rows(sql)]
33
34
  queues = self.class.queues | run_at_by_queue.keys
34
35
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_autoscale_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0.beta.1
4
+ version: 0.9.0.beta.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam McCrea
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-20 00:00:00.000000000 Z
11
+ date: 2020-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler