Add a health check for Geo database

parent fb8798f4
......@@ -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
......
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
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
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