Commit 4c45477e authored by Valery Sizov's avatar Valery Sizov

[Geo] Add rake geo:status command

See https://gitlab.com/gitlab-org/gitlab-ee/issues/4411
parent 6aad9fdc
......@@ -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'
include ActionView::Helpers::DateHelper
include ActionView::Helpers::NumberHelper
task spec: ['geo:db:test:prepare']
namespace :geo do
......@@ -201,4 +205,67 @@ namespace :geo do
Gitlab::Geo::GeoTasks.update_primary_geo_node_url
end
desc 'Print Geo node status'
task status: :environment do
unless Gitlab::Geo.license_allows?
puts 'You need a different license to enable Geo replication'.color(:red)
exit
end
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
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