2018-11-09 13:39:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-07 06:27:15 -04:00
|
|
|
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 metrics
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def metric(name, value, **labels)
|
|
|
|
Metric.new(name, value, labels)
|
|
|
|
end
|
|
|
|
|
2017-07-25 08:19:09 -04:00
|
|
|
def with_timing
|
2017-04-07 06:27:15 -04:00
|
|
|
start = Time.now
|
2017-07-25 08:19:09 -04:00
|
|
|
result = yield
|
|
|
|
[result, Time.now.to_f - start.to_f]
|
2017-04-07 06:27:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def catch_timeout(seconds, &block)
|
2020-01-23 10:08:46 -05:00
|
|
|
Timeout.timeout(seconds.to_i, &block)
|
|
|
|
rescue Timeout::Error => ex
|
|
|
|
ex
|
2017-04-07 06:27:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|