2018-11-09 13:39:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-01-21 18:34:09 -05:00
|
|
|
module Gitlab
|
|
|
|
module HealthChecks
|
|
|
|
class GitalyCheck
|
|
|
|
extend BaseAbstractCheck
|
|
|
|
|
2019-10-16 08:06:32 -04:00
|
|
|
METRIC_PREFIX = 'gitaly_health_check'.freeze
|
2018-01-21 18:34:09 -05:00
|
|
|
|
|
|
|
class << self
|
|
|
|
def readiness
|
|
|
|
repository_storages.map do |storage_name|
|
|
|
|
check(storage_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def metrics
|
2018-06-20 04:21:59 -04:00
|
|
|
Gitaly::Server.all.flat_map do |server|
|
|
|
|
result, elapsed = with_timing { server.read_writeable? }
|
|
|
|
labels = { shard: server.storage }
|
2018-01-21 18:34:09 -05:00
|
|
|
|
|
|
|
[
|
2018-06-20 04:21:59 -04:00
|
|
|
metric("#{metric_prefix}_success", result ? 1 : 0, **labels),
|
2018-01-21 18:34:09 -05:00
|
|
|
metric("#{metric_prefix}_latency_seconds", elapsed, **labels)
|
2018-06-20 04:21:59 -04:00
|
|
|
]
|
2018-01-21 18:34:09 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check(storage_name)
|
|
|
|
serv = Gitlab::GitalyClient::HealthCheckService.new(storage_name)
|
|
|
|
result = serv.check
|
2019-10-03 17:07:29 -04:00
|
|
|
|
|
|
|
HealthChecks::Result.new(
|
|
|
|
name,
|
|
|
|
result[:success],
|
|
|
|
result[:message],
|
|
|
|
shard: storage_name
|
|
|
|
)
|
2018-01-21 18:34:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def metric_prefix
|
|
|
|
METRIC_PREFIX
|
|
|
|
end
|
|
|
|
|
|
|
|
def repository_storages
|
|
|
|
storages.keys
|
|
|
|
end
|
|
|
|
|
|
|
|
def storages
|
|
|
|
Gitlab.config.repositories.storages
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|