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 +4 -4
- data/lib/rails_autoscale_agent/autoscale_api.rb +4 -0
- data/lib/rails_autoscale_agent/reporter.rb +1 -1
- data/lib/rails_autoscale_agent/request.rb +12 -10
- data/lib/rails_autoscale_agent/version.rb +1 -1
- data/lib/rails_autoscale_agent/worker_adapters/delayed_job.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 998351ab2e804fc443d63825d3a71255d6539f225ef791a4819391d735d29e51
|
4
|
+
data.tar.gz: 83df02c312d3fd2a1504c782b699c6ac5e26444145ff885ecff808ebf2a9cfc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
32
|
-
|
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
|
-
|
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
|
@@ -28,7 +28,8 @@ module RailsAutoscaleAgent
|
|
28
28
|
log_msg = String.new
|
29
29
|
t = Time.now
|
30
30
|
|
31
|
-
|
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.
|
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-
|
11
|
+
date: 2020-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|