rails_autoscale_agent 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/rails_autoscale_agent/config.rb +17 -5
- data/lib/rails_autoscale_agent/middleware.rb +3 -4
- data/lib/rails_autoscale_agent/reporter.rb +4 -4
- data/lib/rails_autoscale_agent/request.rb +9 -1
- data/lib/rails_autoscale_agent/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe89dcd1aa0c7e2f91a0d1b28e245fe2069ceea2
|
4
|
+
data.tar.gz: 410d2bda04a6e08b32c346a5772f3d18497e5835
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daa65cd31e4b418a78672b36968a9dc5c9ec99e572f02fea091c22b01e656b5f21fd47b1c400f17edc2c75dbfce942f0847a147d3ebdff1b57a5ae9904cdebd6
|
7
|
+
data.tar.gz: 79205df8bc5d395ce86134af38c21e629a491dd95472bb2b46f7ab3f7448f92a6fd6b491b21d4c1735f423faa328386368ec22a87c306735d38ad8c26a82fb8f
|
data/.gitignore
CHANGED
@@ -1,22 +1,34 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
1
3
|
module RailsAutoscaleAgent
|
2
4
|
class Config
|
3
|
-
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
attr_reader :api_base_url, :dyno, :pid, :fake_mode, :max_request_size
|
8
|
+
attr_accessor :report_interval
|
4
9
|
alias_method :fake_mode?, :fake_mode
|
5
10
|
|
6
|
-
def initialize
|
7
|
-
@api_base_url =
|
11
|
+
def initialize
|
12
|
+
@api_base_url = ENV['RAILS_AUTOSCALE_URL']
|
8
13
|
@pid = Process.pid
|
9
|
-
@
|
14
|
+
@max_request_size = 100_000 # ignore request payloads over 100k since they skew the queue times
|
15
|
+
@report_interval = 60 # this default will be overwritten during Reporter#register!
|
16
|
+
@fake_mode = true if ENV['RAILS_AUTOSCALE_FAKE_MODE'] == 'true'
|
10
17
|
|
11
18
|
if fake_mode?
|
12
19
|
@dyno = 'web.123'
|
13
20
|
else
|
14
|
-
@dyno =
|
21
|
+
@dyno = ENV['DYNO']
|
15
22
|
end
|
16
23
|
end
|
17
24
|
|
18
25
|
def to_s
|
19
26
|
"#{@dyno}##{@pid}"
|
20
27
|
end
|
28
|
+
|
29
|
+
def ignore_large_requests?
|
30
|
+
@max_request_size.present?
|
31
|
+
end
|
32
|
+
|
21
33
|
end
|
22
34
|
end
|
@@ -14,16 +14,15 @@ module RailsAutoscaleAgent
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def call(env)
|
17
|
-
config = Config.new(ENV)
|
18
|
-
|
19
17
|
logger.tagged 'RailsAutoscale' do
|
18
|
+
config = Config.instance
|
20
19
|
request = Request.new(env, config)
|
21
20
|
|
22
|
-
logger.debug "Middleware entered - request_id=#{request.id} path=#{request.path}"
|
21
|
+
logger.debug "Middleware entered - request_id=#{request.id} path=#{request.path} method=#{request.method} request_size=#{request.size}"
|
23
22
|
|
24
23
|
store = Store.instance
|
25
24
|
Reporter.start(config, store)
|
26
|
-
Collector.collect(request, store)
|
25
|
+
Collector.collect(request, store) unless request.ignore?
|
27
26
|
end
|
28
27
|
|
29
28
|
@app.call(env)
|
@@ -21,14 +21,13 @@ module RailsAutoscaleAgent
|
|
21
21
|
|
22
22
|
def start!(config, store)
|
23
23
|
@running = true
|
24
|
-
@report_interval = 60 # this default will be overwritten during #register!
|
25
24
|
|
26
25
|
Thread.new do
|
27
26
|
logger.tagged 'RailsAutoscale' do
|
28
27
|
register!(config)
|
29
28
|
|
30
29
|
loop do
|
31
|
-
sleep
|
30
|
+
sleep config.report_interval
|
32
31
|
|
33
32
|
begin
|
34
33
|
report!(config, store)
|
@@ -73,8 +72,9 @@ module RailsAutoscaleAgent
|
|
73
72
|
|
74
73
|
case result
|
75
74
|
when AutoscaleApi::SuccessResponse
|
76
|
-
|
77
|
-
|
75
|
+
config.report_interval = result.data['report_interval'] if result.data['report_interval']
|
76
|
+
config.max_request_size = result.data['max_request_size'] if result.data['max_request_size']
|
77
|
+
logger.info "Reporter starting, will report every #{config.report_interval} seconds"
|
78
78
|
when AutoscaleApi::FailureResponse
|
79
79
|
logger.error "Reporter failed to register: #{result.failure_message}"
|
80
80
|
end
|
@@ -1,15 +1,23 @@
|
|
1
1
|
module RailsAutoscaleAgent
|
2
2
|
class Request
|
3
|
-
attr_reader :id, :entered_queue_at, :path
|
3
|
+
attr_reader :id, :entered_queue_at, :path, :method, :size
|
4
4
|
|
5
5
|
def initialize(env, config)
|
6
|
+
@config = config
|
6
7
|
@id = env['HTTP_X_REQUEST_ID']
|
7
8
|
@path = env['PATH_INFO']
|
9
|
+
@method = env['REQUEST_METHOD'].downcase
|
10
|
+
@size = env['rack.input'].size
|
8
11
|
@entered_queue_at = if unix_millis = env['HTTP_X_REQUEST_START']
|
9
12
|
Time.at(unix_millis.to_f / 1000)
|
10
13
|
elsif config.fake_mode?
|
11
14
|
Time.now - rand(1000) / 1000.0 # 0-1000 ms ago
|
12
15
|
end
|
13
16
|
end
|
17
|
+
|
18
|
+
def ignore?
|
19
|
+
@config.ignore_large_requests? && @size > @config.max_request_size
|
20
|
+
end
|
21
|
+
|
14
22
|
end
|
15
23
|
end
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam McCrea
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|