FEATURE: Optional detailed performance logging for Sidekiq jobs (#7091)

By default, this does nothing. Two environment variables are available:

- `DISCOURSE_LOG_SIDEKIQ`

  Set to `"1"` to enable logging. This will log all completed jobs to `log/rails/sidekiq.log`, along with various db/redis/network statistics. This is useful to track down poorly performing jobs.

- `DISCOURSE_LOG_SIDEKIQ_INTERVAL`

  (seconds) Check running jobs periodically, and log their current duration. They will appear in the logs with `status:pending`. This is useful to track down jobs which take a long time, then crash sidekiq before completing.
This commit is contained in:
David Taylor
2019-03-05 11:19:11 +00:00
committed by GitHub
parent 73e4204d20
commit 8963f1af30
3 changed files with 108 additions and 47 deletions

View File

@@ -15,26 +15,7 @@ class Middleware::RequestTracker
# # do stuff with env and data
# end
def self.register_detailed_request_logger(callback)
unless @patched_instrumentation
MethodProfiler.patch(PG::Connection, [
:exec, :async_exec, :exec_prepared, :send_query_prepared, :query, :exec_params
], :sql)
MethodProfiler.patch(Redis::Client, [
:call, :call_pipeline
], :redis)
MethodProfiler.patch(Net::HTTP, [
:request
], :net, no_recurse: true)
MethodProfiler.patch(Excon::Connection, [
:request
], :net)
@patched_instrumentation = true
end
MethodProfiler.ensure_discourse_instrumentation!
(@@detailed_request_loggers ||= []) << callback
end