2017-05-19 11:03:10 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe MetricsController do
|
|
|
|
include StubENV
|
|
|
|
|
|
|
|
let(:token) { current_application_settings.health_check_access_token }
|
|
|
|
let(:json_response) { JSON.parse(response.body) }
|
2017-06-06 22:24:30 -04:00
|
|
|
let(:metrics_multiproc_dir) { Dir.mktmpdir }
|
2017-05-22 13:49:34 -04:00
|
|
|
|
2017-05-19 11:03:10 -04:00
|
|
|
before do
|
|
|
|
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
|
2017-06-06 22:24:30 -04:00
|
|
|
stub_env('prometheus_multiproc_dir', metrics_multiproc_dir)
|
2017-05-22 13:49:34 -04:00
|
|
|
allow(Gitlab::Metrics).to receive(:prometheus_metrics_enabled?).and_return(true)
|
2017-05-19 11:03:10 -04:00
|
|
|
end
|
|
|
|
|
2017-05-29 17:23:19 -04:00
|
|
|
describe '#index' do
|
2017-05-19 11:03:10 -04:00
|
|
|
context 'authorization token provided' do
|
|
|
|
before do
|
|
|
|
request.headers['TOKEN'] = token
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns DB ping metrics' do
|
2017-05-29 17:23:19 -04:00
|
|
|
get :index
|
2017-05-23 10:09:00 -04:00
|
|
|
|
2017-05-19 11:03:10 -04:00
|
|
|
expect(response.body).to match(/^db_ping_timeout 0$/)
|
|
|
|
expect(response.body).to match(/^db_ping_success 1$/)
|
|
|
|
expect(response.body).to match(/^db_ping_latency [0-9\.]+$/)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns Redis ping metrics' do
|
2017-05-29 17:23:19 -04:00
|
|
|
get :index
|
2017-05-23 10:09:00 -04:00
|
|
|
|
2017-05-19 11:03:10 -04:00
|
|
|
expect(response.body).to match(/^redis_ping_timeout 0$/)
|
|
|
|
expect(response.body).to match(/^redis_ping_success 1$/)
|
|
|
|
expect(response.body).to match(/^redis_ping_latency [0-9\.]+$/)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns file system check metrics' do
|
2017-05-29 17:23:19 -04:00
|
|
|
get :index
|
2017-05-23 10:09:00 -04:00
|
|
|
|
2017-05-19 11:03:10 -04:00
|
|
|
expect(response.body).to match(/^filesystem_access_latency{shard="default"} [0-9\.]+$/)
|
|
|
|
expect(response.body).to match(/^filesystem_accessible{shard="default"} 1$/)
|
|
|
|
expect(response.body).to match(/^filesystem_write_latency{shard="default"} [0-9\.]+$/)
|
|
|
|
expect(response.body).to match(/^filesystem_writable{shard="default"} 1$/)
|
|
|
|
expect(response.body).to match(/^filesystem_read_latency{shard="default"} [0-9\.]+$/)
|
|
|
|
expect(response.body).to match(/^filesystem_readable{shard="default"} 1$/)
|
|
|
|
end
|
2017-05-23 08:55:31 -04:00
|
|
|
|
|
|
|
context 'prometheus metrics are disabled' do
|
2017-05-23 09:42:36 -04:00
|
|
|
before do
|
|
|
|
allow(Gitlab::Metrics).to receive(:prometheus_metrics_enabled?).and_return(false)
|
|
|
|
end
|
2017-05-23 08:55:31 -04:00
|
|
|
|
|
|
|
it 'returns proper response' do
|
2017-05-29 17:23:19 -04:00
|
|
|
get :index
|
2017-05-23 10:09:00 -04:00
|
|
|
|
2017-05-23 08:55:31 -04:00
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
2017-05-19 11:03:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'without authorization token' do
|
|
|
|
it 'returns proper response' do
|
2017-05-29 17:23:19 -04:00
|
|
|
get :index
|
2017-05-23 10:09:00 -04:00
|
|
|
|
2017-05-19 11:03:10 -04:00
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|