rails_autoscale_agent 0.10.1 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -2
- data/README.md +4 -2
- data/lib/rails_autoscale_agent/config.rb +2 -1
- data/lib/rails_autoscale_agent/reporter.rb +9 -14
- data/lib/rails_autoscale_agent/store.rb +1 -0
- data/lib/rails_autoscale_agent/version.rb +1 -1
- data/lib/rails_autoscale_agent/worker_adapters/delayed_job.rb +23 -5
- data/lib/rails_autoscale_agent/worker_adapters/que.rb +22 -4
- data/lib/rails_autoscale_agent/worker_adapters/resque.rb +2 -2
- data/lib/rails_autoscale_agent/worker_adapters/sidekiq.rb +2 -2
- data/rails_autoscale_agent.gemspec +16 -3
- metadata +17 -11
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36f5471f01400a8db00951513b7387150c370c92ed968b1e2aea3c752e4e5006
|
4
|
+
data.tar.gz: a113b0ca9936451db2a05aa3c0792f100938baf4c036f1f87100ef991155d880
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa7ef93dbcb9ab8341b2d7f313428c6bf75908f0e5db40987463f811f33c9577c99e404dad94e423cd752bd31edb1196bfa41b7ec5ec3c5841c917deaf53b09c
|
7
|
+
data.tar.gz: 59893c8b34924505d1d954a60422b7e3c81feec1933616ccee1a6f717f696e8263397f2b95b178c9c340831e5e4fb469310efe92739751489c32c5759514d5f4
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,21 @@
|
|
1
1
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
2
2
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
3
3
|
|
4
|
-
## [Unreleased](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.
|
4
|
+
## [Unreleased](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.11.0...master)
|
5
5
|
|
6
|
-
|
6
|
+
No currently unreleased changes.
|
7
|
+
|
8
|
+
## [0.11.0](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.10.2...v0.11.0)
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Add `RAILS_AUTOSCALE_MAX_QUEUES` config option. ([28738a5](https://github.com/adamlogic/rails_autoscale_agent/commit/28738a5dc4cd6b0a46e77459d6f98e6b33072da9))
|
13
|
+
|
14
|
+
## [0.10.2](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.10.1...v0.10.2) - 2021-01-12
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
|
18
|
+
- Loosen Ruby constraint to allow Ruby 3. ([#36](https://github.com/adamlogic/rails_autoscale_agent/pull/36))
|
7
19
|
|
8
20
|
## [0.10.1](https://github.com/adamlogic/rails_autoscale_agent/compare/v0.9.1...v0.10.1) - 2021-01-03
|
9
21
|
|
data/README.md
CHANGED
@@ -6,7 +6,8 @@ This gem works together with the [Rails Autoscale](https://railsautoscale.com) H
|
|
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
|
|
@@ -42,8 +43,9 @@ Rails Autoscale aggregates and stores this information to power the autoscaling
|
|
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:
|
43
44
|
|
44
45
|
- `RAILS_AUTOSCALE_DEBUG` - Enables debug logging. See more in the [logging](#logging) section below.
|
45
|
-
- `RAILS_AUTOSCALE_WORKER_ADAPTER` - Overrides the available worker adapters. See more in the [worker adapters](#
|
46
|
+
- `RAILS_AUTOSCALE_WORKER_ADAPTER` - Overrides the available worker adapters. See more in the [worker adapters](#worker-adapters) section below.
|
46
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
|
+
- `RAILS_AUTOSCALE_MAX_QUEUES` - Worker metrics will only report up to 50 queues by default. If you have more than 50 queues, you'll need to configure this settings or reduce your number of queues.
|
47
49
|
|
48
50
|
## Worker adapters
|
49
51
|
|
@@ -10,7 +10,7 @@ module RailsAutoscaleAgent
|
|
10
10
|
|
11
11
|
attr_accessor :report_interval, :logger, :api_base_url, :max_request_size,
|
12
12
|
:dyno, :addon_name, :worker_adapters, :dev_mode, :debug, :quiet,
|
13
|
-
:track_long_running_jobs,
|
13
|
+
:track_long_running_jobs, :max_queues,
|
14
14
|
|
15
15
|
# legacy configs, no longer used
|
16
16
|
:sidekiq_latency_for_active_jobs, :latency_for_active_jobs
|
@@ -24,6 +24,7 @@ module RailsAutoscaleAgent
|
|
24
24
|
@dev_mode = ENV['RAILS_AUTOSCALE_DEV'] == 'true'
|
25
25
|
@debug = dev_mode? || ENV['RAILS_AUTOSCALE_DEBUG'] == 'true'
|
26
26
|
@track_long_running_jobs = ENV['RAILS_AUTOSCALE_LONG_JOBS'] == 'true'
|
27
|
+
@max_queues = ENV.fetch('RAILS_AUTOSCALE_MAX_QUEUES', 50).to_i
|
27
28
|
@max_request_size = 100_000 # ignore request payloads over 100k since they skew the queue times
|
28
29
|
@report_interval = 10 # this default will be overwritten during Reporter#register!
|
29
30
|
@logger ||= defined?(Rails) ? Rails.logger : ::Logger.new(STDOUT)
|
@@ -6,8 +6,6 @@ require 'rails_autoscale_agent/autoscale_api'
|
|
6
6
|
require 'rails_autoscale_agent/time_rounder'
|
7
7
|
require 'rails_autoscale_agent/registration'
|
8
8
|
|
9
|
-
# Reporter wakes up every minute to send metrics to the RailsAutoscale API
|
10
|
-
|
11
9
|
module RailsAutoscaleAgent
|
12
10
|
class Reporter
|
13
11
|
include Singleton
|
@@ -56,20 +54,16 @@ module RailsAutoscaleAgent
|
|
56
54
|
def report!(config, store)
|
57
55
|
report = store.pop_report
|
58
56
|
|
59
|
-
|
60
|
-
logger.info "Reporting #{report.measurements.size} measurements"
|
57
|
+
logger.info "Reporting #{report.measurements.size} measurements"
|
61
58
|
|
62
|
-
|
63
|
-
|
59
|
+
params = report.to_params(config)
|
60
|
+
result = AutoscaleApi.new(config).report_metrics!(params, report.to_csv)
|
64
61
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
71
|
-
else
|
72
|
-
logger.debug "Reporter has nothing to report"
|
62
|
+
case result
|
63
|
+
when AutoscaleApi::SuccessResponse
|
64
|
+
logger.debug "Reported successfully"
|
65
|
+
when AutoscaleApi::FailureResponse
|
66
|
+
logger.error "Reporter failed: #{result.failure_message}"
|
73
67
|
end
|
74
68
|
end
|
75
69
|
|
@@ -84,6 +78,7 @@ module RailsAutoscaleAgent
|
|
84
78
|
config.max_request_size = result.data['max_request_size'] if result.data['max_request_size']
|
85
79
|
worker_adapters_msg = worker_adapters.map { |a| a.class.name }.join(', ')
|
86
80
|
logger.info "Reporter starting, will report every #{config.report_interval} seconds or so. Worker adapters: [#{worker_adapters_msg}]"
|
81
|
+
logger.warn "[DEPRECATION WARNING] rails_autoscale_agent is no longer maintained. Please switch to rails-autoscale-web as soon as possible."
|
87
82
|
when AutoscaleApi::FailureResponse
|
88
83
|
logger.error "Reporter failed to register: #{result.failure_message}"
|
89
84
|
end
|
@@ -12,7 +12,7 @@ module RailsAutoscaleAgent
|
|
12
12
|
|
13
13
|
def enabled?
|
14
14
|
if defined?(::Delayed::Job) && defined?(::Delayed::Backend::ActiveRecord)
|
15
|
-
log_msg = String.new("DelayedJob enabled (#{
|
15
|
+
log_msg = String.new("DelayedJob enabled (#{default_timezone})")
|
16
16
|
log_msg << " with long-running job support" if track_long_running_jobs?
|
17
17
|
logger.info log_msg
|
18
18
|
true
|
@@ -30,11 +30,11 @@ module RailsAutoscaleAgent
|
|
30
30
|
GROUP BY queue
|
31
31
|
SQL
|
32
32
|
|
33
|
-
run_at_by_queue = Hash[
|
33
|
+
run_at_by_queue = Hash[select_rows_silently(sql)]
|
34
34
|
|
35
35
|
# Don't collect worker metrics if there are unreasonable number of queues
|
36
|
-
if run_at_by_queue.size >
|
37
|
-
logger.
|
36
|
+
if run_at_by_queue.size > Config.instance.max_queues
|
37
|
+
logger.warn "Skipping DelayedJob metrics - #{run_at_by_queue.size} queues exceeds the #{Config.instance.max_queues} queue limit"
|
38
38
|
return
|
39
39
|
end
|
40
40
|
|
@@ -50,7 +50,7 @@ module RailsAutoscaleAgent
|
|
50
50
|
GROUP BY 1
|
51
51
|
SQL
|
52
52
|
|
53
|
-
busy_count_by_queue = Hash[
|
53
|
+
busy_count_by_queue = Hash[select_rows_silently(sql)]
|
54
54
|
self.queues = queues | busy_count_by_queue.keys
|
55
55
|
end
|
56
56
|
|
@@ -88,6 +88,24 @@ module RailsAutoscaleAgent
|
|
88
88
|
Config.instance.track_long_running_jobs
|
89
89
|
end
|
90
90
|
|
91
|
+
def default_timezone
|
92
|
+
if ::ActiveRecord.respond_to?(:default_timezone)
|
93
|
+
# Rails >= 7
|
94
|
+
::ActiveRecord.default_timezone
|
95
|
+
else
|
96
|
+
# Rails < 7
|
97
|
+
::ActiveRecord::Base.default_timezone
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def select_rows_silently(sql)
|
102
|
+
if ::ActiveRecord::Base.logger.respond_to?(:silence)
|
103
|
+
::ActiveRecord::Base.logger.silence { select_rows(sql) }
|
104
|
+
else
|
105
|
+
select_rows(sql)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
91
109
|
def select_rows(sql)
|
92
110
|
# This ensures the agent doesn't hold onto a DB connection any longer than necessary
|
93
111
|
ActiveRecord::Base.connection_pool.with_connection { |c| c.select_rows(sql) }
|
@@ -20,7 +20,7 @@ module RailsAutoscaleAgent
|
|
20
20
|
|
21
21
|
def enabled?
|
22
22
|
if defined?(::Que)
|
23
|
-
logger.info "Que enabled (#{
|
23
|
+
logger.info "Que enabled (#{default_timezone})"
|
24
24
|
true
|
25
25
|
end
|
26
26
|
end
|
@@ -37,11 +37,11 @@ module RailsAutoscaleAgent
|
|
37
37
|
GROUP BY 1
|
38
38
|
SQL
|
39
39
|
|
40
|
-
run_at_by_queue = Hash[
|
40
|
+
run_at_by_queue = Hash[select_rows_silently(sql)]
|
41
41
|
|
42
42
|
# Don't collect worker metrics if there are unreasonable number of queues
|
43
|
-
if run_at_by_queue.size >
|
44
|
-
logger.
|
43
|
+
if run_at_by_queue.size > Config.instance.max_queues
|
44
|
+
logger.warn "Skipping Que metrics - #{run_at_by_queue.size} queues exceeds the #{Config.instance.max_queues} queue limit"
|
45
45
|
return
|
46
46
|
end
|
47
47
|
|
@@ -62,6 +62,24 @@ module RailsAutoscaleAgent
|
|
62
62
|
|
63
63
|
private
|
64
64
|
|
65
|
+
def default_timezone
|
66
|
+
if ::ActiveRecord.respond_to?(:default_timezone)
|
67
|
+
# Rails >= 7
|
68
|
+
::ActiveRecord.default_timezone
|
69
|
+
else
|
70
|
+
# Rails < 7
|
71
|
+
::ActiveRecord::Base.default_timezone
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def select_rows_silently(sql)
|
76
|
+
if ::ActiveRecord::Base.logger.respond_to?(:silence)
|
77
|
+
::ActiveRecord::Base.logger.silence { select_rows(sql) }
|
78
|
+
else
|
79
|
+
select_rows(sql)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
65
83
|
def select_rows(sql)
|
66
84
|
# This ensures the agent doesn't hold onto a DB connection any longer than necessary
|
67
85
|
ActiveRecord::Base.connection_pool.with_connection { |c| c.select_rows(sql) }
|
@@ -27,8 +27,8 @@ module RailsAutoscaleAgent
|
|
27
27
|
current_queues = ::Resque.queues
|
28
28
|
|
29
29
|
# Don't collect worker metrics if there are unreasonable number of queues
|
30
|
-
if current_queues.size >
|
31
|
-
logger.
|
30
|
+
if current_queues.size > Config.instance.max_queues
|
31
|
+
logger.warn "Skipping Resque metrics - #{current_queues.size} queues exceeds the #{Config.instance.max_queues} queue limit"
|
32
32
|
return
|
33
33
|
end
|
34
34
|
|
@@ -29,8 +29,8 @@ module RailsAutoscaleAgent
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# Don't collect worker metrics if there are unreasonable number of queues
|
32
|
-
if queues_by_name.size >
|
33
|
-
logger.
|
32
|
+
if queues_by_name.size > Config.instance.max_queues
|
33
|
+
logger.warn "Skipping Sidekiq metrics - #{queues_by_name.size} queues exceeds the #{Config.instance.max_queues} queue limit"
|
34
34
|
return
|
35
35
|
end
|
36
36
|
|
@@ -9,12 +9,25 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Adam McCrea"]
|
10
10
|
spec.email = ["adam@adamlogic.com"]
|
11
11
|
|
12
|
-
spec.summary = "
|
13
|
-
spec.homepage = "https://
|
12
|
+
spec.summary = "[DEPRECATED] Please use the rails-autoscale-web gem"
|
13
|
+
spec.homepage = "https://railsautoscale.com"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
|
-
spec.required_ruby_version = '
|
19
|
+
spec.required_ruby_version = '>= 2.5.0'
|
20
|
+
spec.post_install_message = <<~MSG
|
21
|
+
DEPRECATION WARNING: rails_autoscale_agent is no longer maintained.
|
22
|
+
Please install rails-autoscale-web instead.
|
23
|
+
See https://github.com/rails-autoscale/rails-autoscale-gems for more.
|
24
|
+
MSG
|
25
|
+
|
26
|
+
spec.metadata = {
|
27
|
+
"homepage_uri" => "https://railsautoscale.com",
|
28
|
+
"bug_tracker_uri" => "https://github.com/rails-autoscale/rails-autoscale-gems/issues",
|
29
|
+
"documentation_uri" => "https://railsautoscale.com/docs",
|
30
|
+
"changelog_uri" => "https://github.com/rails-autoscale/rails-autoscale-gems/blob/master/CHANGELOG.md",
|
31
|
+
"source_code_uri" => "https://github.com/rails-autoscale/rails-autoscale-gems",
|
32
|
+
}
|
20
33
|
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.12.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: 2022-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -19,7 +19,6 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- ".gitignore"
|
21
21
|
- ".rspec"
|
22
|
-
- ".ruby-version"
|
23
22
|
- ".travis.yml"
|
24
23
|
- ".vscode/tasks.json"
|
25
24
|
- CHANGELOG.md
|
@@ -49,28 +48,35 @@ files:
|
|
49
48
|
- lib/rails_autoscale_agent/worker_adapters/sidekiq.rb
|
50
49
|
- log/.gitkeep
|
51
50
|
- rails_autoscale_agent.gemspec
|
52
|
-
homepage: https://
|
51
|
+
homepage: https://railsautoscale.com
|
53
52
|
licenses:
|
54
53
|
- MIT
|
55
|
-
metadata:
|
56
|
-
|
54
|
+
metadata:
|
55
|
+
homepage_uri: https://railsautoscale.com
|
56
|
+
bug_tracker_uri: https://github.com/rails-autoscale/rails-autoscale-gems/issues
|
57
|
+
documentation_uri: https://railsautoscale.com/docs
|
58
|
+
changelog_uri: https://github.com/rails-autoscale/rails-autoscale-gems/blob/master/CHANGELOG.md
|
59
|
+
source_code_uri: https://github.com/rails-autoscale/rails-autoscale-gems
|
60
|
+
post_install_message: |
|
61
|
+
DEPRECATION WARNING: rails_autoscale_agent is no longer maintained.
|
62
|
+
Please install rails-autoscale-web instead.
|
63
|
+
See https://github.com/rails-autoscale/rails-autoscale-gems for more.
|
57
64
|
rdoc_options: []
|
58
65
|
require_paths:
|
59
66
|
- lib
|
60
67
|
required_ruby_version: !ruby/object:Gem::Requirement
|
61
68
|
requirements:
|
62
|
-
- - "
|
69
|
+
- - ">="
|
63
70
|
- !ruby/object:Gem::Version
|
64
|
-
version:
|
71
|
+
version: 2.5.0
|
65
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
73
|
requirements:
|
67
74
|
- - ">="
|
68
75
|
- !ruby/object:Gem::Version
|
69
76
|
version: '0'
|
70
77
|
requirements: []
|
71
|
-
rubygems_version: 3.
|
78
|
+
rubygems_version: 3.2.32
|
72
79
|
signing_key:
|
73
80
|
specification_version: 4
|
74
|
-
summary:
|
75
|
-
your web dynos.
|
81
|
+
summary: "[DEPRECATED] Please use the rails-autoscale-web gem"
|
76
82
|
test_files: []
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.6.5
|