Commit da619cb5 authored by Etienne Baqué's avatar Etienne Baqué

Added Errno exceptions to be caught

parent 6216e032
......@@ -84,7 +84,7 @@ module Clusters
# ensures headers containing auth data are appended to original k8s client options
options = kube_client.rest_client.options.merge(headers: kube_client.headers)
Gitlab::PrometheusClient.new(proxy_url, options)
rescue Kubeclient::HttpError
rescue Kubeclient::HttpError, Errno::ECONNRESET, Errno::ECONNREFUSED
# If users have mistakenly set parameters or removed the depended clusters,
# `proxy_url` could raise an exception because gitlab can not communicate with the cluster.
# Since `PrometheusAdapter#can_query?` is eargely loaded on environement pages in gitlab,
......
......@@ -53,6 +53,16 @@ describe Clusters::Applications::Prometheus do
end
describe '#prometheus_client' do
shared_examples 'exception caught for prometheus client' do
before do
allow(kube_client).to receive(:proxy_url).and_raise(exception)
end
it 'returns nil' do
expect(subject.prometheus_client).to be_nil
end
end
context 'cluster is nil' do
it 'returns nil' do
expect(subject.cluster).to be_nil
......@@ -98,12 +108,18 @@ describe Clusters::Applications::Prometheus do
end
context 'when cluster is not reachable' do
before do
allow(kube_client).to receive(:proxy_url).and_raise(Kubeclient::HttpError.new(401, 'Unauthorized', nil))
it_behaves_like 'exception caught for prometheus client' do
let(:exception) { Kubeclient::HttpError.new(401, 'Unauthorized', nil) }
end
end
context 'when there is a socket error while contacting cluster' do
it_behaves_like 'exception caught for prometheus client' do
let(:exception) { Errno::ECONNREFUSED }
end
it 'returns nil' do
expect(subject.prometheus_client).to be_nil
it_behaves_like 'exception caught for prometheus client' do
let(:exception) { Errno::ECONNRESET }
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