BigW Consortium Gitlab

base_abstract_check.rb 802 Bytes
Newer Older
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
module Gitlab
  module HealthChecks
    module BaseAbstractCheck
      def name
        super.demodulize.underscore
      end

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

      def readiness
        raise NotImplementedError
      end

      def liveness
        HealthChecks::Result.new(true)
      end

      def metrics
        []
      end

      protected

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

30
      def with_timing
31
        start = Time.now
32 33
        result = yield
        [result, Time.now.to_f - start.to_f]
34 35 36 37 38 39 40 41 42 43 44 45
      end

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