summaryrefslogtreecommitdiff
path: root/lib/gitlab/health_checks/redis/redis_abstract_check.rb
blob: 9a9a4d1faba30bfe3ba9f87c977c86bbc12cf809 (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
# frozen_string_literal: true

module Gitlab
  module HealthChecks
    module Redis
      module RedisAbstractCheck
        include SimpleAbstractCheck

        def check_up
          successful?(check)
        end

        def redis_instance_class_name
          Gitlab::Redis.const_get(redis_instance_name.camelize, false)
        end

        private

        def metric_prefix
          "redis_#{redis_instance_name}_ping"
        end

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

        def successful?(result)
          result == 'PONG'
        end

        # rubocop: disable CodeReuse/ActiveRecord
        def check
          catch_timeout 10.seconds do
            redis_instance_class_name.with(&:ping)
          end
        end
        # rubocop: enable CodeReuse/ActiveRecord
      end
    end
  end
end