Commit 5c92e031 authored by Valery Sizov's avatar Valery Sizov Committed by Nick Thomas

Resolve "gitlab:geo:check should check connections to the Geo tracking DB"

parent 4cfe5293
---
title: gitlab:geo:check checks connection to the Geo tracking DB
merge_request:
author:
type: added
......@@ -4,20 +4,57 @@ module SystemCheck
set_name 'GitLab Geo secondary database is correctly configured'
set_skip_reason 'not a secondary node'
WRONG_CONFIGURATION_MESSAGE = 'Check if you enabled the `geo_secondary_role` or `geo_postgresql` in the gitlab.rb config file.'.freeze
UNHEALTHY_CONNECTION_MESSAGE = 'Check the tracking database configuration as the connection could not be established'.freeze
NO_TABLES_MESSAGE = 'Run the tracking database migrations: gitlab-rake geo:db:migrate'.freeze
def skip?
!Gitlab::Geo.secondary?
end
def check?
Gitlab::Geo.geo_database_configured?
def multi_check
unless Gitlab::Geo.geo_database_configured?
$stdout.puts 'no'.color(:red)
try_fixing_it(WRONG_CONFIGURATION_MESSAGE)
for_more_information('doc/gitlab-geo/database.md')
return false
end
unless connection_healthy?
$stdout.puts 'no'.color(:red)
try_fixing_it(UNHEALTHY_CONNECTION_MESSAGE)
for_more_information('doc/gitlab-geo/database.md')
return false
end
unless tables_present?
$stdout.puts 'no'.color(:red)
try_fixing_it(NO_TABLES_MESSAGE)
for_more_information('doc/gitlab-geo/database.md')
return false
end
$stdout.puts 'yes'.color(:green)
true
end
def show_error
try_fixing_it(
'Check if you enabled the `geo_secondary_role` or `geo_postgresql` in the gitlab.rb config file.'
)
private
def connection_healthy?
::Geo::TrackingBase.connection.active?
end
for_more_information('doc/gitlab-geo/database.md')
def tables_present?
Gitlab::Geo::DatabaseTasks.with_geo_db { !ActiveRecord::Migrator.needs_migration? }
end
end
end
......
require 'spec_helper'
require 'rake_helper'
describe SystemCheck::Geo::GeoDatabaseConfiguredCheck do
before do
silence_output
end
subject { described_class.new }
describe '#multi_check' do
it "checks database configuration" do
stub_configuration_check(false)
expect(subject).to receive(:try_fixing_it).with(described_class::WRONG_CONFIGURATION_MESSAGE)
expect(subject.multi_check).to be_falsey
end
it "checks database configuration" do
stub_configuration_check(true)
stub_connection_state(false)
expect(subject).to receive(:try_fixing_it).with(described_class::UNHEALTHY_CONNECTION_MESSAGE)
expect(subject.multi_check).to be_falsey
end
it "checks table existence" do
stub_configuration_check(true)
stub_connection_state(true)
stub_tables_existence(false)
expect(subject).to receive(:try_fixing_it).with(described_class::NO_TABLES_MESSAGE)
expect(subject.multi_check).to be_falsey
end
it "returns true when all checks passed" do
stub_configuration_check(true)
stub_connection_state(true)
stub_tables_existence(true)
expect(subject).not_to receive(:try_fixing_it)
expect(subject.multi_check).to be_truthy
end
end
def stub_configuration_check(state)
expect(Gitlab::Geo).to receive(:geo_database_configured?).and_return(state)
end
def stub_connection_state(state)
connection = double
expect(connection).to receive(:active?).and_return(state)
expect(::Geo::TrackingBase).to receive(:connection).and_return(connection)
end
def stub_tables_existence(state)
expect(ActiveRecord::Migrator).to receive(:needs_migration?).and_return(!state)
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