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
63a5d98a
Commit
63a5d98a
authored
May 02, 2017
by
Jose Ivan Vargas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added specs
parent
ad6ac17c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
5 deletions
+33
-5
lib/gitlab/prometheus.rb
lib/gitlab/prometheus.rb
+5
-5
spec/lib/gitlab/prometheus_spec.rb
spec/lib/gitlab/prometheus_spec.rb
+18
-0
spec/support/prometheus_helpers.rb
spec/support/prometheus_helpers.rb
+10
-0
No files found.
lib/gitlab/prometheus.rb
View file @
63a5d98a
...
@@ -49,11 +49,11 @@ module Gitlab
...
@@ -49,11 +49,11 @@ module Gitlab
end
end
def
get
(
url
)
def
get
(
url
)
begin
handle_response
(
HTTParty
.
get
(
url
))
handle_response
(
HTTParty
.
get
(
url
))
rescue
SocketError
rescue
SocketError
raise
PrometheusError
,
"Can't connect to
#{
url
}
"
raise
PrometheusError
,
"Can't connect to
#{
url
}
"
end
rescue
OpenSSL
::
SSL
::
SSLError
raise
PrometheusError
,
"
#{
url
}
contains invalid SSL data"
end
end
def
handle_response
(
response
)
def
handle_response
(
response
)
...
...
spec/lib/gitlab/prometheus_spec.rb
View file @
63a5d98a
...
@@ -49,6 +49,24 @@ describe Gitlab::Prometheus, lib: true do
...
@@ -49,6 +49,24 @@ describe Gitlab::Prometheus, lib: true do
end
end
end
end
describe
'failure to reach a prometheus url'
do
prometheus_invalid_url
=
'https://prometheus.invalid.example.com'
it
'raises a Gitlab::PrometheusError error when a SocketError is rescued'
do
req_stub
=
stub_prometheus_request_with_socket_exception
(
prometheus_invalid_url
)
expect
{
subject
.
send
(
:get
,
prometheus_invalid_url
)
}.
to
raise_error
(
Gitlab
::
PrometheusError
,
"Can't connect to
#{
prometheus_invalid_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
)
expect
{
subject
.
send
(
:get
,
prometheus_invalid_url
)
}.
to
raise_error
(
Gitlab
::
PrometheusError
,
"
#{
prometheus_invalid_url
}
contains invalid SSL data"
)
expect
(
req_stub
).
to
have_been_requested
end
end
describe
'#query'
do
describe
'#query'
do
let
(
:prometheus_query
)
{
prometheus_cpu_query
(
'env-slug'
)
}
let
(
:prometheus_query
)
{
prometheus_cpu_query
(
'env-slug'
)
}
let
(
:query_url
)
{
prometheus_query_url
(
prometheus_query
)
}
let
(
:query_url
)
{
prometheus_query_url
(
prometheus_query
)
}
...
...
spec/support/prometheus_helpers.rb
View file @
63a5d98a
...
@@ -33,6 +33,16 @@ module PrometheusHelpers
...
@@ -33,6 +33,16 @@ module PrometheusHelpers
})
})
end
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
)
end
def
stub_all_prometheus_requests
(
environment_slug
,
body:
nil
,
status:
200
)
def
stub_all_prometheus_requests
(
environment_slug
,
body:
nil
,
status:
200
)
stub_prometheus_request
(
stub_prometheus_request
(
prometheus_query_url
(
prometheus_memory_query
(
environment_slug
)),
prometheus_query_url
(
prometheus_memory_query
(
environment_slug
)),
...
...
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