Commit 7e7eec0e authored by Stan Hu's avatar Stan Hu

Merge branch 'sh-add-slave-status-check' into 'master'

Check for streaming replication in GeoNode status

See merge request !1481
parents 424c40ea fced9299
......@@ -55,6 +55,7 @@ your browser. We perform the following health checks on each secondary node
to help identify if something is wrong:
- Is the node running?
- Is the node's secondary database configured for streaming replication?
- Is the node's secondary tracking database configured?
- Is the node's secondary tracking database connected?
- Is the node's secondary tracking database up-to-date?
......
......@@ -4,6 +4,7 @@ module Gitlab
def self.perform_checks
return '' unless Gitlab::Geo.secondary?
return 'The Geo database configuration file is missing.' unless Gitlab::Geo.configured?
return 'The Geo node has a database that is not configured for streaming replication with the primary node.' unless self.database_secondary?
database_version = self.get_database_version.to_i
migration_version = self.get_migration_version.to_i
......@@ -48,6 +49,14 @@ module Gitlab
latest_migration
end
def self.database_secondary?
raise NotImplemented unless Gitlab::Database.postgresql?
ActiveRecord::Base.connection.execute('SELECT pg_is_in_recovery()')
.first
.fetch('pg_is_in_recovery') == 't'
end
end
end
end
......@@ -12,6 +12,14 @@ describe Gitlab::Geo::HealthCheck do
expect(subject.perform_checks).to be_blank
end
it 'returns an error when database is not configured for streaming replication' do
allow(Gitlab::Geo).to receive(:secondary?) { true }
allow(Gitlab::Database).to receive(:postgresql?) { true }
allow(ActiveRecord::Base).to receive_message_chain(:connection, :execute, :first, :fetch) { 'f' }
expect(subject.perform_checks).not_to be_blank
end
it 'returns an error when configuration file is missing for tracking DB' do
allow(Rails.configuration).to receive(:respond_to?).with(:geo_database) { false }
......
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