Commit edc3ccee authored by Imre Farkas's avatar Imre Farkas

Add deduplication options of the worker to logs

parent aff2c0b0
......@@ -6,11 +6,14 @@ module Gitlab
include Singleton
include LogsJobs
def log(job, deduplication_type)
def log(job, deduplication_type, deduplication_options = {})
payload = parse_job(job)
payload['job_status'] = 'deduplicated'
payload['message'] = "#{base_message(payload)}: deduplicated: #{deduplication_type}"
payload['deduplication_type'] = deduplication_type
payload['deduplication.type'] = deduplication_type
# removing nil values from deduplication options
payload.merge!(
deduplication_options.compact.transform_keys { |k| "deduplication.options.#{k}" })
Sidekiq.logger.info payload
end
......
......@@ -17,7 +17,8 @@ module Gitlab
job['duplicate-of'] = duplicate_job.existing_jid
if duplicate_job.droppable?
Gitlab::SidekiqLogging::DeduplicationLogger.instance.log(job, "dropped until executing")
Gitlab::SidekiqLogging::DeduplicationLogger.instance.log(
job, "dropped until executing", duplicate_job.options)
return false
end
end
......
......@@ -18,11 +18,12 @@ RSpec.describe Gitlab::SidekiqLogging::DeduplicationLogger do
expected_payload = {
'job_status' => 'deduplicated',
'message' => "#{job['class']} JID-#{job['jid']}: deduplicated: a fancy strategy",
'deduplication_type' => 'a fancy strategy'
'deduplication.type' => 'a fancy strategy',
'deduplication.options.foo' => :bar
}
expect(Sidekiq.logger).to receive(:info).with(a_hash_including(expected_payload)).and_call_original
described_class.instance.log(job, "a fancy strategy")
described_class.instance.log(job, "a fancy strategy", { foo: :bar })
end
it "does not modify the job" do
......
......@@ -40,6 +40,7 @@ RSpec.describe Gitlab::SidekiqMiddleware::DuplicateJobs::Strategies::UntilExecut
allow(fake_duplicate_job).to receive(:scheduled?).and_return(false)
allow(fake_duplicate_job).to receive(:check!).and_return('the jid')
allow(fake_duplicate_job).to receive(:droppable?).and_return(true)
allow(fake_duplicate_job).to receive(:options).and_return({})
job_hash = {}
expect(fake_duplicate_job).to receive(:duplicate?).and_return(true)
......@@ -102,6 +103,7 @@ RSpec.describe Gitlab::SidekiqMiddleware::DuplicateJobs::Strategies::UntilExecut
allow(fake_duplicate_job).to receive(:scheduled?).and_return(false)
allow(fake_duplicate_job).to receive(:check!).and_return('the jid')
allow(fake_duplicate_job).to receive(:duplicate?).and_return(true)
allow(fake_duplicate_job).to receive(:options).and_return({})
allow(fake_duplicate_job).to receive(:existing_jid).and_return('the jid')
allow(fake_duplicate_job).to receive(:droppable?).and_return(true)
end
......@@ -119,7 +121,17 @@ RSpec.describe Gitlab::SidekiqMiddleware::DuplicateJobs::Strategies::UntilExecut
fake_logger = instance_double(Gitlab::SidekiqLogging::DeduplicationLogger)
expect(Gitlab::SidekiqLogging::DeduplicationLogger).to receive(:instance).and_return(fake_logger)
expect(fake_logger).to receive(:log).with(a_hash_including({ 'jid' => 'new jid' }), 'dropped until executing')
expect(fake_logger).to receive(:log).with(a_hash_including({ 'jid' => 'new jid' }), 'dropped until executing', {})
strategy.schedule({ 'jid' => 'new jid' }) {}
end
it 'logs the deduplication options of the worker' do
fake_logger = instance_double(Gitlab::SidekiqLogging::DeduplicationLogger)
expect(Gitlab::SidekiqLogging::DeduplicationLogger).to receive(:instance).and_return(fake_logger)
allow(fake_duplicate_job).to receive(:options).and_return({ foo: :bar })
expect(fake_logger).to receive(:log).with(a_hash_including({ 'jid' => 'new jid' }), 'dropped until executing', { foo: :bar })
strategy.schedule({ 'jid' => 'new jid' }) {}
end
......
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