Add API endpoint to get Geo node information

parent 1d35406d
class Geo::ProjectRegistry < Geo::BaseRegistry
validates :project_id, presence: true
scope :failed, -> { where.not(last_repository_synced_at: nil).where(last_repository_successful_sync_at: nil) }
scope :synced, -> { where.not(last_repository_synced_at: nil, last_repository_successful_sync_at: nil) }
end
class GeoNode < ActiveRecord::Base
Status = Struct.new(:health, :repositories, :repositories_synced, :repositories_failed)
belongs_to :geo_node_key, dependent: :destroy
belongs_to :oauth_application, class_name: 'Doorkeeper::Application', dependent: :destroy
belongs_to :system_hook, dependent: :destroy
......
......@@ -768,5 +768,12 @@ module API
expose :id, :message, :starts_at, :ends_at, :color, :font
expose :active?, as: :active
end
class GeoNodeStatus < Grape::Entity
expose :health
expose :repositories
expose :repositories_synced
expose :repositories_failed
end
end
end
......@@ -28,6 +28,24 @@ module API
end
end
# Get node information (e.g. health, repos synced, repos failed, etc.)
#
# Example request:
# GET /geo/status
get 'status' do
authenticated_as_admin!
require_node_to_be_secondary!
status = GeoNode::Status.new(
HealthCheck::Utils.process_checks(['geo']),
Project.count,
::Geo::ProjectRegistry.synced.count,
::Geo::ProjectRegistry.failed.count
)
present status, with: Entities::GeoNodeStatus
end
# Enqueue a batch of IDs of wiki's projects to have their
# wiki repositories updated
#
......@@ -82,6 +100,10 @@ module API
def require_node_to_be_enabled!
forbidden! 'Geo node is disabled.' unless Gitlab::Geo.current_node.enabled?
end
def require_node_to_be_secondary!
forbidden! 'Geo node is disabled.' unless Gitlab::Geo.current_node.secondary?
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