speedshop-cloudwatch 0.2.2 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cff6ca0b03ef4fa6214a14bfe89384b72593aec69ec8fb93288460e3b4228a0
4
- data.tar.gz: 1505eadbc697749442550a5ad22df30fa545c27302b6ba2b5c62a1a218b9c248
3
+ metadata.gz: f88cf52e836639196bffac94062d95b4ee9d6b8943b60baa48b79d8ed17e49d7
4
+ data.tar.gz: d0a9e0d7ccf1c4d045cb423efe7a3b7a606f9fd3cffeab4220140d6db434b830
5
5
  SHA512:
6
- metadata.gz: 986e68cf85c6c4d06c606312838d701e7309f9fb6a20879b23e1353360ae03a29f056c1c8129ac11e0b10cf381226eabeec7a76a160b0555dc1b8f243815d10b
7
- data.tar.gz: 76bc9802a6107aa1f153c096be8bfc94897084cd380646657b10a45cb7dbcbf2e7e98e797fc86c0b87d7084628810e9389bf982f3e9126cd69a0d6b1a7687f9a
6
+ metadata.gz: b740fa84be92541ef34432fbec47d3142a39cac97cfc2c40044393a2d9b5d79b0a1388f07cb562d6cd1e7f5941823320f06fb20d7b113fcf3e69578393a20f2c
7
+ data.tar.gz: 9b18ddf279f05614a701e6ff36788d57c32eafed40d4fd92dcc6a72e89e1160ad43701365307bee711b4d968f16b972eeeeeeee6de183ce3bd57883a3f18754a
data/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.0] - 2026-12-02
11
+
12
+ ### Added
13
+ - Added a Solid Queue integration that reports each supervisor's process metrics and per-queue metrics, in fork and async mode, and with Solid Queue's Puma plugin. Requires Solid Queue 1.6 or newer.
14
+
10
15
  ## [0.2.2] - 2026-09-07
11
16
 
12
17
  ### Changed
@@ -34,7 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
34
39
  ### Added
35
40
  - Initial public release.
36
41
 
37
- [Unreleased]: https://github.com/speedshop/speedshop-cloudwatch/compare/v0.2.2...HEAD
42
+ [Unreleased]: https://github.com/speedshop/speedshop-cloudwatch/compare/v0.3.0...HEAD
43
+ [0.3.0]: https://github.com/speedshop/speedshop-cloudwatch/compare/v0.2.2...v0.3.0
38
44
  [0.2.2]: https://github.com/speedshop/speedshop-cloudwatch/compare/v0.2.1...v0.2.2
39
45
  [0.2.1]: https://github.com/speedshop/speedshop-cloudwatch/compare/v0.2.0...v0.2.1
40
46
  [0.2.0]: https://github.com/speedshop/speedshop-cloudwatch/compare/v0.1.0...v0.2.0
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  <img src="https://github.com/user-attachments/assets/146ce110-311a-4acb-8000-66cd098f8b45" alt="Sit around and watch the clouds all day...">
5
5
  </p>
6
6
 
7
- This gem helps integrate your Ruby application with AWS CloudWatch for the purposes of auto-scaling. There are integrations for **Puma**, **Rack**, **Sidekiq** and **ActiveJob**.
7
+ This gem helps integrate your Ruby application with AWS CloudWatch for the purposes of auto-scaling. There are integrations for **Puma**, **Rack**, **Sidekiq**, **Solid Queue** and **ActiveJob**.
8
8
 
9
9
  This gem is for **infrastructure and queue metrics**, not application performance metrics, like response times, job execution times, or error rates. Use your APM for that stuff.
10
10
 
@@ -12,7 +12,7 @@ CloudWatch is unusually difficult to integrate with properly in Ruby, because th
12
12
 
13
13
  This library helps you avoid that latency by reporting to CloudWatch in a background thread.
14
14
 
15
- This library supports **Ruby 2.7+, Sidekiq 7+, and Puma 6+**.
15
+ This library supports **Ruby 2.7+, Sidekiq 7+, Solid Queue 1.6+, and Puma 6+**.
16
16
 
17
17
  ## Metrics
18
18
 
@@ -23,6 +23,7 @@ By default, only essential queue metrics are enabled:
23
23
  ```ruby
24
24
  config.metrics[:puma] = [] # Disabled by default
25
25
  config.metrics[:sidekiq] = [:QueueLatency] # Per queue
26
+ config.metrics[:solid_queue] = [:QueueLatency] # Per queue
26
27
  config.metrics[:rack] = [:RequestQueueTime]
27
28
  config.metrics[:active_job] = [:QueueLatency] # Per queue
28
29
  ```
@@ -41,6 +42,12 @@ config.metrics[:sidekiq] = [
41
42
  :DeadJobs, :Workers, :Processes, :DefaultQueueLatency, :Capacity,
42
43
  :Utilization, :QueueLatency, :QueueSize
43
44
  ]
45
+
46
+ # Enable additional Solid Queue metrics
47
+ config.metrics[:solid_queue] = [
48
+ :Processes, :Workers, :Capacity, :Utilization,
49
+ :QueueLatency, :QueueSize
50
+ ]
44
51
  ```
45
52
 
46
53
  ## Installation
@@ -78,9 +85,13 @@ Speedshop::Cloudwatch.configure do |config|
78
85
  # Customize which Sidekiq queues to monitor (all queues by default)
79
86
  config.sidekiq_queues = ["critical", "default", "low_priority"]
80
87
 
88
+ # Customize which Solid Queue queues to monitor (all queues by default)
89
+ config.solid_queue_queues = ["critical", "default", "low_priority"]
90
+
81
91
  # Customize CloudWatch namespaces
82
92
  config.namespaces[:puma] = "MyApp/Puma"
83
93
  config.namespaces[:sidekiq] = "MyApp/Sidekiq"
94
+ config.namespaces[:solid_queue] = "MyApp/SolidQueue"
84
95
  config.namespaces[:rack] = "MyApp/Rack"
85
96
  config.namespaces[:active_job] = "MyApp/ActiveJob"
86
97
 
@@ -203,10 +214,40 @@ QueueSize - Size of each queue (Count) [per queue]
203
214
  Metrics marked [per queue] include a QueueName dimension.
204
215
  Utilization metrics include Tag and/or Hostname dimensions.
205
216
 
217
+ ## Solid Queue
218
+
219
+ This integration registers Solid Queue lifecycle hooks automatically. Each supervisor reports process metrics for only its own workers, like Puma reports per server. Every supervisor also reports the queue metrics, so they're duplicated; aggregate them with Average or Maximum. Solid Queue 1.6 or newer is required.
220
+
221
+ The integration also works with Solid Queue's Puma plugin in either fork or async mode.
222
+
223
+ By default, only `QueueLatency` is reported. To enable additional metrics, configure them explicitly:
224
+
225
+ ```ruby
226
+ Speedshop::Cloudwatch.configure do |config|
227
+ config.metrics[:solid_queue] = [
228
+ :Processes, :Workers, :Capacity, :Utilization,
229
+ :QueueLatency, :QueueSize
230
+ ]
231
+ end
232
+ ```
233
+
234
+ We report the following metrics:
235
+
236
+ ```
237
+ Processes - Number of live worker processes for this supervisor (Count)
238
+ Workers - Number of worker threads processing jobs for this supervisor (Count)
239
+ Capacity - Total worker threads across this supervisor's workers (Count)
240
+ Utilization - Average utilization across this supervisor's workers (Percent)
241
+ QueueLatency - Latency for each queue (Seconds) [per queue]
242
+ QueueSize - Size of each queue (Count) [per queue]
243
+ ```
244
+
245
+ Metrics marked [per queue] include a QueueName dimension.
246
+
206
247
  ## ActiveJob
207
248
 
208
249
  > [!WARNING]
209
- > If you're using Sidekiq, just use that integration and do not include the ActiveJob module.
250
+ > If you're using Sidekiq or Solid Queue, just use those integrations and do not include the ActiveJob module.
210
251
 
211
252
  In your ApplicationJob:
212
253
 
@@ -310,7 +351,7 @@ Speedshop::Cloudwatch.start!
310
351
 
311
352
  ## Disabling Automatic Integration
312
353
 
313
- You can disable the auto-integration of Sidekiq and Puma by not requiring them:
354
+ You can disable the auto-integration of Sidekiq, Solid Queue and Puma by not requiring them:
314
355
 
315
356
  ```ruby
316
357
  gem 'speedshop-cloudwatch', require: false
@@ -323,6 +364,7 @@ require 'speedshop/cloudwatch/puma'
323
364
  require 'speedshop/cloudwatch/active_job'
324
365
  require 'speedshop/cloudwatch/rack'
325
366
  # require 'speedshop/cloudwatch/sidekiq'
367
+ # require 'speedshop/cloudwatch/solid_queue'
326
368
  ```
327
369
 
328
370
  ## Bibliography
@@ -5,4 +5,5 @@ require "speedshop/cloudwatch/active_job"
5
5
  require "speedshop/cloudwatch/puma"
6
6
  require "speedshop/cloudwatch/rack"
7
7
  require "speedshop/cloudwatch/sidekiq"
8
+ require "speedshop/cloudwatch/solid_queue"
8
9
  require "speedshop/cloudwatch/railtie" if defined?(Rails)
@@ -9,7 +9,7 @@ module Speedshop
9
9
  include Singleton
10
10
 
11
11
  attr_accessor :interval, :metrics, :namespaces, :logger, :queue_max_size, :sidekiq_queues, :dimensions,
12
- :collectors, :enabled_environments, :environment
12
+ :solid_queue_queues, :collectors, :enabled_environments, :environment
13
13
  attr_writer :client
14
14
 
15
15
  def initialize
@@ -27,11 +27,13 @@ module Speedshop
27
27
  @metrics = {
28
28
  puma: [],
29
29
  sidekiq: [:QueueLatency],
30
+ solid_queue: [:QueueLatency],
30
31
  rack: [:RequestQueueTime],
31
32
  active_job: [:QueueLatency]
32
33
  }
33
- @namespaces = {puma: "Puma", sidekiq: "Sidekiq", rack: "Rack", active_job: "ActiveJob"}
34
+ @namespaces = {puma: "Puma", sidekiq: "Sidekiq", solid_queue: "SolidQueue", rack: "Rack", active_job: "ActiveJob"}
34
35
  @sidekiq_queues = nil
36
+ @solid_queue_queues = nil
35
37
  @dimensions = {}
36
38
  @logger = (defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger) ? Rails.logger : Logger.new($stdout)
37
39
  @collectors = [] # [:puma, :sidekiq]
@@ -155,6 +155,48 @@ module Speedshop
155
155
  )
156
156
  ],
157
157
 
158
+ solid_queue: [
159
+ Metric.new(
160
+ name: :Processes,
161
+ unit: "Count",
162
+ description: "Number of live Solid Queue worker processes for this supervisor.",
163
+ source: "Live worker processes for this supervisor"
164
+ ),
165
+ Metric.new(
166
+ name: :Workers,
167
+ unit: "Count",
168
+ description: "Number of worker threads currently processing jobs for this supervisor.",
169
+ source: "Sum of claimed executions across this supervisor's live worker processes"
170
+ ),
171
+ Metric.new(
172
+ name: :Capacity,
173
+ unit: "Count",
174
+ description: "Number of worker threads available across this supervisor's live workers.",
175
+ source: "Sum of process.metadata['pool_size'] across this supervisor's live worker processes"
176
+ ),
177
+ Metric.new(
178
+ name: :Utilization,
179
+ unit: "Percent",
180
+ description: "Average percentage of this supervisor's worker threads currently busy. 100% " \
181
+ "means all workers are busy.",
182
+ source: "Average of claimed executions / pool_size * 100 across this supervisor's live worker processes"
183
+ ),
184
+ Metric.new(
185
+ name: :QueueLatency,
186
+ unit: "Seconds",
187
+ description: "Time the oldest job in this queue has been waiting. High " \
188
+ "latency indicates jobs are backing up.",
189
+ source: "SolidQueue::Queue#latency"
190
+ ),
191
+ Metric.new(
192
+ name: :QueueSize,
193
+ unit: "Count",
194
+ description: "Number of jobs currently waiting in this queue. Growing " \
195
+ "size indicates jobs arriving faster than processing.",
196
+ source: "SolidQueue::Queue#size"
197
+ )
198
+ ],
199
+
158
200
  rack: [
159
201
  Metric.new(
160
202
  name: :RequestQueueTime,
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Speedshop
4
+ module Cloudwatch
5
+ module Observations
6
+ module SolidQueue
7
+ PROCESS_METRICS = %i[Processes Workers Capacity Utilization].freeze
8
+ QUEUE_METRICS = %i[QueueLatency QueueSize].freeze
9
+
10
+ module_function
11
+
12
+ def collect(supervisor_id:, solid_queue_queues: nil, metrics: PROCESS_METRICS + QUEUE_METRICS)
13
+ enabled = metrics.map(&:to_sym)
14
+ observations = []
15
+ observations.concat(process_observations(supervisor_id, metrics: enabled)) if (enabled & PROCESS_METRICS).any?
16
+ observations.concat(queue_observations(solid_queue_queues, metrics: enabled)) if (enabled & QUEUE_METRICS).any?
17
+ observations
18
+ end
19
+
20
+ def process_observations(supervisor_id, metrics: PROCESS_METRICS)
21
+ enabled = metrics.map(&:to_sym)
22
+ return [] if (enabled & PROCESS_METRICS).empty?
23
+
24
+ include_claimed = (enabled & %i[Workers Utilization]).any?
25
+ processes = live_worker_processes(supervisor_id, include_claimed: include_claimed)
26
+ return [] if processes.empty?
27
+
28
+ observations = []
29
+ observations << {metric: :Processes, value: processes.size} if enabled.include?(:Processes)
30
+ observations << {metric: :Workers, value: processes.sum { |process| process.claimed_executions.size }} if enabled.include?(:Workers)
31
+ observations << {metric: :Capacity, value: processes.sum { |process| pool_size(process).to_i }} if enabled.include?(:Capacity)
32
+
33
+ if enabled.include?(:Utilization)
34
+ utilization = avg_utilization(processes) * 100.0
35
+ observations << {metric: :Utilization, value: utilization} unless utilization.nan?
36
+ end
37
+
38
+ observations
39
+ end
40
+
41
+ def queue_observations(solid_queue_queues, metrics: QUEUE_METRICS)
42
+ enabled = metrics.map(&:to_sym)
43
+ include_latency = enabled.include?(:QueueLatency)
44
+ include_size = enabled.include?(:QueueSize)
45
+ return [] unless include_latency || include_size
46
+
47
+ queues_to_monitor(solid_queue_queues).flat_map do |queue|
48
+ observations = []
49
+ observations << {metric: :QueueLatency, value: queue.latency, dimensions: {QueueName: queue.name}} if include_latency
50
+ observations << {metric: :QueueSize, value: queue.size, dimensions: {QueueName: queue.name}} if include_size
51
+ observations
52
+ end
53
+ end
54
+
55
+ def queues_to_monitor(solid_queue_queues)
56
+ if solid_queue_queues.nil? || solid_queue_queues.empty?
57
+ ::SolidQueue::Queue.all
58
+ else
59
+ solid_queue_queues.map { |name| ::SolidQueue::Queue.find_by_name(name) }
60
+ end
61
+ end
62
+
63
+ def live_worker_processes(supervisor_id, include_claimed: true)
64
+ scope = ::SolidQueue::Process.where(
65
+ kind: "Worker",
66
+ supervisor_id: supervisor_id,
67
+ last_heartbeat_at: ::SolidQueue.process_alive_threshold.ago..
68
+ )
69
+ scope = scope.includes(:claimed_executions) if include_claimed
70
+ scope.to_a
71
+ end
72
+
73
+ def avg_utilization(processes)
74
+ utils = processes.filter_map do |process|
75
+ size = pool_size(process).to_f
76
+ next unless size > 0
77
+
78
+ process.claimed_executions.size / size
79
+ end
80
+ utils.sum / utils.size.to_f
81
+ end
82
+
83
+ def pool_size(process)
84
+ metadata = process.metadata || {}
85
+ metadata["pool_size"] || metadata["thread_pool_size"]
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -4,3 +4,4 @@ require "speedshop/cloudwatch/observations/active_job"
4
4
  require "speedshop/cloudwatch/observations/puma"
5
5
  require "speedshop/cloudwatch/observations/rack"
6
6
  require "speedshop/cloudwatch/observations/sidekiq"
7
+ require "speedshop/cloudwatch/observations/solid_queue"
@@ -23,13 +23,12 @@ module Speedshop
23
23
  end
24
24
 
25
25
  def start!
26
- return if !config.environment_enabled? || started?
26
+ return unless config.environment_enabled?
27
27
 
28
28
  @mutex.synchronize do
29
- return if started?
30
-
31
29
  reset_after_fork! if forked?
32
30
  initialize_collectors
31
+ return if started?
33
32
 
34
33
  Speedshop::Cloudwatch.log_info("Starting metric reporter (collectors: #{@collectors.map(&:class).join(", ")})")
35
34
  @running = true
@@ -128,13 +127,16 @@ module Speedshop
128
127
  end
129
128
 
130
129
  def initialize_collectors
131
- config.collectors.each do |integration|
132
- @collectors << Speedshop::Cloudwatch::Puma.new if integration == :puma
133
- @collectors << Speedshop::Cloudwatch::Sidekiq.new if integration == :sidekiq
134
- @collectors << Speedshop::Cloudwatch::Yabeda::Collector.new if integration == :yabeda
130
+ collectors = []
131
+ config.collectors.uniq.each do |integration|
132
+ collectors << Speedshop::Cloudwatch::Puma.new if integration == :puma
133
+ collectors << Speedshop::Cloudwatch::Sidekiq.new if integration == :sidekiq
134
+ collectors << Speedshop::Cloudwatch::SolidQueue.new if integration == :solid_queue
135
+ collectors << Speedshop::Cloudwatch::Yabeda::Collector.new if integration == :yabeda
135
136
  rescue => e
136
137
  Speedshop::Cloudwatch.log_error("Failed to initialize collector for #{integration}: #{e.message}", e)
137
138
  end
139
+ @collectors = collectors
138
140
  end
139
141
 
140
142
  def run_loop
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "speedshop/cloudwatch/observations"
4
+
5
+ module Speedshop
6
+ module Cloudwatch
7
+ class SolidQueue
8
+ class << self
9
+ attr_accessor :supervisor
10
+
11
+ def setup_lifecycle_hooks
12
+ ::SolidQueue.on_start do |supervisor|
13
+ Speedshop::Cloudwatch::SolidQueue.supervisor = supervisor
14
+ Speedshop::Cloudwatch.configure do |c|
15
+ c.collectors << :solid_queue unless c.collectors.include?(:solid_queue)
16
+ end
17
+ Speedshop::Cloudwatch.start!
18
+ end
19
+
20
+ ::SolidQueue.on_exit { |supervisor| Speedshop::Cloudwatch.stop! if supervisor.standalone? }
21
+ end
22
+ end
23
+
24
+ def collect
25
+ supervisor = self.class.supervisor
26
+ return unless supervisor&.pid == ::Process.pid
27
+
28
+ enabled_metrics = Config.instance.metrics[:solid_queue]
29
+ return if enabled_metrics.nil? || enabled_metrics.empty?
30
+
31
+ observations = ::SolidQueue::Record.connection_pool.with_connection do
32
+ Observations::SolidQueue.collect(
33
+ supervisor_id: supervisor.process_id,
34
+ solid_queue_queues: Config.instance.solid_queue_queues,
35
+ metrics: enabled_metrics
36
+ )
37
+ end
38
+ observations.each do |observation|
39
+ metric_mapper.report(
40
+ metric: observation[:metric],
41
+ value: observation[:value],
42
+ dimensions: observation[:dimensions] || {},
43
+ integration: :solid_queue
44
+ )
45
+ end
46
+ rescue => e
47
+ Speedshop::Cloudwatch.log_error("Failed to collect Solid Queue metrics: #{e.message}", e)
48
+ end
49
+
50
+ private
51
+
52
+ def metric_mapper
53
+ Speedshop::Cloudwatch.metric_mapper
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ ActiveSupport.on_load(:solid_queue) { Speedshop::Cloudwatch::SolidQueue.setup_lifecycle_hooks } if defined?(ActiveSupport)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Speedshop
4
4
  module Cloudwatch
5
- VERSION = "0.2.2"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: speedshop-cloudwatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Berkopec
@@ -78,12 +78,14 @@ files:
78
78
  - lib/speedshop/cloudwatch/observations/puma.rb
79
79
  - lib/speedshop/cloudwatch/observations/rack.rb
80
80
  - lib/speedshop/cloudwatch/observations/sidekiq.rb
81
+ - lib/speedshop/cloudwatch/observations/solid_queue.rb
81
82
  - lib/speedshop/cloudwatch/puma.rb
82
83
  - lib/speedshop/cloudwatch/rack.rb
83
84
  - lib/speedshop/cloudwatch/railtie.rb
84
85
  - lib/speedshop/cloudwatch/reporter.rb
85
86
  - lib/speedshop/cloudwatch/request_size.rb
86
87
  - lib/speedshop/cloudwatch/sidekiq.rb
88
+ - lib/speedshop/cloudwatch/solid_queue.rb
87
89
  - lib/speedshop/cloudwatch/version.rb
88
90
  - lib/speedshop/cloudwatch/yabeda.rb
89
91
  - speedshop-cloudwatch.gemspec
@@ -108,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
110
  - !ruby/object:Gem::Version
109
111
  version: '0'
110
112
  requirements: []
111
- rubygems_version: 3.6.9
113
+ rubygems_version: 4.0.20
112
114
  specification_version: 4
113
115
  summary: Ruby application integration with AWS CloudWatch for Puma, Rack, Sidekiq,
114
116
  and ActiveJob