2018-11-09 13:39:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-07 06:27:15 -04:00
|
|
|
module Gitlab
|
|
|
|
module HealthChecks
|
|
|
|
class DbCheck
|
|
|
|
extend SimpleAbstractCheck
|
|
|
|
|
|
|
|
class << self
|
|
|
|
private
|
|
|
|
|
|
|
|
def metric_prefix
|
|
|
|
'db_ping'
|
|
|
|
end
|
|
|
|
|
2017-08-24 13:02:27 -04:00
|
|
|
def successful?(result)
|
2017-04-07 06:27:15 -04:00
|
|
|
result == '1'
|
|
|
|
end
|
|
|
|
|
|
|
|
def check
|
|
|
|
catch_timeout 10.seconds do
|
|
|
|
if Gitlab::Database.postgresql?
|
2018-06-15 13:04:02 -04:00
|
|
|
ActiveRecord::Base.connection.execute('SELECT 1 as ping')&.first&.[]('ping')&.to_s
|
2017-04-07 06:27:15 -04:00
|
|
|
else
|
|
|
|
ActiveRecord::Base.connection.execute('SELECT 1 as ping')&.first&.first&.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|