Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
da619cb5
Commit
da619cb5
authored
Dec 04, 2019
by
Etienne Baqué
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Errno exceptions to be caught
parent
6216e032
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
5 deletions
+21
-5
app/models/clusters/applications/prometheus.rb
app/models/clusters/applications/prometheus.rb
+1
-1
spec/models/clusters/applications/prometheus_spec.rb
spec/models/clusters/applications/prometheus_spec.rb
+20
-4
No files found.
app/models/clusters/applications/prometheus.rb
View file @
da619cb5
...
...
@@ -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,
...
...
spec/models/clusters/applications/prometheus_spec.rb
View file @
da619cb5
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment