I was wondering if you'd be open to extending Sidekiq::Middleware::Server::Statsd a bit?
First, @options isn't used at all from the initializer. How about we lose the options hash, and use a keyword argument for tags: {}? Then do something like...
@tags.merge!(worker: w, queue: queue)
tags_array = @tags.each_with_object([]) { |(k, v), o| o << "#{k}:#{v.is_a?(Proc) ? v.call : v}" }
then use tags: tags_array in the various places it's used.
Second, queue time. I made my own middleware, but feels like something that should be measured out of the box?
@statsd.batch do |b|
if msg['enqueued_at']
queued_ms = ((start - Time.at(msg['enqueued_at'])) * 1000).round
b.timing("jobs.queue", queued_ms, tags: tags_array)
end
end
Thanks, Mike!
I'd suggest you upgrade to 5.2.0 as there have been statsd changes since 5.0.0. Then, update your issue based on the latest code.
That said, I'm very happy to consider requests like this!
Gah! Another version issue. So, I don't think we're comfortable migrating to 6.0 just yet... I'll work on that.
Bundler could not find compatible versions for gem "sidekiq":
In Gemfile:
sidekiq-pro (~> 5.2.0) was resolved to 5.2.0, which depends on
sidekiq (>= 6.1.0)
Looking at the code for 5.2.0, and still seems like most of my request holds. I'll update the original!
Job latency is better expressed as queue latency, which is available in the API and via Ent's Historical Metrics. The default queue latency is stored out of the box but you can add others.
https://github.com/mperham/sidekiq/wiki/Ent-Historical-Metrics#custom
The global Statsd client initializer can take global tags to add to each metric, I don't see any reason to add a special case only for the middleware:
Sidekiq::Pro.dogstatsd = ->{ Datadog::Statsd.new("metrics.example.com", 8125, tags: ["foo:bar", "env:production"]) }
queues = ::Sidekiq::Queue.all
config.retain_history(30) do |s|
s.batch do |b|
queues.each do |queue|
b.gauge('sidekiq.queue.latency', queue.latency, tags: ["queue:#{queue.name}", "paused:#{queue.paused?}"])
end
end
end
Just to make sure I grab them all. Thanks for pointing me in the right direction!