Commit 8951a54a authored by Etienne Baqué's avatar Etienne Baqué

Merge branch...

Merge branch '337351-use-structured-logging-for-mergerequestmergeabilitycheckworker-2' into 'master'

Use Structured Logging for MergeRequestMergeabilityCheckWorker

See merge request gitlab-org/gitlab!67440
parents b302b2b2 d971a728
...@@ -14,7 +14,7 @@ class MergeRequestMergeabilityCheckWorker ...@@ -14,7 +14,7 @@ class MergeRequestMergeabilityCheckWorker
merge_request = MergeRequest.find_by_id(merge_request_id) merge_request = MergeRequest.find_by_id(merge_request_id)
unless merge_request unless merge_request
logger.error("Failed to find merge request with ID: #{merge_request_id}") Sidekiq.logger.error(worker: self.class.name, message: "Failed to find merge request", merge_request_id: merge_request_id)
return return
end end
...@@ -23,6 +23,6 @@ class MergeRequestMergeabilityCheckWorker ...@@ -23,6 +23,6 @@ class MergeRequestMergeabilityCheckWorker
.new(merge_request) .new(merge_request)
.execute(recheck: false, retry_lease: false) .execute(recheck: false, retry_lease: false)
logger.error("Failed to check mergeability of merge request (#{merge_request_id}): #{result.message}") if result.error? Sidekiq.logger.error(worker: self.class.name, message: "Failed to check mergeability of merge request: #{result.message}", merge_request_id: merge_request_id) if result.error?
end end
end end
...@@ -10,6 +10,12 @@ RSpec.describe MergeRequestMergeabilityCheckWorker do ...@@ -10,6 +10,12 @@ RSpec.describe MergeRequestMergeabilityCheckWorker do
it 'does not execute MergeabilityCheckService' do it 'does not execute MergeabilityCheckService' do
expect(MergeRequests::MergeabilityCheckService).not_to receive(:new) expect(MergeRequests::MergeabilityCheckService).not_to receive(:new)
expect(Sidekiq.logger).to receive(:error).once
.with(
merge_request_id: 1,
worker: "MergeRequestMergeabilityCheckWorker",
message: 'Failed to find merge request')
subject.perform(1) subject.perform(1)
end end
end end
...@@ -24,6 +30,20 @@ RSpec.describe MergeRequestMergeabilityCheckWorker do ...@@ -24,6 +30,20 @@ RSpec.describe MergeRequestMergeabilityCheckWorker do
subject.perform(merge_request.id) subject.perform(merge_request.id)
end end
it 'structurally logs a failed mergeability check' do
expect_next_instance_of(MergeRequests::MergeabilityCheckService, merge_request) do |service|
expect(service).to receive(:execute).and_return(double(error?: true, message: "solar flares"))
end
expect(Sidekiq.logger).to receive(:error).once
.with(
merge_request_id: merge_request.id,
worker: "MergeRequestMergeabilityCheckWorker",
message: 'Failed to check mergeability of merge request: solar flares')
subject.perform(merge_request.id)
end
end end
it_behaves_like 'an idempotent worker' do it_behaves_like 'an idempotent worker' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment