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
Show 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
...
@@ -11,13 +11,15 @@ class Projects::DeploymentsController < Projects::ApplicationController
end
end
def
metrics
def
metrics
return
render_404
unless
deployment
.
has_metrics?
@metrics
=
deployment
.
metrics
@metrics
=
deployment
.
metrics
if
@metrics
&
.
any?
if
@metrics
&
.
any?
render
json:
@metrics
,
status: :ok
render
json:
@metrics
,
status: :ok
else
else
head
:no_content
head
:no_content
end
end
rescue
NotImplementedError
render_404
end
end
private
private
...
...
spec/controllers/projects/deployments_controller_spec.rb
View file @
f38779c6
...
@@ -42,6 +42,22 @@ describe Projects::DeploymentsController do
...
@@ -42,6 +42,22 @@ describe Projects::DeploymentsController do
before
do
before
do
allow
(
controller
).
to
receive
(
:deployment
).
and_return
(
deployment
)
allow
(
controller
).
to
receive
(
:deployment
).
and_return
(
deployment
)
end
end
context
'when metrics are disabled'
do
before
do
allow
(
deployment
).
to
receive
(
:has_metrics?
).
and_return
false
end
it
'responds with not found'
do
get
:metrics
,
deployment_params
(
id:
deployment
.
id
)
expect
(
response
).
to
be_not_found
end
end
context
'when metrics are enabled'
do
before
do
allow
(
deployment
).
to
receive
(
:has_metrics?
).
and_return
true
end
context
'when environment has no metrics'
do
context
'when environment has no metrics'
do
before
do
before
do
...
@@ -77,6 +93,19 @@ describe Projects::DeploymentsController do
...
@@ -77,6 +93,19 @@ describe Projects::DeploymentsController do
expect
(
json_response
[
'last_update'
]).
to
eq
(
42
)
expect
(
json_response
[
'last_update'
]).
to
eq
(
42
)
end
end
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_not_found
end
end
end
end
end
def
deployment_params
(
opts
=
{})
def
deployment_params
(
opts
=
{})
...
...
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