Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
88ea06c8
Commit
88ea06c8
authored
Jun 03, 2021
by
Matthias Kaeppler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix missing data_consistency field in job hash
This was being emitted to Prometheus but never set.
parent
1c6c3b8b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
14 deletions
+20
-14
lib/gitlab/database/load_balancing/sidekiq_server_middleware.rb
...tlab/database/load_balancing/sidekiq_server_middleware.rb
+4
-1
spec/lib/gitlab/database/load_balancing/sidekiq_server_middleware_spec.rb
...database/load_balancing/sidekiq_server_middleware_spec.rb
+16
-13
No files found.
lib/gitlab/database/load_balancing/sidekiq_server_middleware.rb
View file @
88ea06c8
...
@@ -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."
...
...
spec/lib/gitlab/database/load_balancing/sidekiq_server_middleware_spec.rb
View file @
88ea06c8
...
@@ -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
'do
es
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment