summaryrefslogtreecommitdiff
path: root/lib/gitlab/health_checks/base_abstract_check.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/health_checks/base_abstract_check.rb')
-rw-r--r--lib/gitlab/health_checks/base_abstract_check.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/gitlab/health_checks/base_abstract_check.rb b/lib/gitlab/health_checks/base_abstract_check.rb
new file mode 100644
index 00000000000..7de6d4d9367
--- /dev/null
+++ b/lib/gitlab/health_checks/base_abstract_check.rb
@@ -0,0 +1,45 @@
+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
+
+ def with_timing(proc)
+ start = Time.now
+ result = proc.call
+ yield result, Time.now.to_f - start.to_f
+ end
+
+ def catch_timeout(seconds, &block)
+ begin
+ Timeout.timeout(seconds.to_i, &block)
+ rescue Timeout::Error => ex
+ ex
+ end
+ end
+ end
+ end
+end