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
6ee0ea3c
Commit
6ee0ea3c
authored
Sep 04, 2020
by
Mike Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Geo: Add rake task to check DB replication
parent
d991c4b1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
0 deletions
+82
-0
ee/changelogs/unreleased/mk-add-replication-working-rake-task.yml
...elogs/unreleased/mk-add-replication-working-rake-task.yml
+5
-0
ee/lib/tasks/gitlab/geo.rake
ee/lib/tasks/gitlab/geo.rake
+26
-0
ee/spec/tasks/gitlab/geo_rake_spec.rb
ee/spec/tasks/gitlab/geo_rake_spec.rb
+51
-0
No files found.
ee/changelogs/unreleased/mk-add-replication-working-rake-task.yml
0 → 100644
View file @
6ee0ea3c
---
title
:
'
Geo:
Add
rake
task
to
check
if
DB
replication
is
working'
merge_request
:
41618
author
:
type
:
added
ee/lib/tasks/gitlab/geo.rake
View file @
6ee0ea3c
...
...
@@ -32,5 +32,31 @@ namespace :gitlab do
exit
1
end
end
desc
'GitLab | Geo | Check Geo database replication'
task
check_database_replication_working: :gitlab_environment
do
unless
::
Gitlab
::
Geo
.
secondary?
abort
'This command is only available on a secondary node'
.
color
(
:red
)
end
geo_health_check
=
Gitlab
::
Geo
::
HealthCheck
.
new
enabled
=
geo_health_check
.
replication_enabled?
success
=
enabled
&&
geo_health_check
.
replication_working?
if
success
puts
'SUCCESS - Database replication is working.'
.
color
(
:green
)
elsif
enabled
abort
"ERROR - Database replication is enabled, but not working.
\n
"
\
"This rake task is intended for programmatic use. Please run
\n
"
\
"the full Geo check task for more information:
\n
"
\
" gitlab-rake gitlab:geo:check"
.
color
(
:red
)
else
abort
"ERROR - Database replication is not enabled.
\n
"
\
"This rake task is intended for programmatic use. Please run
\n
"
\
"the full Geo check task for more information:
\n
"
\
" gitlab-rake gitlab:geo:check"
.
color
(
:red
)
end
end
end
end
ee/spec/tasks/gitlab/geo_rake_spec.rb
View file @
6ee0ea3c
...
...
@@ -50,4 +50,55 @@ RSpec.describe 'gitlab:geo rake tasks', :geo do
end
end
end
describe
'gitlab:geo:check_database_replication_working'
do
let
(
:run_task
)
do
run_rake_task
(
'gitlab:geo:check_database_replication_working'
)
end
before
do
stub_secondary_node
end
context
'when DB replication is enabled'
do
let
(
:enabled
)
{
true
}
before
do
allow_next_instance_of
(
Gitlab
::
Geo
::
HealthCheck
)
do
|
health_check
|
allow
(
health_check
).
to
receive
(
:replication_enabled?
).
and_return
(
enabled
)
allow
(
health_check
).
to
receive
(
:replication_working?
).
and_return
(
working
)
end
end
context
'when DB replication is working'
do
let
(
:working
)
{
true
}
it
'prints a success message'
do
expect
{
run_task
}.
to
output
(
/SUCCESS - Database replication is working/
).
to_stdout
end
end
context
'when DB replication is not working'
do
let
(
:working
)
{
false
}
it
'exits with non-success code'
do
expect
{
run_task
}.
to
abort_execution
.
with_message
(
/ERROR - Database replication is enabled, but not working/
)
end
end
end
context
'when DB replication is not enabled'
do
let
(
:enabled
)
{
false
}
before
do
allow_next_instance_of
(
Gitlab
::
Geo
::
HealthCheck
)
do
|
health_check
|
allow
(
health_check
).
to
receive
(
:replication_enabled?
).
and_return
(
enabled
)
end
end
it
'exits with non-success code'
do
expect
{
run_task
}.
to
abort_execution
.
with_message
(
/ERROR - Database replication is not enabled/
)
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