2017-04-07 06:27:15 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe HealthController do
|
|
|
|
include StubENV
|
|
|
|
|
|
|
|
let(:json_response) { JSON.parse(response.body) }
|
2018-02-02 13:39:55 -05:00
|
|
|
let(:token) { Gitlab::CurrentSettings.health_check_access_token }
|
2017-07-03 11:09:34 -04:00
|
|
|
let(:whitelisted_ip) { '127.0.0.1' }
|
|
|
|
let(:not_whitelisted_ip) { '127.0.0.2' }
|
2017-04-07 06:27:15 -04:00
|
|
|
|
|
|
|
before do
|
2017-07-04 18:12:21 -04:00
|
|
|
allow(Settings.monitoring).to receive(:ip_whitelist).and_return([whitelisted_ip])
|
2017-09-18 12:13:49 -04:00
|
|
|
stub_storage_settings({}) # Hide the broken storage
|
2017-04-07 06:27:15 -04:00
|
|
|
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
|
|
|
|
end
|
|
|
|
|
2017-11-13 10:52:07 -05:00
|
|
|
describe '#storage_check' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::RequestContext).to receive(:client_ip).and_return(whitelisted_ip)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { post :storage_check }
|
|
|
|
|
|
|
|
it 'checks all the configured storages' do
|
|
|
|
expect(Gitlab::Git::Storage::Checker).to receive(:check_all).and_call_original
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the check interval' do
|
|
|
|
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'true')
|
|
|
|
stub_application_setting(circuitbreaker_check_interval: 10)
|
|
|
|
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(json_response['check_interval']).to eq(10)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with failing storages', :broken_storage do
|
|
|
|
before do
|
|
|
|
stub_storage_settings(
|
|
|
|
broken: { path: 'tmp/tests/non-existent-repositories' }
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes the failure information' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expected_results = [
|
|
|
|
{ 'storage' => 'broken', 'success' => false },
|
|
|
|
{ 'storage' => 'default', 'success' => true }
|
|
|
|
]
|
|
|
|
|
|
|
|
expect(json_response['results']).to eq(expected_results)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-07 06:27:15 -04:00
|
|
|
describe '#readiness' do
|
2017-07-06 07:36:16 -04:00
|
|
|
shared_context 'endpoint responding with readiness data' do
|
2017-07-10 11:00:43 -04:00
|
|
|
let(:request_params) { {} }
|
|
|
|
|
|
|
|
subject { get :readiness, request_params }
|
2017-04-07 06:27:15 -04:00
|
|
|
|
2017-07-06 07:36:16 -04:00
|
|
|
it 'responds with readiness checks data' do
|
|
|
|
subject
|
2017-04-07 06:27:15 -04:00
|
|
|
|
|
|
|
expect(json_response['db_check']['status']).to eq('ok')
|
2017-07-10 23:35:47 -04:00
|
|
|
expect(json_response['cache_check']['status']).to eq('ok')
|
|
|
|
expect(json_response['queues_check']['status']).to eq('ok')
|
|
|
|
expect(json_response['shared_state_check']['status']).to eq('ok')
|
2017-04-07 06:27:15 -04:00
|
|
|
expect(json_response['fs_shards_check']['status']).to eq('ok')
|
|
|
|
expect(json_response['fs_shards_check']['labels']['shard']).to eq('default')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-06 07:36:16 -04:00
|
|
|
context 'accessed from whitelisted ip' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::RequestContext).to receive(:client_ip).and_return(whitelisted_ip)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'endpoint responding with readiness data'
|
|
|
|
end
|
|
|
|
|
2017-07-03 11:09:34 -04:00
|
|
|
context 'accessed from not whitelisted ip' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::RequestContext).to receive(:client_ip).and_return(not_whitelisted_ip)
|
|
|
|
end
|
|
|
|
|
2017-07-06 07:36:16 -04:00
|
|
|
it 'responds with resource not found' do
|
2017-04-07 06:27:15 -04:00
|
|
|
get :readiness
|
2017-07-04 18:12:21 -04:00
|
|
|
|
2017-04-07 06:27:15 -04:00
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
2017-07-06 07:36:16 -04:00
|
|
|
|
|
|
|
context 'accessed with valid token' do
|
|
|
|
context 'token passed in request header' do
|
|
|
|
before do
|
|
|
|
request.headers['TOKEN'] = token
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'endpoint responding with readiness data'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'token passed as URL param' do
|
|
|
|
it_behaves_like 'endpoint responding with readiness data' do
|
2017-07-10 11:00:43 -04:00
|
|
|
let(:request_params) { { token: token } }
|
2017-07-06 07:36:16 -04:00
|
|
|
end
|
|
|
|
end
|
2017-04-07 06:27:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#liveness' do
|
2017-07-06 07:36:16 -04:00
|
|
|
shared_context 'endpoint responding with liveness data' do
|
|
|
|
subject { get :liveness }
|
2017-04-07 06:27:15 -04:00
|
|
|
|
2017-07-06 07:36:16 -04:00
|
|
|
it 'responds with liveness checks data' do
|
|
|
|
subject
|
2017-04-07 06:27:15 -04:00
|
|
|
|
|
|
|
expect(json_response['db_check']['status']).to eq('ok')
|
2017-07-10 23:35:47 -04:00
|
|
|
expect(json_response['cache_check']['status']).to eq('ok')
|
|
|
|
expect(json_response['queues_check']['status']).to eq('ok')
|
|
|
|
expect(json_response['shared_state_check']['status']).to eq('ok')
|
2017-04-07 06:27:15 -04:00
|
|
|
expect(json_response['fs_shards_check']['status']).to eq('ok')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-06 07:36:16 -04:00
|
|
|
context 'accessed from whitelisted ip' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::RequestContext).to receive(:client_ip).and_return(whitelisted_ip)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'endpoint responding with liveness data'
|
|
|
|
end
|
|
|
|
|
2017-07-03 11:09:34 -04:00
|
|
|
context 'accessed from not whitelisted ip' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::RequestContext).to receive(:client_ip).and_return(not_whitelisted_ip)
|
|
|
|
end
|
|
|
|
|
2017-07-06 07:36:16 -04:00
|
|
|
it 'responds with resource not found' do
|
2017-04-07 06:27:15 -04:00
|
|
|
get :liveness
|
2017-07-04 18:12:21 -04:00
|
|
|
|
2017-04-07 06:27:15 -04:00
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
2017-07-06 07:36:16 -04:00
|
|
|
|
|
|
|
context 'accessed with valid token' do
|
|
|
|
context 'token passed in request header' do
|
|
|
|
before do
|
|
|
|
request.headers['TOKEN'] = token
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'endpoint responding with liveness data'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'token passed as URL param' do
|
|
|
|
it_behaves_like 'endpoint responding with liveness data' do
|
|
|
|
subject { get :liveness, token: token }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-04-07 06:27:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|