Move LogWorkerQueueStats from labor to services (#11642)
This commit is contained in:
parent
aba7204664
commit
06fd95f93f
4 changed files with 11 additions and 9 deletions
|
|
@ -1,7 +1,7 @@
|
|||
module Loggers
|
||||
class LogWorkerQueueStats
|
||||
class << self
|
||||
def run
|
||||
def call
|
||||
queues = Sidekiq::Queue.all.map(&:itself)
|
||||
record_totals(queues)
|
||||
record_queue_stats(queues)
|
||||
|
|
@ -10,12 +10,14 @@ module Loggers
|
|||
private
|
||||
|
||||
def record_totals(queues)
|
||||
log_to_datadog("sidekiq.queues.total_size", queues.map(&:size).sum)
|
||||
log_to_datadog("sidekiq.queues.total_size", queues.sum(&:size))
|
||||
log_to_datadog("sidekiq.queues.total_workers", Sidekiq::Workers.new.size)
|
||||
end
|
||||
|
||||
def record_queue_stats(queues)
|
||||
queue_hash = queues.map { |queue| [queue.name, { size: queue.size, latency: queue.latency }] }.to_h
|
||||
queue_hash = queues.map do |queue|
|
||||
[queue.name, { size: queue.size, latency: queue.latency }]
|
||||
end.to_h
|
||||
queue_hash.each do |queue_name, queue_values|
|
||||
latency = queue_values.fetch(:latency, 0)
|
||||
size = queue_values.fetch(:size, 0)
|
||||
|
|
@ -4,7 +4,7 @@ module Metrics
|
|||
sidekiq_options queue: :low_priority, retry: 10
|
||||
|
||||
def perform
|
||||
Loggers::LogWorkerQueueStats.run
|
||||
Loggers::LogWorkerQueueStats.call
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe Loggers::LogWorkerQueueStats do
|
||||
describe Loggers::LogWorkerQueueStats, type: :service do
|
||||
it "logs totals" do
|
||||
allow(described_class).to receive(:record_totals)
|
||||
described_class.run
|
||||
described_class.call
|
||||
expect(described_class).to have_received(:record_totals)
|
||||
end
|
||||
|
||||
it "logs queue stats" do
|
||||
allow(described_class).to receive(:record_queue_stats)
|
||||
described_class.run
|
||||
described_class.call
|
||||
expect(described_class).to have_received(:record_queue_stats)
|
||||
end
|
||||
end
|
||||
|
|
@ -5,10 +5,10 @@ RSpec.describe Metrics::RecordBackgroundQueueStatsWorker, type: :worker do
|
|||
|
||||
describe "#perform" do
|
||||
it "logs estimated counts in Datadog" do
|
||||
allow(Loggers::LogWorkerQueueStats).to receive(:run)
|
||||
allow(Loggers::LogWorkerQueueStats).to receive(:call)
|
||||
described_class.new.perform
|
||||
|
||||
expect(Loggers::LogWorkerQueueStats).to have_received(:run)
|
||||
expect(Loggers::LogWorkerQueueStats).to have_received(:call)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue