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

base_abstract_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: 2eef359cc6e8d4a8ff24a7b94c0b74a08cc8ca26 (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
# frozen_string_literal: true

module Gitlab
  module HealthChecks
    module BaseAbstractCheck
      def name
        super.demodulize.underscore
      end

      def human_name
        name.sub(/_check$/, '').capitalize
      end

      def available?
        true
      end

      def readiness
        raise NotImplementedError
      end

      def metrics
        []
      end

      protected

      def metric(name, value, **labels)
        Metric.new(name, value, labels)
      end

      def with_timing
        start = Time.now
        result = yield
        [result, Time.now.to_f - start.to_f]
      end

      def catch_timeout(seconds, &block)
        Timeout.timeout(seconds.to_i, &block)
      rescue Timeout::Error => ex
        ex
      end
    end
  end
end