2017-05-19 11:03:10 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe MetricsController do
|
|
|
|
include StubENV
|
|
|
|
|
|
|
|
let(:json_response) { JSON.parse(response.body) }
|
2017-06-06 22:24:30 -04:00
|
|
|
let(:metrics_multiproc_dir) { Dir.mktmpdir }
|
2017-07-03 11:09:34 -04:00
|
|
|
let(:whitelisted_ip) { '127.0.0.1' }
|
2017-07-04 17:50:18 -04:00
|
|
|
let(:whitelisted_ip_range) { '10.0.0.0/24' }
|
|
|
|
let(:ip_in_whitelisted_range) { '10.0.0.1' }
|
|
|
|
let(:not_whitelisted_ip) { '10.0.1.1' }
|
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-07-19 04:54:39 -04:00
|
|
|
allow(Prometheus::Client.configuration).to receive(:multiprocess_files_dir).and_return(metrics_multiproc_dir)
|
2017-05-22 13:49:34 -04:00
|
|
|
allow(Gitlab::Metrics).to receive(:prometheus_metrics_enabled?).and_return(true)
|
2017-07-04 17:50:18 -04:00
|
|
|
allow(Settings.monitoring).to receive(:ip_whitelist).and_return([whitelisted_ip, whitelisted_ip_range])
|
2017-05-19 11:03:10 -04:00
|
|
|
end
|
|
|
|
|
2017-05-29 17:23:19 -04:00
|
|
|
describe '#index' do
|
2017-07-04 17:50:18 -04:00
|
|
|
shared_examples_for 'endpoint providing metrics' do
|
2017-05-19 11:03:10 -04:00
|
|
|
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$/)
|
2017-07-12 08:48:46 -04:00
|
|
|
expect(response.body).to match(/^db_ping_latency_seconds [0-9\.]+$/)
|
2017-05-19 11:03:10 -04:00
|
|
|
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$/)
|
2017-07-12 08:48:46 -04:00
|
|
|
expect(response.body).to match(/^redis_ping_latency_seconds [0-9\.]+$/)
|
2017-05-19 11:03:10 -04:00
|
|
|
end
|
|
|
|
|
2017-07-10 23:35:47 -04:00
|
|
|
it 'returns Caching ping metrics' do
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(response.body).to match(/^redis_cache_ping_timeout 0$/)
|
|
|
|
expect(response.body).to match(/^redis_cache_ping_success 1$/)
|
2017-07-12 08:48:46 -04:00
|
|
|
expect(response.body).to match(/^redis_cache_ping_latency_seconds [0-9\.]+$/)
|
2017-07-10 23:35:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns Queues ping metrics' do
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(response.body).to match(/^redis_queues_ping_timeout 0$/)
|
|
|
|
expect(response.body).to match(/^redis_queues_ping_success 1$/)
|
2017-07-12 08:48:46 -04:00
|
|
|
expect(response.body).to match(/^redis_queues_ping_latency_seconds [0-9\.]+$/)
|
2017-07-10 23:35:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns SharedState ping metrics' do
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(response.body).to match(/^redis_shared_state_ping_timeout 0$/)
|
|
|
|
expect(response.body).to match(/^redis_shared_state_ping_success 1$/)
|
2017-07-12 08:48:46 -04:00
|
|
|
expect(response.body).to match(/^redis_shared_state_ping_latency_seconds [0-9\.]+$/)
|
2017-07-10 23:35:47 -04:00
|
|
|
end
|
|
|
|
|
2017-05-19 11:03:10 -04:00
|
|
|
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-07-12 08:48:46 -04:00
|
|
|
expect(response.body).to match(/^filesystem_access_latency_seconds{shard="default"} [0-9\.]+$/)
|
2017-05-19 11:03:10 -04:00
|
|
|
expect(response.body).to match(/^filesystem_accessible{shard="default"} 1$/)
|
2017-07-12 08:48:46 -04:00
|
|
|
expect(response.body).to match(/^filesystem_write_latency_seconds{shard="default"} [0-9\.]+$/)
|
2017-05-19 11:03:10 -04:00
|
|
|
expect(response.body).to match(/^filesystem_writable{shard="default"} 1$/)
|
2017-07-12 08:48:46 -04:00
|
|
|
expect(response.body).to match(/^filesystem_read_latency_seconds{shard="default"} [0-9\.]+$/)
|
2017-05-19 11:03:10 -04:00
|
|
|
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
|
|
|
|
|
2017-07-04 17:50:18 -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 providing metrics'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'accessed from ip in whitelisted range' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::RequestContext).to receive(:client_ip).and_return(ip_in_whitelisted_range)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'endpoint providing metrics'
|
|
|
|
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-05-19 11:03:10 -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-19 11:03:10 -04:00
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|