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
64e81195
Commit
64e81195
authored
May 02, 2017
by
Jose Ivan Vargas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved code styling and added a HTTParty rescue block
parent
63a5d98a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
22 deletions
+29
-22
lib/gitlab/prometheus.rb
lib/gitlab/prometheus.rb
+2
-0
spec/lib/gitlab/prometheus_spec.rb
spec/lib/gitlab/prometheus_spec.rb
+23
-11
spec/models/project_services/prometheus_service_spec.rb
spec/models/project_services/prometheus_service_spec.rb
+2
-3
spec/support/prometheus_helpers.rb
spec/support/prometheus_helpers.rb
+2
-8
No files found.
lib/gitlab/prometheus.rb
View file @
64e81195
...
...
@@ -54,6 +54,8 @@ module Gitlab
raise
PrometheusError
,
"Can't connect to
#{
url
}
"
rescue
OpenSSL
::
SSL
::
SSLError
raise
PrometheusError
,
"
#{
url
}
contains invalid SSL data"
rescue
HTTParty
::
Error
raise
PrometheusError
,
"An error has ocurred"
end
def
handle_response
(
response
)
...
...
spec/lib/gitlab/prometheus_spec.rb
View file @
64e81195
...
...
@@ -49,22 +49,34 @@ describe Gitlab::Prometheus, lib: true do
end
end
describe
'failure to reach a prometheus url'
do
prometheus_invalid_url
=
'https://prometheus.invalid.example.com'
describe
'failure to reach a pro
vided pro
metheus url'
do
let
(
:prometheus_url
)
{
"https://prometheus.invalid.example.com"
}
context
'exceptions are raised'
do
it
'raises a Gitlab::PrometheusError error when a SocketError is rescued'
do
req_stub
=
stub_prometheus_request_with_socket_exception
(
prometheus_invalid_url
)
req_stub
=
stub_prometheus_request_with_exception
(
prometheus_url
,
SocketError
)
expect
{
subject
.
send
(
:get
,
prometheus_invalid_url
)
}.
to
raise_error
(
Gitlab
::
PrometheusError
,
"Can't connect to
#{
prometheus_invalid_url
}
"
)
expect
{
subject
.
send
(
:get
,
prometheus_url
)
}
.
to
raise_error
(
Gitlab
::
PrometheusError
,
"Can't connect to
#{
prometheus_url
}
"
)
expect
(
req_stub
).
to
have_been_requested
end
it
'raises a Gitlab::PrometheusError error when a SSLError is rescued'
do
req_stub
=
stub_prometheus_request_with_ssl_exception
(
prometheus_invalid_url
)
req_stub
=
stub_prometheus_request_with_exception
(
prometheus_url
,
OpenSSL
::
SSL
::
SSLError
)
expect
{
subject
.
send
(
:get
,
prometheus_invalid_url
)
}.
to
raise_error
(
Gitlab
::
PrometheusError
,
"
#{
prometheus_invalid_url
}
contains invalid SSL data"
)
expect
{
subject
.
send
(
:get
,
prometheus_url
)
}
.
to
raise_error
(
Gitlab
::
PrometheusError
,
"
#{
prometheus_url
}
contains invalid SSL data"
)
expect
(
req_stub
).
to
have_been_requested
end
it
'raises a Gitlab::PrometheusError error when a HTTParty::Error is rescued'
do
req_stub
=
stub_prometheus_request_with_exception
(
prometheus_url
,
HTTParty
::
Error
)
expect
{
subject
.
send
(
:get
,
prometheus_url
)
}
.
to
raise_error
(
Gitlab
::
PrometheusError
,
"An error has ocurred"
)
expect
(
req_stub
).
to
have_been_requested
end
end
end
describe
'#query'
do
...
...
spec/models/project_services/prometheus_service_spec.rb
View file @
64e81195
...
...
@@ -93,12 +93,11 @@ describe PrometheusService, models: true, caching: true do
[
404
,
500
].
each
do
|
status
|
context
"when Prometheus responds with
#{
status
}
"
do
body_response
=
'QUERY_FAILED'
before
do
stub_all_prometheus_requests
(
environment
.
slug
,
status:
status
,
body:
body_response
)
stub_all_prometheus_requests
(
environment
.
slug
,
status:
status
,
body:
"QUERY FAILED!"
)
end
it
{
is_expected
.
to
eq
(
success:
false
,
result:
%(#{status} -
\"#{body_response}\
")
)
}
it
{
is_expected
.
to
eq
(
success:
false
,
result:
%(#{status} -
"QUERY FAILED!
")
)
}
end
end
end
...
...
spec/support/prometheus_helpers.rb
View file @
64e81195
...
...
@@ -33,14 +33,8 @@ module PrometheusHelpers
})
end
def
stub_prometheus_request_with_socket_exception
(
url
)
WebMock
.
stub_request
(
:get
,
url
)
.
to_raise
(
SocketError
)
end
def
stub_prometheus_request_with_ssl_exception
(
url
)
WebMock
.
stub_request
(
:get
,
url
)
.
to_raise
(
OpenSSL
::
SSL
::
SSLError
)
def
stub_prometheus_request_with_exception
(
url
,
exception_type
)
WebMock
.
stub_request
(
:get
,
url
).
to_raise
(
exception_type
)
end
def
stub_all_prometheus_requests
(
environment_slug
,
body:
nil
,
status:
200
)
...
...
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