Commit 8323e55b authored by Alejandro Rodríguez's avatar Alejandro Rodríguez

Return a value to check if redis is available on /internal/check

parent 063e285e
...@@ -46,6 +46,15 @@ module API ...@@ -46,6 +46,15 @@ module API
::MergeRequests::GetUrlsService.new(project).execute(params[:changes]) ::MergeRequests::GetUrlsService.new(project).execute(params[:changes])
end end
def redis_ping
result = Gitlab::Redis::SharedState.with { |redis| redis.ping }
result == 'PONG'
rescue => e
Rails.logger.warn("GitLab: An unexpected error occurred in pinging to Redis: #{e}")
false
end
private private
def set_project def set_project
......
...@@ -88,7 +88,8 @@ module API ...@@ -88,7 +88,8 @@ module API
{ {
api_version: API.version, api_version: API.version,
gitlab_version: Gitlab::VERSION, gitlab_version: Gitlab::VERSION,
gitlab_rev: Gitlab::REVISION gitlab_rev: Gitlab::REVISION,
redis: redis_ping
} }
end end
......
...@@ -8,10 +8,21 @@ describe API::Internal do ...@@ -8,10 +8,21 @@ describe API::Internal do
describe "GET /internal/check" do describe "GET /internal/check" do
it do it do
expect_any_instance_of(Redis).to receive(:ping).and_return('PONG')
get api("/internal/check"), secret_token: secret_token get api("/internal/check"), secret_token: secret_token
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['api_version']).to eq(API::API.version) expect(json_response['api_version']).to eq(API::API.version)
expect(json_response['redis']).to be(true)
end
it 'returns false for field `redis` when redis is unavailable' do
expect_any_instance_of(Redis).to receive(:ping).and_raise(Errno::ENOENT)
get api("/internal/check"), secret_token: secret_token
expect(json_response['redis']).to be(false)
end end
end 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