Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitaly_check.rb « health_checks « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 898733fea5d016786e009d3427fd8f78485acd15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

module Gitlab
  module HealthChecks
    class GitalyCheck
      extend BaseAbstractCheck

      METRIC_PREFIX = 'gitaly_health_check'.freeze

      class << self
        def readiness
          repository_storages.map do |storage_name|
            check(storage_name)
          end
        end

        def metrics
          Gitaly::Server.all.flat_map do |server|
            result, elapsed = with_timing { server.read_writeable? }
            labels = { shard: server.storage }

            [
              metric("#{metric_prefix}_success", result ? 1 : 0, **labels),
              metric("#{metric_prefix}_latency_seconds", elapsed, **labels)
            ]
          end
        end

        def check(storage_name)
          serv = Gitlab::GitalyClient::HealthCheckService.new(storage_name)
          result = serv.check
          HealthChecks::Result.new(result[:success], result[:message], shard: storage_name)
        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