summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/workers/update_merge_requests_worker.rb7
-rw-r--r--changelogs/unreleased/35914-merge-request-update-worker-is-slow.yml5
-rw-r--r--lib/gitlab/metrics/sidekiq_middleware.rb2
-rw-r--r--spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb6
4 files changed, 13 insertions, 7 deletions
diff --git a/app/workers/update_merge_requests_worker.rb b/app/workers/update_merge_requests_worker.rb
index f1e43bea8b3..e364fb698d3 100644
--- a/app/workers/update_merge_requests_worker.rb
+++ b/app/workers/update_merge_requests_worker.rb
@@ -2,10 +2,10 @@ class UpdateMergeRequestsWorker
include Sidekiq::Worker
include DedicatedSidekiqQueue
- attr_reader :targets # for metrics tags
+ attr_reader :metrics_tags
def initialize
- @targets = {}
+ @metrics_tags = {}
end
def perform(project_id, user_id, oldrev, newrev, ref)
@@ -15,10 +15,11 @@ class UpdateMergeRequestsWorker
user = User.find_by(id: user_id)
return unless user
- @targets = {
+ @metrics_tags = {
project_id: project_id,
user_id: user_id
}
+
MergeRequests::RefreshService.new(project, user).execute(oldrev, newrev, ref)
end
end
diff --git a/changelogs/unreleased/35914-merge-request-update-worker-is-slow.yml b/changelogs/unreleased/35914-merge-request-update-worker-is-slow.yml
new file mode 100644
index 00000000000..34bb76195af
--- /dev/null
+++ b/changelogs/unreleased/35914-merge-request-update-worker-is-slow.yml
@@ -0,0 +1,5 @@
+---
+title: Add metric tagging for sidekiq workers
+merge_request: 15111
+author:
+type: added
diff --git a/lib/gitlab/metrics/sidekiq_middleware.rb b/lib/gitlab/metrics/sidekiq_middleware.rb
index 2febd79e547..b983a40611f 100644
--- a/lib/gitlab/metrics/sidekiq_middleware.rb
+++ b/lib/gitlab/metrics/sidekiq_middleware.rb
@@ -12,7 +12,7 @@ module Gitlab
trans.set(:sidekiq_queue_duration, Time.now.to_f - (message['enqueued_at'] || message['created_at'] || 0))
trans.run { yield }
- worker.targets.each { |name, target| trans.add_tag(name, target) } if worker.respond_to?(:targets)
+ worker.metrics_tags.each { |tag, value| trans.add_tag(tag, value) } if worker.respond_to?(:metrics_tags)
rescue Exception => error # rubocop: disable Lint/RescueException
trans.add_event(:sidekiq_exception)
diff --git a/spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb b/spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb
index 196e0fadda2..0803ce42fac 100644
--- a/spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb
+++ b/spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb
@@ -47,11 +47,11 @@ describe Gitlab::Metrics::SidekiqMiddleware do
end
it 'tags the metrics accordingly' do
- targets = { one: 1, two: 2 }
+ tags = { one: 1, two: 2 }
worker = double(:worker, class: double(:class, name: 'TestWorker'))
- allow(worker).to receive(:targets).and_return(targets)
+ allow(worker).to receive(:metrics_tags).and_return(tags)
- targets.each do |tag, value|
+ tags.each do |tag, value|
expect_any_instance_of(Gitlab::Metrics::Transaction).to receive(:add_tag)
.with(tag, value)
end