Skip to content

Commit

Permalink
Fixes #31545: Add status of Rails cache to Ping API
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Oct 10, 2023
1 parent 7c41286 commit dfb0d00
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions app/services/ping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def ping
{
'foreman': {
database: ping_database,
cache: ping_cache,
},
}.merge(plugins_ping)
end
Expand Down Expand Up @@ -47,6 +48,39 @@ def ping_database
}
end

def ping_cache
response = {}

if Rails.application.config.cache_store.first == :redis_cache_store
redis = Rails.cache.redis
response['servers'] = {}

if redis.respond_to?(:nodes)
nodes = redis.nodes
else
nodes = [redis]
end

nodes.each_with_index do |node, index|
start = Time.now

begin
node.ping
status = STATUS_OK
rescue Redis::CannotConnectError => e
status = STATUS_FAIL
ensure
response['servers'][index] = {
status: status,
duration_ms: duration_ms(start),
}
end
end
end

response
end

def statuses_compute_resources
results = []
ComputeResource.all.index.map do |resource|
Expand Down

0 comments on commit dfb0d00

Please sign in to comment.