Commit d971a728 authored by Gary Holtz's avatar Gary Holtz

Add structured logging to MergeRequestMergeabilityCheckWorker

Changelog: added
parent 2afa9308
......@@ -14,7 +14,7 @@ class MergeRequestMergeabilityCheckWorker
merge_request = MergeRequest.find_by_id(merge_request_id)
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
end
......@@ -23,6 +23,6 @@ class MergeRequestMergeabilityCheckWorker
.new(merge_request)
.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
......@@ -10,6 +10,12 @@ RSpec.describe MergeRequestMergeabilityCheckWorker do
it 'does not execute MergeabilityCheckService' do
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)
end
end
......@@ -24,6 +30,20 @@ RSpec.describe MergeRequestMergeabilityCheckWorker do
subject.perform(merge_request.id)
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
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