Commit 3924c47a authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '1333-simplify-health-checks' into 'master'

Follow-up: Add Gitlab::Redis::Sessions Redis instance

See merge request gitlab-org/gitlab!72287
parents 536d193d b23f1bf1
......@@ -4,31 +4,7 @@ module Gitlab
module HealthChecks
module Redis
class CacheCheck
extend SimpleAbstractCheck
class << self
def check_up
check
end
private
def metric_prefix
'redis_cache_ping'
end
def successful?(result)
result == 'PONG'
end
# rubocop: disable CodeReuse/ActiveRecord
def check
catch_timeout 10.seconds do
Gitlab::Redis::Cache.with(&:ping)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
extend RedisAbstractCheck
end
end
end
......
......@@ -4,31 +4,7 @@ module Gitlab
module HealthChecks
module Redis
class QueuesCheck
extend SimpleAbstractCheck
class << self
def check_up
check
end
private
def metric_prefix
'redis_queues_ping'
end
def successful?(result)
result == 'PONG'
end
# rubocop: disable CodeReuse/ActiveRecord
def check
catch_timeout 10.seconds do
Gitlab::Redis::Queues.with(&:ping)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
extend RedisAbstractCheck
end
end
end
......
......@@ -4,31 +4,7 @@ module Gitlab
module HealthChecks
module Redis
class RateLimitingCheck
extend SimpleAbstractCheck
class << self
def check_up
check
end
private
def metric_prefix
'redis_rate_limiting_ping'
end
def successful?(result)
result == 'PONG'
end
# rubocop: disable CodeReuse/ActiveRecord
def check
catch_timeout 10.seconds do
Gitlab::Redis::RateLimiting.with(&:ping)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
extend RedisAbstractCheck
end
end
end
......
# frozen_string_literal: true
module Gitlab
module HealthChecks
module Redis
module RedisAbstractCheck
include SimpleAbstractCheck
def check_up
successful?(check)
end
private
def redis_instance_class_name
Gitlab::Redis.const_get(redis_instance_name.camelize, false)
end
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
......@@ -14,16 +14,22 @@ module Gitlab
end
def successful?(result)
result == 'PONG'
result == true
end
def check
::Gitlab::HealthChecks::Redis::CacheCheck.check_up &&
::Gitlab::HealthChecks::Redis::QueuesCheck.check_up &&
::Gitlab::HealthChecks::Redis::SharedStateCheck.check_up &&
::Gitlab::HealthChecks::Redis::TraceChunksCheck.check_up &&
::Gitlab::HealthChecks::Redis::RateLimitingCheck.check_up &&
::Gitlab::HealthChecks::Redis::SessionsCheck.check_up
redis_health_checks.all?(&:check_up)
end
def redis_health_checks
[
Gitlab::HealthChecks::Redis::CacheCheck,
Gitlab::HealthChecks::Redis::QueuesCheck,
Gitlab::HealthChecks::Redis::SharedStateCheck,
Gitlab::HealthChecks::Redis::TraceChunksCheck,
Gitlab::HealthChecks::Redis::RateLimitingCheck,
Gitlab::HealthChecks::Redis::SessionsCheck
]
end
end
end
......
......@@ -4,31 +4,7 @@ module Gitlab
module HealthChecks
module Redis
class SessionsCheck
extend SimpleAbstractCheck
class << self
def check_up
check
end
private
def metric_prefix
'redis_sessions_ping'
end
def successful?(result)
result == 'PONG'
end
# rubocop: disable CodeReuse/ActiveRecord
def check
catch_timeout 10.seconds do
Gitlab::Redis::Sessions.with(&:ping)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
extend RedisAbstractCheck
end
end
end
......
......@@ -4,31 +4,7 @@ module Gitlab
module HealthChecks
module Redis
class SharedStateCheck
extend SimpleAbstractCheck
class << self
def check_up
check
end
private
def metric_prefix
'redis_shared_state_ping'
end
def successful?(result)
result == 'PONG'
end
# rubocop: disable CodeReuse/ActiveRecord
def check
catch_timeout 10.seconds do
Gitlab::Redis::SharedState.with(&:ping)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
extend RedisAbstractCheck
end
end
end
......
......@@ -4,31 +4,7 @@ module Gitlab
module HealthChecks
module Redis
class TraceChunksCheck
extend SimpleAbstractCheck
class << self
def check_up
check
end
private
def metric_prefix
'redis_trace_chunks_ping'
end
def successful?(result)
result == 'PONG'
end
# rubocop: disable CodeReuse/ActiveRecord
def check
catch_timeout 10.seconds do
Gitlab::Redis::TraceChunks.with(&:ping)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
extend RedisAbstractCheck
end
end
end
......
......@@ -4,5 +4,5 @@ require 'spec_helper'
require_relative '../simple_check_shared'
RSpec.describe Gitlab::HealthChecks::Redis::RedisCheck do
include_examples 'simple_check', 'redis_ping', 'Redis', 'PONG'
include_examples 'simple_check', 'redis_ping', 'Redis', true
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment