rails_autoscale_agent 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -0
- data/.travis.yml +1 -3
- data/README.md +15 -1
- data/Rakefile +2 -0
- data/lib/rails_autoscale_agent.rb +2 -0
- data/lib/rails_autoscale_agent/autoscale_api.rb +2 -0
- data/lib/rails_autoscale_agent/config.rb +7 -11
- data/lib/rails_autoscale_agent/logger.rb +3 -1
- data/lib/rails_autoscale_agent/measurement.rb +2 -0
- data/lib/rails_autoscale_agent/middleware.rb +8 -2
- data/lib/rails_autoscale_agent/railtie.rb +2 -0
- data/lib/rails_autoscale_agent/registration.rb +3 -1
- data/lib/rails_autoscale_agent/report.rb +5 -3
- data/lib/rails_autoscale_agent/reporter.rb +2 -0
- data/lib/rails_autoscale_agent/request.rb +22 -5
- data/lib/rails_autoscale_agent/store.rb +2 -0
- data/lib/rails_autoscale_agent/time_rounder.rb +2 -0
- data/lib/rails_autoscale_agent/version.rb +3 -1
- data/log/.gitkeep +0 -0
- metadata +5 -4
- data/lib/rails_autoscale_agent/collector.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 835d9318705ae0bab9644578e6e39f6b29dd9c36d50671cf8651e44bfcfe2af5
|
4
|
+
data.tar.gz: c205493eb704e12e8d7da388de903e9391dfa328636118021ff5f4ca4173b127
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fe642672aa559193cd48ca32ade1acdabc3c176d8a9435b4964bb0db86752fdd2aae9ed1698d75570c015b44a87d0b6dd895925cadc831a2f4628f4c9a5efe8
|
7
|
+
data.tar.gz: f55a4a48fe981add95eb0ad497bc7d389841e0d2c9254a63b4378284f2bd14ae364b0b3a5e468783b23f453d31c34e84f716f1d27fbde56ec8c3c7f8a4d4d1c4
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.0
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Rails Autoscale Agent
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/adamlogic/rails_autoscale_agent.svg?branch=master)](https://travis-ci.org/adamlogic/rails_autoscale_agent)
|
4
|
+
|
3
5
|
This gem works together with the Rails Autoscale Heroku add-on
|
4
6
|
to automatically scale your web dynos as needed.
|
5
7
|
It gathers a minimal set of metrics for each request,
|
@@ -24,6 +26,19 @@ which happens automatically when you install the Heroku add-on.
|
|
24
26
|
In development (or anytime the ENV var is missing), the middleware will still produce
|
25
27
|
`INFO`-level log output to your Rails log.
|
26
28
|
|
29
|
+
## Non-Rails Rack apps
|
30
|
+
|
31
|
+
You'll need to insert the `RailsAutoscaleAgent::Middleware` manually. Insert it
|
32
|
+
before `Rack::Runtime` to ensure accuracy of request queue timings.
|
33
|
+
|
34
|
+
## Changing the logger
|
35
|
+
|
36
|
+
If you wish to use a different logger you can set it on the configuration object:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
RailsAutoscaleAgent::Config.instance.logger = MyLogger.new
|
40
|
+
```
|
41
|
+
|
27
42
|
## Development
|
28
43
|
|
29
44
|
After checking out the repo, run `bin/setup` to install dependencies.
|
@@ -42,4 +57,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/adamlo
|
|
42
57
|
## License
|
43
58
|
|
44
59
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
45
|
-
|
data/Rakefile
CHANGED
@@ -1,25 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'singleton'
|
2
4
|
|
3
5
|
module RailsAutoscaleAgent
|
4
6
|
class Config
|
5
7
|
include Singleton
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
alias_method :fake_mode?, :fake_mode
|
9
|
+
attr_accessor :report_interval, :logger, :api_base_url, :max_request_size,
|
10
|
+
:dyno, :pid
|
10
11
|
|
11
12
|
def initialize
|
12
13
|
@api_base_url = ENV['RAILS_AUTOSCALE_URL']
|
13
14
|
@pid = Process.pid
|
14
15
|
@max_request_size = 100_000 # ignore request payloads over 100k since they skew the queue times
|
15
16
|
@report_interval = 60 # this default will be overwritten during Reporter#register!
|
16
|
-
@
|
17
|
-
|
18
|
-
if fake_mode?
|
19
|
-
@dyno = 'web.123'
|
20
|
-
else
|
21
|
-
@dyno = ENV['DYNO']
|
22
|
-
end
|
17
|
+
@logger ||= defined?(Rails) ? Rails.logger : ::Logger.new(STDOUT)
|
18
|
+
@dyno = ENV['DYNO']
|
23
19
|
end
|
24
20
|
|
25
21
|
def to_s
|
@@ -27,7 +23,7 @@ module RailsAutoscaleAgent
|
|
27
23
|
end
|
28
24
|
|
29
25
|
def ignore_large_requests?
|
30
|
-
@max_request_size
|
26
|
+
@max_request_size
|
31
27
|
end
|
32
28
|
|
33
29
|
end
|
@@ -1,6 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails_autoscale_agent/logger'
|
2
4
|
require 'rails_autoscale_agent/store'
|
3
|
-
require 'rails_autoscale_agent/collector'
|
4
5
|
require 'rails_autoscale_agent/reporter'
|
5
6
|
require 'rails_autoscale_agent/config'
|
6
7
|
require 'rails_autoscale_agent/request'
|
@@ -22,7 +23,12 @@ module RailsAutoscaleAgent
|
|
22
23
|
|
23
24
|
store = Store.instance
|
24
25
|
Reporter.start(config, store)
|
25
|
-
|
26
|
+
|
27
|
+
if !request.ignore? && queue_time = request.queue_time
|
28
|
+
# NOTE: Expose queue time to the app
|
29
|
+
env['queue_time'] = queue_time
|
30
|
+
store.push queue_time
|
31
|
+
end
|
26
32
|
end
|
27
33
|
|
28
34
|
@app.call(env)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails_autoscale_agent/version'
|
2
4
|
|
3
5
|
module RailsAutoscaleAgent
|
@@ -8,7 +10,7 @@ module RailsAutoscaleAgent
|
|
8
10
|
dyno: config.dyno,
|
9
11
|
pid: config.pid,
|
10
12
|
ruby_version: RUBY_VERSION,
|
11
|
-
rails_version: Rails.version,
|
13
|
+
rails_version: defined?(Rails) && Rails.version,
|
12
14
|
gem_version: VERSION,
|
13
15
|
}
|
14
16
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RailsAutoscaleAgent
|
2
4
|
class Report
|
3
5
|
|
@@ -15,12 +17,12 @@ module RailsAutoscaleAgent
|
|
15
17
|
end
|
16
18
|
|
17
19
|
def to_csv
|
18
|
-
|
20
|
+
String.new.tap do |result|
|
19
21
|
@measurements.each do |measurement|
|
20
22
|
result << measurement.time.to_i.to_s
|
21
|
-
result << ','
|
23
|
+
result << ','
|
22
24
|
result << measurement.value.to_s
|
23
|
-
result << "\n"
|
25
|
+
result << "\n"
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
@@ -1,5 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RailsAutoscaleAgent
|
2
4
|
class Request
|
5
|
+
include Logger
|
6
|
+
|
3
7
|
attr_reader :id, :entered_queue_at, :path, :method, :size
|
4
8
|
|
5
9
|
def initialize(env, config)
|
@@ -8,16 +12,29 @@ module RailsAutoscaleAgent
|
|
8
12
|
@path = env['PATH_INFO']
|
9
13
|
@method = env['REQUEST_METHOD'].downcase
|
10
14
|
@size = env['rack.input'].respond_to?(:size) ? env['rack.input'].size : 0
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
15
|
+
|
16
|
+
if unix_millis = env['HTTP_X_REQUEST_START']
|
17
|
+
@entered_queue_at = Time.at(unix_millis.to_f / 1000)
|
18
|
+
end
|
16
19
|
end
|
17
20
|
|
18
21
|
def ignore?
|
19
22
|
@config.ignore_large_requests? && @size > @config.max_request_size
|
20
23
|
end
|
21
24
|
|
25
|
+
def queue_time
|
26
|
+
if entered_queue_at
|
27
|
+
if entered_queue_at < (Time.now - 60 * 10)
|
28
|
+
# ignore unreasonable values
|
29
|
+
logger.info "request queued for more than 10 minutes... skipping collection"
|
30
|
+
else
|
31
|
+
queue_time = ((Time.now - entered_queue_at) * 1000).to_i
|
32
|
+
queue_time = 0 if queue_time < 0
|
33
|
+
logger.info "Collected queue_time=#{queue_time}ms request_id=#{id} request_size=#{size}"
|
34
|
+
|
35
|
+
queue_time
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
22
39
|
end
|
23
40
|
end
|
data/log/.gitkeep
ADDED
File without changes
|
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.4.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:
|
11
|
+
date: 2018-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -131,6 +131,7 @@ extra_rdoc_files: []
|
|
131
131
|
files:
|
132
132
|
- ".gitignore"
|
133
133
|
- ".rspec"
|
134
|
+
- ".ruby-version"
|
134
135
|
- ".travis.yml"
|
135
136
|
- Gemfile
|
136
137
|
- LICENSE.txt
|
@@ -140,7 +141,6 @@ files:
|
|
140
141
|
- bin/setup
|
141
142
|
- lib/rails_autoscale_agent.rb
|
142
143
|
- lib/rails_autoscale_agent/autoscale_api.rb
|
143
|
-
- lib/rails_autoscale_agent/collector.rb
|
144
144
|
- lib/rails_autoscale_agent/config.rb
|
145
145
|
- lib/rails_autoscale_agent/logger.rb
|
146
146
|
- lib/rails_autoscale_agent/measurement.rb
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- lib/rails_autoscale_agent/store.rb
|
154
154
|
- lib/rails_autoscale_agent/time_rounder.rb
|
155
155
|
- lib/rails_autoscale_agent/version.rb
|
156
|
+
- log/.gitkeep
|
156
157
|
- rails_autoscale_agent.gemspec
|
157
158
|
homepage: https://github.com/adamlogic/rails_autoscale_agent
|
158
159
|
licenses:
|
@@ -174,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
175
|
version: '0'
|
175
176
|
requirements: []
|
176
177
|
rubyforge_project:
|
177
|
-
rubygems_version: 2.
|
178
|
+
rubygems_version: 2.7.3
|
178
179
|
signing_key:
|
179
180
|
specification_version: 4
|
180
181
|
summary: This gem works with the Rails Autoscale Heroku add-on to automatically scale
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'rails_autoscale_agent/logger'
|
2
|
-
|
3
|
-
module RailsAutoscaleAgent
|
4
|
-
class Collector
|
5
|
-
extend Logger
|
6
|
-
|
7
|
-
def self.collect(request, store)
|
8
|
-
if request.entered_queue_at
|
9
|
-
if request.entered_queue_at < (Time.now - 60 * 10)
|
10
|
-
# ignore unreasonable values
|
11
|
-
logger.info "request queued for more than 10 minutes... skipping collection"
|
12
|
-
else
|
13
|
-
queue_time_millis = ((Time.now - request.entered_queue_at) * 1000).to_i
|
14
|
-
queue_time_millis = 0 if queue_time_millis < 0
|
15
|
-
store.push(queue_time_millis)
|
16
|
-
logger.info "Collected queue_time=#{queue_time_millis}ms request_id=#{request.id}"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|