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

Added Errno exceptions to be caught

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