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
2df2a5bc
Commit
2df2a5bc
authored
Feb 22, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a health check for Geo database
parent
fb8798f4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
0 deletions
+58
-0
app/views/admin/health_check/show.html.haml
app/views/admin/health_check/show.html.haml
+3
-0
config/initializers/health_check.rb
config/initializers/health_check.rb
+4
-0
lib/gitlab/geo/health_check.rb
lib/gitlab/geo/health_check.rb
+51
-0
No files found.
app/views/admin/health_check/show.html.haml
View file @
2df2a5bc
...
...
@@ -34,6 +34,9 @@
%code
=
health_check_url
(
token:
current_application_settings
.
health_check_access_token
,
checks: :database
)
%li
%code
=
health_check_url
(
token:
current_application_settings
.
health_check_access_token
,
checks: :migrations
)
-
if
Gitlab
::
Geo
.
secondary?
%li
%code
=
health_check_url
(
token:
current_application_settings
.
health_check_access_token
,
checks: :geo
)
%hr
.panel.panel-default
...
...
config/initializers/health_check.rb
View file @
2df2a5bc
HealthCheck
.
setup
do
|
config
|
config
.
standard_checks
=
%w(database migrations cache)
config
.
full_checks
=
%w(database migrations cache)
config
.
add_custom_check
(
'geo'
)
do
Gitlab
::
Geo
::
HealthCheck
.
perform_checks
end
end
lib/gitlab/geo/health_check.rb
0 → 100644
View file @
2df2a5bc
module
Gitlab
module
Geo
class
HealthCheck
def
self
.
perform_checks
return
''
unless
Gitlab
::
Geo
.
secondary?
database_version
=
self
.
get_database_version
migration_version
=
self
.
get_migration_version
if
database_version
.
to_i
!=
migration_version
.
to_i
"Current database version (
#{
database_version
}
) does not match latest migration (
#{
migration_version
}
)."
else
''
end
rescue
=>
e
e
.
message
end
def
self
.
db_migrate_path
# Lazy initialisation so Rails.root will be defined
@@db_migrate_path
||=
File
.
join
(
Rails
.
root
,
'db_geo'
,
'migrate'
)
end
def
self
.
get_database_version
if
defined?
(
ActiveRecord
)
connection
=
::
Geo
::
BaseRegistry
.
connection
schema_migrations_table_name
=
ActiveRecord
::
Base
.
schema_migrations_table_name
if
connection
.
table_exists?
(
schema_migrations_table_name
)
connection
.
execute
(
"SELECT MAX(version) AS version FROM
#{
schema_migrations_table_name
}
"
)
.
first
.
fetch
(
'version'
)
else
0
end
end
end
def
self
.
get_migration_version
latest_migration
=
nil
Dir
[
File
.
join
(
self
.
db_migrate_path
,
"[0-9]*_*.rb"
)].
each
do
|
f
|
l
=
f
.
scan
(
/0*([0-9]+)_[_.a-zA-Z0-9]*.rb/
).
first
.
first
rescue
-
1
latest_migration
=
l
if
!
latest_migration
||
l
.
to_i
>
latest_migration
.
to_i
end
latest_migration
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