2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
module Gitlab
|
|
|
|
module HealthChecks
|
|
|
|
class GitalyCheck
|
|
|
|
extend BaseAbstractCheck
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
METRIC_PREFIX = 'gitaly_health_check'
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
class << self
|
|
|
|
def readiness
|
|
|
|
repository_storages.map do |storage_name|
|
|
|
|
check(storage_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def metrics
|
2018-11-08 19:23:39 +05:30
|
|
|
Gitaly::Server.all.flat_map do |server|
|
|
|
|
result, elapsed = with_timing { server.read_writeable? }
|
|
|
|
labels = { shard: server.storage }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
[
|
2018-11-08 19:23:39 +05:30
|
|
|
metric("#{metric_prefix}_success", result ? 1 : 0, **labels),
|
2018-03-17 18:26:18 +05:30
|
|
|
metric("#{metric_prefix}_latency_seconds", elapsed, **labels)
|
2018-11-08 19:23:39 +05:30
|
|
|
]
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check(storage_name)
|
2022-10-11 01:57:18 +05:30
|
|
|
storage_healthy = healthy(storage_name)
|
|
|
|
unless storage_healthy[:success]
|
|
|
|
return HealthChecks::Result.new(
|
|
|
|
name,
|
|
|
|
storage_healthy[:success],
|
|
|
|
storage_healthy[:message],
|
|
|
|
shard: storage_name
|
|
|
|
)
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
storage_ready = ready(storage_name)
|
2019-12-21 20:55:43 +05:30
|
|
|
HealthChecks::Result.new(
|
|
|
|
name,
|
2022-10-11 01:57:18 +05:30
|
|
|
storage_ready[:success],
|
|
|
|
storage_ready[:message],
|
2019-12-21 20:55:43 +05:30
|
|
|
shard: storage_name
|
|
|
|
)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
def healthy(storage_name)
|
|
|
|
serv = Gitlab::GitalyClient::HealthCheckService.new(storage_name)
|
|
|
|
serv.check
|
|
|
|
end
|
|
|
|
|
|
|
|
def ready(storage_name)
|
|
|
|
serv = Gitlab::GitalyClient::ServerService.new(storage_name)
|
|
|
|
serv.readiness_check
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def metric_prefix
|
|
|
|
METRIC_PREFIX
|
|
|
|
end
|
|
|
|
|
|
|
|
def repository_storages
|
|
|
|
storages.keys
|
|
|
|
end
|
|
|
|
|
|
|
|
def storages
|
|
|
|
Gitlab.config.repositories.storages
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|