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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
0e90284c
Commit
0e90284c
authored
Feb 07, 2018
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Catch json parsing error as PrometheusError
parent
5209689d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
0 deletions
+12
-0
lib/gitlab/prometheus_client.rb
lib/gitlab/prometheus_client.rb
+2
-0
spec/lib/gitlab/prometheus_client_spec.rb
spec/lib/gitlab/prometheus_client_spec.rb
+10
-0
No files found.
lib/gitlab/prometheus_client.rb
View file @
0e90284c
...
@@ -42,6 +42,8 @@ module Gitlab
...
@@ -42,6 +42,8 @@ module Gitlab
def
json_api_get
(
type
,
args
=
{})
def
json_api_get
(
type
,
args
=
{})
path
=
[
'api'
,
'v1'
,
type
].
join
(
'/'
)
path
=
[
'api'
,
'v1'
,
type
].
join
(
'/'
)
get
(
path
,
args
)
get
(
path
,
args
)
rescue
JSON
::
ParserError
raise
PrometheusError
,
'Parsing response failed'
rescue
Errno
::
ECONNREFUSED
rescue
Errno
::
ECONNREFUSED
raise
PrometheusError
,
'Connection refused'
raise
PrometheusError
,
'Connection refused'
end
end
...
...
spec/lib/gitlab/prometheus_client_spec.rb
View file @
0e90284c
...
@@ -47,6 +47,16 @@ describe Gitlab::PrometheusClient do
...
@@ -47,6 +47,16 @@ describe Gitlab::PrometheusClient do
expect
(
req_stub
).
to
have_been_requested
expect
(
req_stub
).
to
have_been_requested
end
end
end
end
context
'when request returns non json data'
do
it
'raises a Gitlab::PrometheusError error'
do
req_stub
=
stub_prometheus_request
(
query_url
,
status:
200
,
body:
'not json'
)
expect
{
execute_query
}
.
to
raise_error
(
Gitlab
::
PrometheusError
,
'Parsing response failed'
)
expect
(
req_stub
).
to
have_been_requested
end
end
end
end
describe
'failure to reach a provided prometheus url'
do
describe
'failure to reach a provided prometheus url'
do
...
...
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