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
1048ed4d
Commit
1048ed4d
authored
Nov 14, 2018
by
Shinya Maeda
Committed by
Kamil Trzciński
Nov 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid returning deployment metrics url to MR widget when the deployment is not successful
parent
f139ccf7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
4 deletions
+50
-4
app/models/deployment.rb
app/models/deployment.rb
+3
-3
app/serializers/environment_status_entity.rb
app/serializers/environment_status_entity.rb
+5
-1
changelogs/unreleased/fix-deployment-metrics-in-mr-widget.yml
...gelogs/unreleased/fix-deployment-metrics-in-mr-widget.yml
+6
-0
spec/serializers/environment_status_entity_spec.rb
spec/serializers/environment_status_entity_spec.rb
+36
-0
No files found.
app/models/deployment.rb
View file @
1048ed4d
...
...
@@ -160,18 +160,18 @@ class Deployment < ActiveRecord::Base
end
def
has_metrics?
prometheus_adapter
&
.
can_query?
prometheus_adapter
&
.
can_query?
&&
success?
end
def
metrics
return
{}
unless
has_metrics?
&&
success?
return
{}
unless
has_metrics?
metrics
=
prometheus_adapter
.
query
(
:deployment
,
self
)
metrics
&
.
merge
(
deployment_time:
finished_at
.
to_i
)
||
{}
end
def
additional_metrics
return
{}
unless
has_metrics?
&&
success?
return
{}
unless
has_metrics?
metrics
=
prometheus_adapter
.
query
(
:additional_metrics_deployment
,
self
)
metrics
&
.
merge
(
deployment_time:
finished_at
.
to_i
)
||
{}
...
...
app/serializers/environment_status_entity.rb
View file @
1048ed4d
...
...
@@ -11,7 +11,7 @@ class EnvironmentStatusEntity < Grape::Entity
project_environment_path
(
es
.
project
,
es
.
environment
)
end
expose
:metrics_url
,
if:
->
(
*
)
{
can_read_environment?
&&
environ
ment
.
has_metrics?
}
do
|
es
|
expose
:metrics_url
,
if:
->
(
*
)
{
can_read_environment?
&&
deploy
ment
.
has_metrics?
}
do
|
es
|
metrics_project_environment_deployment_path
(
es
.
project
,
es
.
environment
,
es
.
deployment
)
end
...
...
@@ -45,6 +45,10 @@ class EnvironmentStatusEntity < Grape::Entity
object
.
environment
end
def
deployment
object
.
deployment
end
def
project
object
.
environment
.
project
end
...
...
changelogs/unreleased/fix-deployment-metrics-in-mr-widget.yml
0 → 100644
View file @
1048ed4d
---
title
:
Avoid returning deployment metrics url to MR widget when the deployment is
not successful
merge_request
:
23010
author
:
type
:
fixed
spec/serializers/environment_status_entity_spec.rb
View file @
1048ed4d
...
...
@@ -40,4 +40,40 @@ describe EnvironmentStatusEntity do
it
{
is_expected
.
to
include
(
:stop_url
)
}
end
context
'when deployment has metrics'
do
let
(
:prometheus_adapter
)
{
double
(
'prometheus_adapter'
,
can_query?:
true
)
}
let
(
:simple_metrics
)
do
{
success:
true
,
metrics:
{},
last_update:
42
}
end
before
do
project
.
add_maintainer
(
user
)
allow
(
deployment
).
to
receive
(
:prometheus_adapter
).
and_return
(
prometheus_adapter
)
allow
(
prometheus_adapter
).
to
receive
(
:query
).
with
(
:deployment
,
deployment
).
and_return
(
simple_metrics
)
allow
(
entity
).
to
receive
(
:deployment
).
and_return
(
deployment
)
end
context
'when deployment succeeded'
do
let
(
:deployment
)
{
create
(
:deployment
,
:succeed
,
:review_app
)
}
it
'returns metrics url'
do
expect
(
subject
[
:metrics_url
])
.
to
eq
(
"/
#{
project
.
namespace
.
name
}
/
#{
project
.
name
}
/environments/
#{
environment
.
id
}
/deployments/
#{
deployment
.
iid
}
/metrics"
)
end
end
context
'when deployment is running'
do
let
(
:deployment
)
{
create
(
:deployment
,
:running
,
:review_app
)
}
it
'does not return metrics url'
do
expect
(
subject
[
:metrics_url
]).
to
be_nil
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