BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
0 deletions
+12
-0
prometheus_client.rb
lib/gitlab/prometheus_client.rb
+2
-0
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