2018-10-08 10:50:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-01-30 05:11:47 -05:00
|
|
|
module Gitaly
|
|
|
|
class Server
|
2019-12-02 07:06:45 -05:00
|
|
|
SHA_VERSION_REGEX = /\A\d+\.\d+\.\d+-\d+-g([a-f0-9]{8})\z/.freeze
|
|
|
|
|
2019-06-20 07:04:56 -04:00
|
|
|
class << self
|
|
|
|
def all
|
|
|
|
Gitlab.config.repositories.storages.keys.map { |s| Gitaly::Server.new(s) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def count
|
|
|
|
all.size
|
|
|
|
end
|
|
|
|
|
|
|
|
def filesystems
|
|
|
|
all.map(&:filesystem_type).compact.uniq
|
|
|
|
end
|
2018-01-30 05:11:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :storage
|
|
|
|
|
|
|
|
def initialize(storage)
|
|
|
|
@storage = storage
|
|
|
|
end
|
|
|
|
|
|
|
|
def server_version
|
|
|
|
info.server_version
|
|
|
|
end
|
|
|
|
|
|
|
|
def git_binary_version
|
|
|
|
info.git_version
|
|
|
|
end
|
|
|
|
|
2019-12-02 07:06:45 -05:00
|
|
|
def expected_version?
|
|
|
|
server_version == Gitlab::GitalyClient.expected_server_version || matches_sha?
|
2018-01-30 05:11:47 -05:00
|
|
|
end
|
2019-12-02 07:06:45 -05:00
|
|
|
alias_method :up_to_date?, :expected_version?
|
2018-01-30 05:11:47 -05:00
|
|
|
|
2018-06-20 04:21:59 -04:00
|
|
|
def read_writeable?
|
|
|
|
readable? && writeable?
|
|
|
|
end
|
|
|
|
|
|
|
|
def readable?
|
|
|
|
storage_status&.readable
|
|
|
|
end
|
|
|
|
|
|
|
|
def writeable?
|
|
|
|
storage_status&.writeable
|
|
|
|
end
|
|
|
|
|
2019-06-20 07:04:56 -04:00
|
|
|
def filesystem_type
|
|
|
|
storage_status&.fs_type
|
|
|
|
end
|
|
|
|
|
2020-01-24 13:09:00 -05:00
|
|
|
def disk_used
|
|
|
|
disk_statistics_storage_status&.used
|
|
|
|
end
|
|
|
|
|
|
|
|
def disk_available
|
|
|
|
disk_statistics_storage_status&.available
|
|
|
|
end
|
|
|
|
|
|
|
|
# Simple convenience method for when obtaining both used and available
|
|
|
|
# statistics at once is preferred.
|
|
|
|
def disk_stats
|
|
|
|
disk_statistics_storage_status
|
|
|
|
end
|
|
|
|
|
2018-01-30 05:11:47 -05:00
|
|
|
def address
|
|
|
|
Gitlab::GitalyClient.address(@storage)
|
|
|
|
rescue RuntimeError => e
|
|
|
|
"Error getting the address: #{e.message}"
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-06-20 04:21:59 -04:00
|
|
|
def storage_status
|
|
|
|
@storage_status ||= info.storage_statuses.find { |s| s.storage_name == storage }
|
|
|
|
end
|
|
|
|
|
2020-01-24 13:09:00 -05:00
|
|
|
def disk_statistics_storage_status
|
|
|
|
@disk_statistics_storage_status ||= disk_statistics.storage_statuses.find { |s| s.storage_name == storage }
|
|
|
|
end
|
|
|
|
|
2019-12-02 07:06:45 -05:00
|
|
|
def matches_sha?
|
|
|
|
match = server_version.match(SHA_VERSION_REGEX)
|
|
|
|
return false unless match
|
|
|
|
|
|
|
|
Gitlab::GitalyClient.expected_server_version.start_with?(match[1])
|
|
|
|
end
|
|
|
|
|
2018-01-30 05:11:47 -05:00
|
|
|
def info
|
|
|
|
@info ||=
|
|
|
|
begin
|
|
|
|
Gitlab::GitalyClient::ServerService.new(@storage).info
|
2020-01-24 13:09:00 -05:00
|
|
|
rescue GRPC::Unavailable, GRPC::DeadlineExceeded => ex
|
|
|
|
Gitlab::ErrorTracking.track_exception(ex)
|
|
|
|
# This will show the server as being out of date
|
|
|
|
Gitaly::ServerInfoResponse.new(git_version: '', server_version: '', storage_statuses: [])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def disk_statistics
|
|
|
|
@disk_statistics ||=
|
|
|
|
begin
|
|
|
|
Gitlab::GitalyClient::ServerService.new(@storage).disk_statistics
|
|
|
|
rescue GRPC::Unavailable, GRPC::DeadlineExceeded => ex
|
|
|
|
Gitlab::ErrorTracking.track_exception(ex)
|
2018-01-30 05:11:47 -05:00
|
|
|
# This will show the server as being out of date
|
2018-06-20 04:21:59 -04:00
|
|
|
Gitaly::ServerInfoResponse.new(git_version: '', server_version: '', storage_statuses: [])
|
2018-01-30 05:11:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|