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
Boxiang Sun
gitlab-ce
Commits
a3a98039
Commit
a3a98039
authored
Apr 02, 2019
by
Peter Leitzen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract parsing JSON
parent
9817124f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
lib/gitlab/prometheus_client.rb
lib/gitlab/prometheus_client.rb
+8
-6
No files found.
lib/gitlab/prometheus_client.rb
View file @
a3a98039
...
...
@@ -85,8 +85,6 @@ module Gitlab
path
=
api_path
(
type
)
response
=
get
(
path
,
args
)
handle_response
(
response
)
rescue
JSON
::
ParserError
raise
PrometheusClient
::
Error
,
'Parsing response failed'
rescue
RestClient
::
ExceptionWithResponse
=>
ex
if
ex
.
response
handle_exception_response
(
ex
.
response
)
...
...
@@ -109,7 +107,7 @@ module Gitlab
end
def
handle_response
(
response
)
json_data
=
JSON
.
parse
(
response
.
body
)
json_data
=
parse_json
(
response
.
body
)
if
response
.
code
==
200
&&
json_data
[
'status'
]
==
'success'
json_data
[
'data'
]
||
{}
else
...
...
@@ -121,18 +119,22 @@ module Gitlab
if
response
.
code
==
200
&&
response
[
'status'
]
==
'success'
response
[
'data'
]
||
{}
elsif
response
.
code
==
400
json_data
=
JSON
.
parse
(
response
.
body
)
json_data
=
parse_json
(
response
.
body
)
raise
PrometheusClient
::
QueryError
,
json_data
[
'error'
]
||
'Bad data received'
else
raise
PrometheusClient
::
Error
,
"
#{
response
.
code
}
-
#{
response
.
body
}
"
end
rescue
JSON
::
ParserError
raise
PrometheusClient
::
Error
,
'Parsing response failed'
end
def
get_result
(
expected_type
)
data
=
yield
data
[
'result'
]
if
data
[
'resultType'
]
==
expected_type
end
def
parse_json
(
response_body
)
JSON
.
parse
(
response_body
)
rescue
JSON
::
ParserError
raise
PrometheusClient
::
Error
,
'Parsing response failed'
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