rework the logging to be simpler and add a threshold
This commit is contained in:
parent
a579bc59b0
commit
0b4a7d656b
2 changed files with 21 additions and 9 deletions
|
@ -2,6 +2,8 @@ class UpdateMergeRequestsWorker
|
|||
include Sidekiq::Worker
|
||||
include DedicatedSidekiqQueue
|
||||
|
||||
LOG_TIME_THRESHOLD = 90 # seconds
|
||||
|
||||
def perform(project_id, user_id, oldrev, newrev, ref)
|
||||
project = Project.find_by(id: project_id)
|
||||
return unless project
|
||||
|
@ -14,12 +16,16 @@ class UpdateMergeRequestsWorker
|
|||
MergeRequests::RefreshService.new(project, user).execute(oldrev, newrev, ref)
|
||||
end
|
||||
|
||||
log_args = ["elapsed=#{time.real}"]
|
||||
method(__method__).parameters.map do |_, p|
|
||||
pname = p.to_s
|
||||
log_args << [pname, binding.local_variable_get(pname)].join('=')
|
||||
end
|
||||
args_log = [
|
||||
"elapsed=#{time.real}",
|
||||
"project_id=#{project_id}",
|
||||
"user_id=#{user_id}",
|
||||
"oldrev=#{oldrev}",
|
||||
"newrev=#{newrev}",
|
||||
"ref=#{ref}"
|
||||
].join(',')
|
||||
|
||||
Rails.logger.info("UpdateMergeRequestsWorker#perform #{log_args.join(',')}")
|
||||
Rails.logger.info("UpdateMergeRequestsWorker#perform #{args_log}") if time.real > LOG_TIME_THRESHOLD
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -24,10 +24,16 @@ describe UpdateMergeRequestsWorker do
|
|||
perform
|
||||
end
|
||||
|
||||
it 'logs performance' do
|
||||
expect(Rails.logger).to receive(:info).with(a_string_matching(/\AUpdateMergeRequestsWorker#perform.*project_id=#{project.id},user_id=#{user.id},oldrev=#{oldrev},newrev=#{newrev},ref=#{ref}/))
|
||||
context 'when slow' do
|
||||
before do
|
||||
stub_const("UpdateMergeRequestsWorker::LOG_TIME_THRESHOLD", -1)
|
||||
end
|
||||
|
||||
perform
|
||||
it 'logs debug info' do
|
||||
expect(Rails.logger).to receive(:info).with(a_string_matching(/\AUpdateMergeRequestsWorker#perform.*project_id=#{project.id},user_id=#{user.id},oldrev=#{oldrev},newrev=#{newrev},ref=#{ref}/))
|
||||
|
||||
perform
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue