summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-11-15 09:20:15 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-11-15 09:20:15 +0000
commit5c600294a26ae8df430f64d73753d6eaadd9e427 (patch)
tree28b5e0ff86cf7adb9cd435723111e8c33c4794ff
parent068f9df2bdf8b758360dbb81a449986b2636bc3b (diff)
parent45c373caf570cee7ef3b51d0709c01cc3df3a818 (diff)
downloadgitlab-ce-5c600294a26ae8df430f64d73753d6eaadd9e427.tar.gz
Merge branch 'update-merge-worker-metrics' into 'master'
Add simple logging to UpdateMergeRequestsWorker#perform See merge request gitlab-org/gitlab-ce!15360
-rw-r--r--app/workers/update_merge_requests_worker.rb18
-rw-r--r--changelogs/unreleased/update-merge-worker-metrics.yml5
-rw-r--r--spec/workers/update_merge_requests_worker_spec.rb12
3 files changed, 34 insertions, 1 deletions
diff --git a/app/workers/update_merge_requests_worker.rb b/app/workers/update_merge_requests_worker.rb
index 89ae17cef37..afc47fc63d6 100644
--- a/app/workers/update_merge_requests_worker.rb
+++ b/app/workers/update_merge_requests_worker.rb
@@ -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
@@ -9,6 +11,20 @@ class UpdateMergeRequestsWorker
user = User.find_by(id: user_id)
return unless user
- MergeRequests::RefreshService.new(project, user).execute(oldrev, newrev, ref)
+ # TODO: remove this benchmarking when we have rich logging
+ time = Benchmark.measure do
+ MergeRequests::RefreshService.new(project, user).execute(oldrev, newrev, ref)
+ 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 #{args_log}") if time.real > LOG_TIME_THRESHOLD
end
end
diff --git a/changelogs/unreleased/update-merge-worker-metrics.yml b/changelogs/unreleased/update-merge-worker-metrics.yml
new file mode 100644
index 00000000000..c733675926a
--- /dev/null
+++ b/changelogs/unreleased/update-merge-worker-metrics.yml
@@ -0,0 +1,5 @@
+---
+title: Add performance logging to UpdateMergeRequestsWorker.
+merge_request: 15360
+author:
+type: performance
diff --git a/spec/workers/update_merge_requests_worker_spec.rb b/spec/workers/update_merge_requests_worker_spec.rb
index 558ff9109ec..0fa19ac84bb 100644
--- a/spec/workers/update_merge_requests_worker_spec.rb
+++ b/spec/workers/update_merge_requests_worker_spec.rb
@@ -23,5 +23,17 @@ describe UpdateMergeRequestsWorker do
perform
end
+
+ context 'when slow' do
+ before do
+ stub_const("UpdateMergeRequestsWorker::LOG_TIME_THRESHOLD", -1)
+ end
+
+ 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