Commit b2c592cd authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'if-222783-scheduled_deduplication_log' into 'master'

Add deduplication options of the worker to logs

See merge request gitlab-org/gitlab!36731
parents 4a3e182f edc3ccee
...@@ -6,11 +6,14 @@ module Gitlab ...@@ -6,11 +6,14 @@ module Gitlab
include Singleton include Singleton
include LogsJobs include LogsJobs
def log(job, deduplication_type) def log(job, deduplication_type, deduplication_options = {})
payload = parse_job(job) payload = parse_job(job)
payload['job_status'] = 'deduplicated' payload['job_status'] = 'deduplicated'
payload['message'] = "#{base_message(payload)}: deduplicated: #{deduplication_type}" 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 Sidekiq.logger.info payload
end end
......
...@@ -17,7 +17,8 @@ module Gitlab ...@@ -17,7 +17,8 @@ module Gitlab
job['duplicate-of'] = duplicate_job.existing_jid job['duplicate-of'] = duplicate_job.existing_jid
if duplicate_job.droppable? 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 return false
end end
end end
......
...@@ -18,11 +18,12 @@ RSpec.describe Gitlab::SidekiqLogging::DeduplicationLogger do ...@@ -18,11 +18,12 @@ RSpec.describe Gitlab::SidekiqLogging::DeduplicationLogger do
expected_payload = { expected_payload = {
'job_status' => 'deduplicated', 'job_status' => 'deduplicated',
'message' => "#{job['class']} JID-#{job['jid']}: deduplicated: a fancy strategy", '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 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 end
it "does not modify the job" do it "does not modify the job" do
......
...@@ -40,6 +40,7 @@ RSpec.describe Gitlab::SidekiqMiddleware::DuplicateJobs::Strategies::UntilExecut ...@@ -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(:scheduled?).and_return(false)
allow(fake_duplicate_job).to receive(:check!).and_return('the jid') 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(:droppable?).and_return(true)
allow(fake_duplicate_job).to receive(:options).and_return({})
job_hash = {} job_hash = {}
expect(fake_duplicate_job).to receive(:duplicate?).and_return(true) expect(fake_duplicate_job).to receive(:duplicate?).and_return(true)
...@@ -102,6 +103,7 @@ RSpec.describe Gitlab::SidekiqMiddleware::DuplicateJobs::Strategies::UntilExecut ...@@ -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(:scheduled?).and_return(false)
allow(fake_duplicate_job).to receive(:check!).and_return('the jid') 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(: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(:existing_jid).and_return('the jid')
allow(fake_duplicate_job).to receive(:droppable?).and_return(true) allow(fake_duplicate_job).to receive(:droppable?).and_return(true)
end end
...@@ -119,7 +121,17 @@ RSpec.describe Gitlab::SidekiqMiddleware::DuplicateJobs::Strategies::UntilExecut ...@@ -119,7 +121,17 @@ RSpec.describe Gitlab::SidekiqMiddleware::DuplicateJobs::Strategies::UntilExecut
fake_logger = instance_double(Gitlab::SidekiqLogging::DeduplicationLogger) fake_logger = instance_double(Gitlab::SidekiqLogging::DeduplicationLogger)
expect(Gitlab::SidekiqLogging::DeduplicationLogger).to receive(:instance).and_return(fake_logger) 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' }) {} strategy.schedule({ 'jid' => 'new jid' }) {}
end 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