Class: RequestQueueTime::AutoScalingMetrics::SidekiqReporter
- Inherits:
-
Object
- Object
- RequestQueueTime::AutoScalingMetrics::SidekiqReporter
- Defined in:
- lib/services/auto_scaling_metrics/sidekiq_reporter.rb
Class Method Summary collapse
- .collect_metrics(required_queues = []) ⇒ Object
-
.enable(required_queues: []) ⇒ Object
‘required_queues` lists queue names that must always publish a datapoint, even when Redis has no entry for them.
Class Method Details
.collect_metrics(required_queues = []) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/services/auto_scaling_metrics/sidekiq_reporter.rb', line 18 def self.collect_metrics(required_queues = []) live_queues = Sidekiq::Queue.all.to_h { |q| [q.name, q] } names = (required_queues + live_queues.keys).uniq names.each do |name| queue = live_queues[name] AutoScalingMetrics::Reporter.add_metric( metric_name: "sidekiq_queue_latency", value: (queue.nil? || queue.paused?) ? 0 : queue.latency, unit: "Seconds", dimensions: [{name: "queue_name", value: name}] ) end end |
.enable(required_queues: []) ⇒ Object
‘required_queues` lists queue names that must always publish a datapoint, even when Redis has no entry for them. Without this, a queue with a CloudWatch autoscaling policy that never enqueues sits permanently in INSUFFICIENT_DATA, blocking scale-in for the whole service.
8 9 10 11 12 13 14 15 16 |
# File 'lib/services/auto_scaling_metrics/sidekiq_reporter.rb', line 8 def self.enable(required_queues: []) Sidekiq.configure_server do |config| config.on(:leader) do AutoScalingMetrics::Reporter.start do |reporter| reporter.collector = -> { collect_metrics(required_queues) } end end end end |