Commit 04fdd455 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch '4411-geo-node-status-rake-task' into 'master'

Add rake task to print Geo node status

Closes #4411

See merge request gitlab-org/gitlab-ee!4101
parents 8327c2c7 be43e13b
---
title: Add rake task to print Geo node status
merge_request:
author:
type: added
......@@ -23,6 +23,12 @@ to help identify if something is wrong:
![GitLab Geo health check](img/geo-node-healthcheck.png)
There is also an option to check the status of the secondary node by running a special rake task:
```
sudo gitlab-rake geo:status
```
#### Is Postgres replication working?
#### Are my nodes pointing to the correct database instance?
......@@ -133,4 +139,3 @@ sudo gitlab-ctl reconfigure
This will increase the timeout to three hours (10800 seconds). Choose a time
long enough to accomodate a full clone of your largest repositories.
require 'action_view/helpers'
task spec: ['geo:db:test:prepare']
namespace :geo do
include ActionView::Helpers::DateHelper
include ActionView::Helpers::NumberHelper
GEO_LICENSE_ERROR_TEXT = 'GitLab Geo is not supported with this license. Please contact sales@gitlab.com.'.freeze
namespace :db do |ns|
......@@ -201,4 +206,64 @@ namespace :geo do
Gitlab::Geo::GeoTasks.update_primary_geo_node_url
end
desc 'Print Geo node status'
task status: :environment do
abort GEO_LICENSE_ERROR_TEXT unless Gitlab::Geo.license_allows?
COLUMN_WIDTH = 35
current_node_status = GeoNodeStatus.current_node_status
geo_node = current_node_status.geo_node
unless geo_node.secondary?
puts 'This command is only available on a secondary node'.color(:red)
exit
end
puts
puts GeoNode.current_node_url
puts '-----------------------------------------------------'.color(:yellow)
print 'GitLab version: '.rjust(COLUMN_WIDTH)
puts Gitlab::VERSION
print 'Health Status: '.rjust(COLUMN_WIDTH)
puts current_node_status.health_status
print 'Repositories: '.rjust(COLUMN_WIDTH)
print "#{current_node_status.repositories_synced_count}/#{current_node_status.repositories_count} "
puts "(#{number_to_percentage(current_node_status.repositories_synced_in_percentage, precision: 0)})"
print 'LFS objects: '.rjust(COLUMN_WIDTH)
print "#{current_node_status.lfs_objects_synced_count}/#{current_node_status.lfs_objects_count} "
puts "(#{number_to_percentage(current_node_status.lfs_objects_synced_in_percentage, precision: 0)})"
print 'Attachments: '.rjust(COLUMN_WIDTH)
print "#{current_node_status.attachments_synced_count}/#{current_node_status.attachments_count} "
puts "(#{number_to_percentage(current_node_status.attachments_synced_in_percentage, precision: 0)})"
print 'Wikis: '.rjust(COLUMN_WIDTH)
print "#{current_node_status.wikis_synced_count}/#{current_node_status.wikis_count} "
puts "(#{number_to_percentage(current_node_status.wikis_synced_in_percentage, precision: 0)})"
print 'Sync settings: '.rjust(COLUMN_WIDTH)
puts geo_node.namespaces.any? ? 'Selective' : 'Full'
print 'Database replication lag: '.rjust(COLUMN_WIDTH)
puts "#{Gitlab::Geo::HealthCheck.db_replication_lag_seconds} seconds"
print 'Last event ID seen from primary: '.rjust(COLUMN_WIDTH)
last_event = Geo::EventLog.last
last_event_id = last_event&.id
print last_event_id
puts "(#{time_ago_in_words(last_event&.created_at)} ago)"
print 'Last event ID processed by cursor: '.rjust(COLUMN_WIDTH)
cursor_last_event_id = Geo::EventLogState.last_processed&.event_id
if cursor_last_event_id
print cursor_last_event_id
puts "(#{time_ago_in_words(Geo::EventLog.find_by(id: cursor_last_event_id)&.created_at)} ago)"
end
end
end
require 'rake_helper'
describe 'geo rake tasks' do
describe 'geo rake tasks', :geo do
include ::EE::GeoHelpers
before do
......@@ -57,4 +57,21 @@ describe 'geo rake tasks' do
expect(primary_node.reload.url).to eq 'https://primary.geo.example.com/'
end
end
describe 'status task' do
let!(:current_node) { create(:geo_node) }
let!(:primary_node) { create(:geo_node, :primary) }
let!(:geo_event_log) { create(:geo_event_log) }
before do
expect(Gitlab::Geo).to receive(:license_allows?).and_return(true).at_least(:once)
expect(GeoNodeStatus).to receive(:current_node_status).and_call_original
stub_current_geo_node(current_node)
end
it 'runs with no error' do
expect { run_rake_task('geo:status') }.to output(/Sync settings: Full/).to_stdout
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