Commit 88ea06c8 authored by Matthias Kaeppler's avatar Matthias Kaeppler

Fix missing data_consistency field in job hash

This was being emitted to Prometheus but never set.
parent 1c6c3b8b
...@@ -32,10 +32,13 @@ module Gitlab ...@@ -32,10 +32,13 @@ module Gitlab
return true unless location return true unless location
job_data_consistency = worker_class.get_data_consistency
job[:data_consistency] = job_data_consistency.to_s
if replica_caught_up?(location) if replica_caught_up?(location)
job[:database_chosen] = 'replica' job[:database_chosen] = 'replica'
false false
elsif worker_class.get_data_consistency == :delayed && not_yet_retried?(job) elsif job_data_consistency == :delayed && not_yet_retried?(job)
job[:database_chosen] = 'retry' job[:database_chosen] = 'retry'
raise JobReplicaNotUpToDate, "Sidekiq job #{worker_class} JID-#{job['jid']} couldn't use the replica."\ raise JobReplicaNotUpToDate, "Sidekiq job #{worker_class} JID-#{job['jid']} couldn't use the replica."\
" Replica was not up to date." " Replica was not up to date."
......
...@@ -31,14 +31,6 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqServerMiddleware do ...@@ -31,14 +31,6 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqServerMiddleware do
end end
end end
shared_examples_for 'job marked with chosen database' do
it 'yields and sets database chosen', :aggregate_failures do
expect { |b| middleware.call(worker, job, double(:queue), &b) }.to yield_control
expect(job[:database_chosen]).to eq('primary')
end
end
shared_examples_for 'stick to the primary' do shared_examples_for 'stick to the primary' do
it 'sticks to the primary' do it 'sticks to the primary' do
middleware.call(worker, job, double(:queue)) do middleware.call(worker, job, double(:queue)) do
...@@ -47,8 +39,8 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqServerMiddleware do ...@@ -47,8 +39,8 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqServerMiddleware do
end end
end end
shared_examples_for 'replica is up to date' do |location| shared_examples_for 'replica is up to date' do |location, data_consistency|
it 'do not stick to the primary', :aggregate_failures do it 'does not stick to the primary', :aggregate_failures do
expect(middleware).to receive(:replica_caught_up?).with(location).and_return(true) expect(middleware).to receive(:replica_caught_up?).with(location).and_return(true)
middleware.call(worker, job, double(:queue)) do middleware.call(worker, job, double(:queue)) do
...@@ -57,6 +49,12 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqServerMiddleware do ...@@ -57,6 +49,12 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqServerMiddleware do
expect(job[:database_chosen]).to eq('replica') expect(job[:database_chosen]).to eq('replica')
end end
it "updates job hash with data_consistency :#{data_consistency}" do
middleware.call(worker, job, double(:queue)) do
expect(job).to include(data_consistency: data_consistency.to_s)
end
end
end end
shared_examples_for 'sticks based on data consistency' do |data_consistency| shared_examples_for 'sticks based on data consistency' do |data_consistency|
...@@ -77,7 +75,7 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqServerMiddleware do ...@@ -77,7 +75,7 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqServerMiddleware do
allow(middleware).to receive(:replica_caught_up?).and_return(true) allow(middleware).to receive(:replica_caught_up?).and_return(true)
end end
it_behaves_like 'replica is up to date', '0/D525E3A8' it_behaves_like 'replica is up to date', '0/D525E3A8', data_consistency
end end
context 'when database primary location is set' do context 'when database primary location is set' do
...@@ -87,7 +85,7 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqServerMiddleware do ...@@ -87,7 +85,7 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqServerMiddleware do
allow(middleware).to receive(:replica_caught_up?).and_return(true) allow(middleware).to receive(:replica_caught_up?).and_return(true)
end end
it_behaves_like 'replica is up to date', '0/D525E3A8' it_behaves_like 'replica is up to date', '0/D525E3A8', data_consistency
end end
context 'when database location is not set' do context 'when database location is not set' do
...@@ -171,7 +169,12 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqServerMiddleware do ...@@ -171,7 +169,12 @@ RSpec.describe Gitlab::Database::LoadBalancing::SidekiqServerMiddleware do
end end
include_examples 'stick to the primary' include_examples 'stick to the primary'
include_examples 'job marked with chosen database'
it 'updates job hash with primary database chosen', :aggregate_failures do
expect { |b| middleware.call(worker, job, double(:queue), &b) }.to yield_control
expect(job[:database_chosen]).to eq('primary')
end
end end
end end
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