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
f38779c6
Commit
f38779c6
authored
May 12, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Respond with 404 when metrics are not enabled or deployment_metrics is not implemented
parent
2a89d2c9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
22 deletions
+53
-22
app/controllers/projects/deployments_controller.rb
app/controllers/projects/deployments_controller.rb
+3
-1
spec/controllers/projects/deployments_controller_spec.rb
spec/controllers/projects/deployments_controller_spec.rb
+50
-21
No files found.
app/controllers/projects/deployments_controller.rb
View file @
f38779c6
...
...
@@ -11,13 +11,15 @@ class Projects::DeploymentsController < Projects::ApplicationController
end
def
metrics
return
render_404
unless
deployment
.
has_metrics?
@metrics
=
deployment
.
metrics
if
@metrics
&
.
any?
render
json:
@metrics
,
status: :ok
else
head
:no_content
end
rescue
NotImplementedError
render_404
end
private
...
...
spec/controllers/projects/deployments_controller_spec.rb
View file @
f38779c6
...
...
@@ -42,39 +42,68 @@ describe Projects::DeploymentsController do
before
do
allow
(
controller
).
to
receive
(
:deployment
).
and_return
(
deployment
)
end
context
'when environment has no metrics'
do
context
'when metrics are disabled'
do
before
do
expect
(
deployment
).
to
receive
(
:metrics
).
and_return
(
nil
)
allow
(
deployment
).
to
receive
(
:has_metrics?
).
and_return
false
end
it
're
turns a empty response 204 resposne
'
do
it
're
sponds with not found
'
do
get
:metrics
,
deployment_params
(
id:
deployment
.
id
)
expect
(
response
).
to
have_http_status
(
204
)
expect
(
response
.
body
).
to
eq
(
''
)
expect
(
response
).
to
be_not_found
end
end
context
'when environment has some metrics'
do
let
(
:empty_metrics
)
do
{
success:
true
,
metrics:
{},
last_update:
42
}
context
'when metrics are enabled'
do
before
do
allow
(
deployment
).
to
receive
(
:has_metrics?
).
and_return
true
end
before
do
expect
(
deployment
).
to
receive
(
:metrics
).
and_return
(
empty_metrics
)
context
'when environment has no metrics'
do
before
do
expect
(
deployment
).
to
receive
(
:metrics
).
and_return
(
nil
)
end
it
'returns a empty response 204 resposne'
do
get
:metrics
,
deployment_params
(
id:
deployment
.
id
)
expect
(
response
).
to
have_http_status
(
204
)
expect
(
response
.
body
).
to
eq
(
''
)
end
end
it
'returns a metrics JSON document'
do
get
:metrics
,
deployment_params
(
id:
deployment
.
id
)
context
'when environment has some metrics'
do
let
(
:empty_metrics
)
do
{
success:
true
,
metrics:
{},
last_update:
42
}
end
before
do
expect
(
deployment
).
to
receive
(
:metrics
).
and_return
(
empty_metrics
)
end
it
'returns a metrics JSON document'
do
get
:metrics
,
deployment_params
(
id:
deployment
.
id
)
expect
(
response
).
to
be_ok
expect
(
json_response
[
'success'
]).
to
be
(
true
)
expect
(
json_response
[
'metrics'
]).
to
eq
({})
expect
(
json_response
[
'last_update'
]).
to
eq
(
42
)
end
end
context
'when metrics service does not implement deployment metrics'
do
before
do
allow
(
deployment
).
to
receive
(
:metrics
).
and_raise
(
NotImplementedError
)
end
it
'responds with not found'
do
get
:metrics
,
deployment_params
(
id:
deployment
.
id
)
expect
(
response
).
to
be_ok
expect
(
json_response
[
'success'
]).
to
be
(
true
)
expect
(
json_response
[
'metrics'
]).
to
eq
({})
expect
(
json_response
[
'last_update'
]).
to
eq
(
42
)
expect
(
response
).
to
be_not_found
end
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