rails_autoscale_agent 0.7.0 → 0.10.2
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 +4 -4
- data/.vscode/tasks.json +85 -0
- data/CHANGELOG.md +115 -0
- data/Gemfile +13 -1
- data/README.md +65 -17
- data/lib/rails_autoscale_agent/autoscale_api.rb +13 -4
- data/lib/rails_autoscale_agent/config.rb +29 -8
- data/lib/rails_autoscale_agent/logger.rb +28 -14
- data/lib/rails_autoscale_agent/measurement.rb +5 -3
- data/lib/rails_autoscale_agent/middleware.rb +8 -13
- data/lib/rails_autoscale_agent/railtie.rb +4 -0
- data/lib/rails_autoscale_agent/registration.rb +4 -2
- data/lib/rails_autoscale_agent/report.rb +7 -9
- data/lib/rails_autoscale_agent/reporter.rb +37 -23
- data/lib/rails_autoscale_agent/request.rb +29 -15
- data/lib/rails_autoscale_agent/store.rb +7 -2
- data/lib/rails_autoscale_agent/version.rb +1 -1
- data/lib/rails_autoscale_agent/worker_adapters/delayed_job.rb +97 -0
- data/lib/rails_autoscale_agent/worker_adapters/que.rb +71 -0
- data/lib/rails_autoscale_agent/worker_adapters/resque.rb +50 -0
- data/lib/rails_autoscale_agent/worker_adapters/sidekiq.rb +69 -18
- data/rails_autoscale_agent.gemspec +1 -10
- metadata +14 -135
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd7549c359dd5f45dbd5d44113c04413685c0cabc12836c1a88559404104ea8b
|
4
|
+
data.tar.gz: b193f06500d2d281e22b2684364e2aad7107dcd1713f8e30d98f2cc3a814a99f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ecc593e4d6a404bbeb0d082047c87511e5be55daa77169a4159f0a96c8bc1bd7c5b78e09e712ec90119e0198c615849331de9b8ff1fd48e3f2ecf631e8395a5
|
7
|
+
data.tar.gz: b4802270f5a2ac21f5c8fee31c200dcd2fee5b8771591a3b9c9eb21b1a716ec59e56e24e958afbbc8ea5aa49670e0bf62dc64ad8d3670f8cb4ff7126afaf6f4f
|
data/.vscode/tasks.json
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
{
|
2
|
+
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
3
|
+
// for the documentation about the tasks.json format
|
4
|
+
"version": "2.0.0",
|
5
|
+
"tasks": [
|
6
|
+
{
|
7
|
+
"label": "test: all",
|
8
|
+
"group": "test",
|
9
|
+
"command": "bundle",
|
10
|
+
"args": ["exec", "rspec"],
|
11
|
+
"runOptions": {
|
12
|
+
"reevaluateOnRerun": false
|
13
|
+
},
|
14
|
+
"problemMatcher": {
|
15
|
+
"owner": "ruby",
|
16
|
+
"fileLocation": ["relative", "${workspaceRoot}"],
|
17
|
+
"severity": "error",
|
18
|
+
"pattern": [
|
19
|
+
{
|
20
|
+
"regexp": "^\\s{7}(.*)$",
|
21
|
+
"message": 1
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"regexp": "^\\s+#\\s(\\./.*):(\\d+):(in.*)$",
|
25
|
+
"file": 1,
|
26
|
+
"line": 2,
|
27
|
+
"code": 3
|
28
|
+
}
|
29
|
+
]
|
30
|
+
}
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"label": "test: file",
|
34
|
+
"group": "test",
|
35
|
+
"command": "bundle",
|
36
|
+
"args": ["exec", "rspec", "${relativeFile}"],
|
37
|
+
"runOptions": {
|
38
|
+
"reevaluateOnRerun": false
|
39
|
+
},
|
40
|
+
"problemMatcher": {
|
41
|
+
"owner": "ruby",
|
42
|
+
"fileLocation": ["relative", "${workspaceRoot}"],
|
43
|
+
"severity": "error",
|
44
|
+
"pattern": [
|
45
|
+
{
|
46
|
+
"regexp": "^\\s{7}(.*)$",
|
47
|
+
"message": 1
|
48
|
+
},
|
49
|
+
{
|
50
|
+
"regexp": "^\\s+#\\s(\\./.*):(\\d+):(in.*)$",
|
51
|
+
"file": 1,
|
52
|
+
"line": 2,
|
53
|
+
"code": 3
|
54
|
+
}
|
55
|
+
]
|
56
|
+
}
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"label": "test: line",
|
60
|
+
"group": "test",
|
61
|
+
"command": "bundle",
|
62
|
+
"args": ["exec", "rspec", "${relativeFile}:${lineNumber}"],
|
63
|
+
"runOptions": {
|
64
|
+
"reevaluateOnRerun": false
|
65
|
+
},
|
66
|
+
"problemMatcher": {
|
67
|
+
"owner": "ruby",
|
68
|
+
"fileLocation": ["relative", "${workspaceRoot}"],
|
69
|
+
"severity": "error",
|
70
|
+
"pattern": [
|
71
|
+
{
|
72
|
+
"regexp": "^\\s{7}(.*)$",
|
73
|
+
"message": 1
|
74
|
+
},
|
75
|
+
{
|
76
|
+
"regexp": "^\\s+#\\s(\\./.*):(\\d+):(in.*)$",
|
77
|
+
"file": 1,
|
78
|
+
"line": 2,
|
79
|
+
"code": 3
|
80
|
+
}
|
81
|
+
]
|
82
|
+
}
|
83
|
+
}
|
84
|
+
]
|
85
|
+
}
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
2
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
3
|
+
|
4
|
+
## [Unreleased](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.10.2...master)
|
5
|
+
|
6
|
+
No currently unreleased changes.
|
7
|
+
|
8
|
+
## [0.10.2](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.10.1...v0.10.2) - 2021-01-12
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
|
12
|
+
- Loosen Ruby constraint to allow Ruby 3. ([#36](https://github.com/adamlogic/rails_autoscale_agent/pull/36))
|
13
|
+
|
14
|
+
## [0.10.1](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.9.1...v0.10.1) - 2021-01-03
|
15
|
+
|
16
|
+
### Added
|
17
|
+
|
18
|
+
- Add support for [long-running jobs](https://railsautoscale.com/docs/long-running-jobs/) in Sidekiq and Delayed Job.
|
19
|
+
- Handle x-request-start measured in seconds (instead of milliseconds) to support nginx buildpack ([cd092f3](https://github.com/adamlogic/rails_autoscale_agent/commit/cd092f38718abf5ffaea866bcae7831d4c910ffd))
|
20
|
+
- Override worker adapter config via env var ([75dd06b](https://github.com/adamlogic/rails_autoscale_agent/commit/75dd06b2a7ff4eeab829eec24d503dc067c8fe32))
|
21
|
+
|
22
|
+
### Changed
|
23
|
+
|
24
|
+
- Require Ruby 2.5 or newer. ([b033050](https://github.com/adamlogic/rails_autoscale_agent/commit/b033050b7f9d4d7f1e50dbd780cf0e1822249268))
|
25
|
+
- Only report worker metrics from web.1 to avoid redundant data. ([d5d5fa8](https://github.com/adamlogic/rails_autoscale_agent/commit/d5d5fa87fb4d7d046832a64edde9ed0c3a6ec75f))
|
26
|
+
- Don't collect worker metrics for an unreasonable number of queues. ([a9358af](https://github.com/adamlogic/rails_autoscale_agent/commit/a9358af74a29a941d1f1d60a0222077dafd5ce08))
|
27
|
+
|
28
|
+
### Fixed
|
29
|
+
|
30
|
+
- Avoid holding onto database connections (DJ & Que only). ([3919ca5](https://github.com/adamlogic/rails_autoscale_agent/commit/3919ca54420cafa82abf9f8cd251569f9637482b))
|
31
|
+
- Better error handling for worker adapters. ([190786e](https://github.com/adamlogic/rails_autoscale_agent/commit/190786e4a910d41e394a3129aac1d23b594dbd9b))
|
32
|
+
- Don't collect metrics of the reporter isn't running. Avoids memory bloat. ([247c322](https://github.com/adamlogic/rails_autoscale_agent/commit/247c322cffc625a8c6b2395080a048ffb94e7f3b))
|
33
|
+
|
34
|
+
## [0.10.0](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.9.1...v0.10.0) - 2021-01-03 [YANKED]
|
35
|
+
|
36
|
+
_I released the wrong branch 🤦♂️_
|
37
|
+
|
38
|
+
## [0.9.1](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.9.0...v0.9.1) - 2020-07-29
|
39
|
+
|
40
|
+
### Fixed
|
41
|
+
|
42
|
+
- Fix a bug in error handling. ([3018542](https://github.com/adamlogic/rails_autoscale_agent/commit/3018542cd046fc4e1bd6e7da86e72a6aa2d50a8f))
|
43
|
+
- Remove unintentional Rails dependency.
|
44
|
+
|
45
|
+
## [0.9.0](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.8.3...v0.9.0) - 2020-07-12
|
46
|
+
|
47
|
+
### Added
|
48
|
+
|
49
|
+
- Add support for Resque workers.
|
50
|
+
- Add dev mode for working on the agent gem itself. ([47e3fca](https://github.com/adamlogic/rails_autoscale_agent/commit/47e3fca5b788f48567a345d9cab3a26b9cd87693))
|
51
|
+
- Report agent exceptions to Rails Autoscale.
|
52
|
+
|
53
|
+
### Changed
|
54
|
+
|
55
|
+
- Adjust queue time metric to exclude time waiting for large request bodies. ([#25](https://github.com/adamlogic/rails_autoscale_agent/pull/25))
|
56
|
+
- Que and DJ jobs without a queue name will be included in the "default" queue metrics.
|
57
|
+
|
58
|
+
### Fixed
|
59
|
+
|
60
|
+
- Multiple fixes to the Delayed Job SQL query.
|
61
|
+
|
62
|
+
## [0.8.3](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.8.2...v0.8.3) - 2020-05-26
|
63
|
+
|
64
|
+
### Fixed
|
65
|
+
|
66
|
+
- Ignored failed job in Delayed Job adapter. ([fa72fc2](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.8.2...v0.8.3))
|
67
|
+
|
68
|
+
## [0.8.2](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.8.1...v0.8.2) - 2020-05-22
|
69
|
+
|
70
|
+
### Fixed
|
71
|
+
|
72
|
+
- Ignore worker metrics from unnamed queues (DJ & Que only). These metrics were being lumped with web metrics. ([#21](https://github.com/adamlogic/rails_autoscale_agent/pull/21))
|
73
|
+
|
74
|
+
## [0.8.1](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.8.0...v0.8.1) - 2020-05-04
|
75
|
+
|
76
|
+
### Fixed
|
77
|
+
|
78
|
+
- Ignore failed jobs in Que adapter. ([#18](https://github.com/adamlogic/rails_autoscale_agent/pull/18))
|
79
|
+
|
80
|
+
## [0.8.0](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.7.0...v0.8.0) - 2020-03-21
|
81
|
+
|
82
|
+
### Added
|
83
|
+
|
84
|
+
- Add support for Delayed Job ([#14](https://github.com/adamlogic/rails_autoscale_agent/pull/14))
|
85
|
+
- Add support for Que ([#15](https://github.com/adamlogic/rails_autoscale_agent/pull/15))
|
86
|
+
|
87
|
+
## [0.7.0](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.6.3...v0.7.0) - 2019-12-04
|
88
|
+
|
89
|
+
### Added
|
90
|
+
|
91
|
+
- Make worker adapters configurable. ([012d937](https://github.com/adamlogic/rails_autoscale_agent/commit/012d9379296763f5e42df95f05b066fe82ab0051))
|
92
|
+
|
93
|
+
## [0.6.3](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.6.2...v0.6.3) - 2019-06-25
|
94
|
+
|
95
|
+
### Fixed
|
96
|
+
|
97
|
+
- Fix issues with logging.
|
98
|
+
|
99
|
+
## [0.6.2](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.6.1...v0.6.2) - 2019-06-22
|
100
|
+
|
101
|
+
### Fixed
|
102
|
+
|
103
|
+
- Fix issues with logging.
|
104
|
+
|
105
|
+
## [0.6.1](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.6.0...v0.6.1) - 2019-05-06
|
106
|
+
|
107
|
+
### Fixed
|
108
|
+
|
109
|
+
- Don't assume Sidekiq is present.
|
110
|
+
|
111
|
+
## [0.6.0](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.4.1...v0.6.0) - 2019-05-03
|
112
|
+
|
113
|
+
### Added
|
114
|
+
|
115
|
+
- Add support for autoscaling Sidekiq.
|
data/Gemfile
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
# Specify your gem's dependencies in rails_autoscale_agent.gemspec
|
4
3
|
gemspec
|
4
|
+
|
5
|
+
gem "rake", ">= 12.3.3"
|
6
|
+
gem "rspec", ">= 3.0"
|
7
|
+
gem "vcr", ">= 3.0"
|
8
|
+
gem "webmock"
|
9
|
+
gem "pry-byebug"
|
10
|
+
gem "sidekiq", ">= 5.0"
|
11
|
+
gem "delayed_job"
|
12
|
+
gem "delayed_job_active_record"
|
13
|
+
gem "que"
|
14
|
+
gem "resque"
|
15
|
+
gem "activesupport"
|
16
|
+
gem "sqlite3", platforms: :ruby
|
data/README.md
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
|
3
3
|
[](https://travis-ci.org/adamlogic/rails_autoscale_agent)
|
4
4
|
|
5
|
-
This gem works together with the [Rails Autoscale](https://railsautoscale.com) Heroku add-on to automatically scale your web dynos as needed. It gathers a minimal set of metrics for each request, and periodically posts this data asynchronously to the Rails Autoscale service.
|
5
|
+
This gem works together with the [Rails Autoscale](https://railsautoscale.com) Heroku add-on to automatically scale your web and worker dynos as needed. It gathers a minimal set of metrics for each request (and job queue), and periodically posts this data asynchronously to the Rails Autoscale service.
|
6
6
|
|
7
7
|
## Requirements
|
8
8
|
|
9
|
-
|
9
|
+
- Rack-based app
|
10
|
+
- Ruby 2.5 or newer
|
10
11
|
|
11
12
|
## Getting Started
|
12
13
|
|
@@ -22,15 +23,7 @@ The agent will only communicate with Rails Autoscale if a `RAILS_AUTOSCALE_URL`
|
|
22
23
|
|
23
24
|
## Non-Rails Rack apps
|
24
25
|
|
25
|
-
You'll need to insert the `RailsAutoscaleAgent::Middleware` manually. Insert it before `Rack::Runtime` to ensure accuracy of request queue timings.
|
26
|
-
|
27
|
-
## Changing the logger
|
28
|
-
|
29
|
-
If you wish to use a different logger you can set it on the configuration object:
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
RailsAutoscaleAgent::Config.instance.logger = MyLogger.new
|
33
|
-
```
|
26
|
+
You'll need to `require 'rails_autoscale_agent/middleware'` and insert the `RailsAutoscaleAgent::Middleware` manually. Insert it before `Rack::Runtime` to ensure accuracy of request queue timings.
|
34
27
|
|
35
28
|
## What data is collected?
|
36
29
|
|
@@ -43,29 +36,84 @@ The middleware agent runs in its own thread so your web requests are not impacte
|
|
43
36
|
- PID
|
44
37
|
- Collection of queue time measurements (time and milliseconds)
|
45
38
|
|
46
|
-
Rails Autoscale
|
39
|
+
Rails Autoscale aggregates and stores this information to power the autoscaling algorithm and dashboard visualizations.
|
47
40
|
|
48
|
-
##
|
41
|
+
## Configuration
|
42
|
+
|
43
|
+
Most Rails Autoscale configurations are handled via the settings page on your Rails Autoscale dashboard, but there a few ways you can directly change the behavior of the agent via environment variables:
|
44
|
+
|
45
|
+
- `RAILS_AUTOSCALE_DEBUG` - Enables debug logging. See more in the [logging](#logging) section below.
|
46
|
+
- `RAILS_AUTOSCALE_WORKER_ADAPTER` - Overrides the available worker adapters. See more in the [worker adapters](#worker_adapters) section below.
|
47
|
+
- `RAILS_AUTOSCALE_LONG_JOBS` - Enables reporting for active workers. See [Handling Long-Running Background Jobs](https://railsautoscale.com/docs/long-running-jobs/) in the Rails Autoscale docs for more.
|
48
|
+
|
49
|
+
## Worker adapters
|
50
|
+
|
51
|
+
Rails Autoscale supports autoscaling worker dynos. Out of the box, four job backends are supported: Sidekiq, Resque, Delayed Job, and Que. The agent will automatically enable the appropriate worker adapter based on what you have installed in your app.
|
52
|
+
|
53
|
+
In some scenarios you might want to override this behavior. Let's say you have both Sidekiq and Resque installed 🤷♂️, but you only want Rails Autoscale to collect metrics for Sidekiq. Here's how you'd override that:
|
54
|
+
|
55
|
+
```
|
56
|
+
heroku config:add RAILS_AUTOSCALE_WORKER_ADAPTER=sidekiq
|
57
|
+
```
|
58
|
+
|
59
|
+
You can also disable collection of worker metrics altogether:
|
60
|
+
|
61
|
+
```
|
62
|
+
heroku config:add RAILS_AUTOSCALE_WORKER_ADAPTER=""
|
63
|
+
```
|
64
|
+
|
65
|
+
It's also possible to write a custom worker adapter. See [these docs](https://railsautoscale.com/docs/custom-worker-adapter/) for details.
|
49
66
|
|
50
|
-
|
67
|
+
## Troubleshooting
|
51
68
|
|
52
|
-
Once installed, you should see something like this in development:
|
69
|
+
Once installed, you should see something like this in your development log:
|
53
70
|
|
54
71
|
> [RailsAutoscale] Reporter not started: RAILS_AUTOSCALE_URL is not set
|
55
72
|
|
56
|
-
In production, you should see something like this:
|
73
|
+
In production, run `heroku logs -t | grep RailsAutoscale`, and you should see something like this:
|
57
74
|
|
58
75
|
> [RailsAutoscale] Reporter starting, will report every 15 seconds
|
59
76
|
|
60
77
|
If you don't see either of these, try running `bundle` again and restarting your Rails application.
|
61
78
|
|
79
|
+
You can see more detailed (debug) logging by setting `RAILS_AUTOSCALE_DEBUG` on your Heroku app:
|
80
|
+
|
81
|
+
```
|
82
|
+
heroku config:add RAILS_AUTOSCALE_DEBUG=true
|
83
|
+
```
|
84
|
+
|
85
|
+
See more in the [logging](#logging) section below.
|
86
|
+
|
62
87
|
Reach out to help@railsautoscale.com if you run into any other problems.
|
63
88
|
|
89
|
+
## Logging
|
90
|
+
|
91
|
+
The Rails logger is used by default.
|
92
|
+
If you wish to use a different logger you can set it on the configuration object:
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
# config/initializers/rails_autoscale_agent.rb
|
96
|
+
RailsAutoscaleAgent::Config.instance.logger = MyLogger.new
|
97
|
+
```
|
98
|
+
|
99
|
+
Debug logs are silenced by default because Rails apps default to a DEBUG log level in production, and this gem has _very_ chatty debug logs. If you want to see the debug logs, set `RAILS_AUTOSCALE_DEBUG` on your Heroku app:
|
100
|
+
|
101
|
+
```
|
102
|
+
heroku config:add RAILS_AUTOSCALE_DEBUG=true
|
103
|
+
```
|
104
|
+
|
105
|
+
If you find the gem too chatty even without this, you can quiet it down further:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
# config/initializers/rails_autoscale_agent.rb
|
109
|
+
RailsAutoscaleAgent::Config.instance.quiet = true
|
110
|
+
```
|
111
|
+
|
64
112
|
## Development
|
65
113
|
|
66
114
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
67
115
|
|
68
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
116
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, commit it, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
69
117
|
|
70
118
|
## Contributing
|
71
119
|
|
@@ -11,8 +11,8 @@ module RailsAutoscaleAgent
|
|
11
11
|
|
12
12
|
SUCCESS = 'success'
|
13
13
|
|
14
|
-
def initialize(
|
15
|
-
@
|
14
|
+
def initialize(config)
|
15
|
+
@config = config
|
16
16
|
end
|
17
17
|
|
18
18
|
def report_metrics!(report_params, timings_csv)
|
@@ -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)
|
@@ -37,9 +41,14 @@ module RailsAutoscaleAgent
|
|
37
41
|
end
|
38
42
|
|
39
43
|
def post_raw(options)
|
40
|
-
uri = URI.parse("#{@
|
44
|
+
uri = URI.parse("#{@config.api_base_url}#{options.fetch(:path)}")
|
41
45
|
ssl = uri.scheme == 'https'
|
42
46
|
|
47
|
+
if @config.dev_mode
|
48
|
+
logger.debug "[DEV_MODE] Skipping request to #{uri}"
|
49
|
+
return SuccessResponse.new('{}')
|
50
|
+
end
|
51
|
+
|
43
52
|
response = Net::HTTP.start(uri.host, uri.port, use_ssl: ssl) do |http|
|
44
53
|
request = Net::HTTP::Post.new(uri.request_uri, options[:headers] || {})
|
45
54
|
request.body = options.fetch(:body)
|
@@ -50,7 +59,7 @@ module RailsAutoscaleAgent
|
|
50
59
|
|
51
60
|
case response.code.to_i
|
52
61
|
when 200...300 then SuccessResponse.new(response.body)
|
53
|
-
else FailureResponse.new(response.message)
|
62
|
+
else FailureResponse.new([response.code, response.message].join(' - '))
|
54
63
|
end
|
55
64
|
end
|
56
65
|
|
@@ -4,32 +4,53 @@ require 'singleton'
|
|
4
4
|
|
5
5
|
module RailsAutoscaleAgent
|
6
6
|
class Config
|
7
|
+
DEFAULT_WORKER_ADAPTERS = 'sidekiq,delayed_job,que,resque'
|
8
|
+
|
7
9
|
include Singleton
|
8
10
|
|
9
11
|
attr_accessor :report_interval, :logger, :api_base_url, :max_request_size,
|
10
|
-
:dyno, :
|
12
|
+
:dyno, :addon_name, :worker_adapters, :dev_mode, :debug, :quiet,
|
13
|
+
:track_long_running_jobs,
|
14
|
+
|
15
|
+
# legacy configs, no longer used
|
16
|
+
:sidekiq_latency_for_active_jobs, :latency_for_active_jobs
|
11
17
|
|
12
18
|
def initialize
|
19
|
+
@worker_adapters = prepare_worker_adapters
|
20
|
+
|
13
21
|
# Allow the add-on name to be configured - needed for testing
|
14
22
|
@addon_name = ENV['RAILS_AUTOSCALE_ADDON'] || 'RAILS_AUTOSCALE'
|
15
23
|
@api_base_url = ENV["#{@addon_name}_URL"]
|
16
|
-
@
|
24
|
+
@dev_mode = ENV['RAILS_AUTOSCALE_DEV'] == 'true'
|
25
|
+
@debug = dev_mode? || ENV['RAILS_AUTOSCALE_DEBUG'] == 'true'
|
26
|
+
@track_long_running_jobs = ENV['RAILS_AUTOSCALE_LONG_JOBS'] == 'true'
|
17
27
|
@max_request_size = 100_000 # ignore request payloads over 100k since they skew the queue times
|
18
|
-
@report_interval =
|
28
|
+
@report_interval = 10 # this default will be overwritten during Reporter#register!
|
19
29
|
@logger ||= defined?(Rails) ? Rails.logger : ::Logger.new(STDOUT)
|
20
|
-
@dyno = ENV['DYNO']
|
21
|
-
@worker_adapters = [
|
22
|
-
WorkerAdapters::Sidekiq.new,
|
23
|
-
]
|
30
|
+
@dyno = dev_mode? ? 'dev.1' : ENV['DYNO']
|
24
31
|
end
|
25
32
|
|
26
33
|
def to_s
|
27
|
-
"#{@dyno}##{
|
34
|
+
"#{@dyno}##{Process.pid}"
|
28
35
|
end
|
29
36
|
|
30
37
|
def ignore_large_requests?
|
31
38
|
@max_request_size
|
32
39
|
end
|
33
40
|
|
41
|
+
alias_method :dev_mode?, :dev_mode
|
42
|
+
alias_method :debug?, :debug
|
43
|
+
alias_method :quiet?, :quiet
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def prepare_worker_adapters
|
48
|
+
adapter_names = (ENV['RAILS_AUTOSCALE_WORKER_ADAPTER'] || DEFAULT_WORKER_ADAPTERS).split(',')
|
49
|
+
adapter_names.map do |adapter_name|
|
50
|
+
require "rails_autoscale_agent/worker_adapters/#{adapter_name}"
|
51
|
+
adapter_constant_name = adapter_name.capitalize.gsub(/(?:_)(.)/i) { $1.upcase }
|
52
|
+
WorkerAdapters.const_get(adapter_constant_name).instance
|
53
|
+
end
|
54
|
+
end
|
34
55
|
end
|
35
56
|
end
|