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
6e4d5334
Commit
6e4d5334
authored
Jun 16, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move Prometheus service to project model
parent
be5f6655
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
21 additions
and
24 deletions
+21
-24
app/controllers/projects/deployments_controller.rb
app/controllers/projects/deployments_controller.rb
+1
-1
app/controllers/projects/prometheus_controller.rb
app/controllers/projects/prometheus_controller.rb
+2
-6
app/models/deployment.rb
app/models/deployment.rb
+6
-6
app/models/environment.rb
app/models/environment.rb
+2
-6
app/models/project.rb
app/models/project.rb
+4
-0
spec/controllers/projects/deployments_controller_spec.rb
spec/controllers/projects/deployments_controller_spec.rb
+1
-1
spec/controllers/projects/prometheus_controller_spec.rb
spec/controllers/projects/prometheus_controller_spec.rb
+1
-1
spec/models/deployment_spec.rb
spec/models/deployment_spec.rb
+4
-3
No files found.
app/controllers/projects/deployments_controller.rb
View file @
6e4d5334
...
...
@@ -23,7 +23,7 @@ class Projects::DeploymentsController < Projects::ApplicationController
end
def
additional_metrics
return
render_404
unless
deployment
.
prometheus_service
.
present
?
return
render_404
unless
deployment
.
has_additional_metrics
?
metrics
=
deployment
.
additional_metrics
...
...
app/controllers/projects/prometheus_controller.rb
View file @
6e4d5334
...
...
@@ -5,7 +5,7 @@ class Projects::PrometheusController < Projects::ApplicationController
def
active_metrics
respond_to
do
|
format
|
format
.
json
do
matched_metrics
=
prometheus_service
.
matched_metrics
||
{}
matched_metrics
=
pro
ject
.
pro
metheus_service
.
matched_metrics
||
{}
if
matched_metrics
.
any?
render
json:
matched_metrics
...
...
@@ -22,11 +22,7 @@ class Projects::PrometheusController < Projects::ApplicationController
render_404
end
def
prometheus_service
@prometheus_service
||=
project
.
monitoring_services
.
reorder
(
nil
).
find_by
(
active:
true
,
type:
PrometheusService
.
name
)
end
def
require_prometheus_metrics!
render_404
unless
prometheus_service
.
present?
render_404
unless
pro
ject
.
pro
metheus_service
.
present?
end
end
app/models/deployment.rb
View file @
6e4d5334
...
...
@@ -114,17 +114,17 @@ class Deployment < ActiveRecord::Base
project
.
monitoring_service
.
deployment_metrics
(
self
)
end
def
has_additional_metrics?
project
.
prometheus_service
.
present?
end
def
additional_metrics
return
{}
unless
prometheus_service
.
present?
return
{}
unless
pro
ject
.
pro
metheus_service
.
present?
metrics
=
prometheus_service
.
additional_deployment_metrics
(
self
)
metrics
=
pro
ject
.
pro
metheus_service
.
additional_deployment_metrics
(
self
)
metrics
&
.
merge
(
deployment_time:
created_at
.
to_i
)
||
{}
end
def
prometheus_service
@prometheus_service
||=
project
.
monitoring_services
.
reorder
(
nil
).
find_by
(
active:
true
,
type:
PrometheusService
.
name
)
end
private
def
ref_path
...
...
app/models/environment.rb
View file @
6e4d5334
...
...
@@ -158,19 +158,15 @@ class Environment < ActiveRecord::Base
end
def
has_additional_metrics?
prometheus_service
.
present?
&&
available?
&&
last_deployment
.
present?
pro
ject
.
pro
metheus_service
.
present?
&&
available?
&&
last_deployment
.
present?
end
def
additional_metrics
if
has_additional_metrics?
prometheus_service
.
additional_environment_metrics
(
self
)
pro
ject
.
pro
metheus_service
.
additional_environment_metrics
(
self
)
end
end
def
prometheus_service
@prometheus_service
||=
project
.
monitoring_services
.
reorder
(
nil
).
find_by
(
active:
true
,
type:
PrometheusService
.
name
)
end
# An environment name is not necessarily suitable for use in URLs, DNS
# or other third-party contexts, so provide a slugified version. A slug has
# the following properties:
...
...
app/models/project.rb
View file @
6e4d5334
...
...
@@ -798,6 +798,10 @@ class Project < ActiveRecord::Base
@monitoring_service
||=
monitoring_services
.
reorder
(
nil
).
find_by
(
active:
true
)
end
def
prometheus_service
@prometheus_service
||=
monitoring_services
.
find_by
(
active:
true
,
type:
PrometheusService
.
name
)
end
def
jira_tracker?
issues_tracker
.
to_param
==
'jira'
end
...
...
spec/controllers/projects/deployments_controller_spec.rb
View file @
6e4d5334
...
...
@@ -132,7 +132,7 @@ describe Projects::DeploymentsController do
let
(
:prometheus_service
)
{
double
(
'prometheus_service'
)
}
before
do
allow
(
deployment
).
to
receive
(
:prometheus_service
).
and_return
(
prometheus_service
)
allow
(
deployment
.
project
).
to
receive
(
:prometheus_service
).
and_return
(
prometheus_service
)
end
context
'when environment has no metrics'
do
...
...
spec/controllers/projects/prometheus_controller_spec.rb
View file @
6e4d5334
...
...
@@ -8,7 +8,7 @@ describe Projects::PrometheusController do
before
do
allow
(
controller
).
to
receive
(
:project
).
and_return
(
project
)
allow
(
controller
).
to
receive
(
:prometheus_service
).
and_return
(
prometheus_service
)
allow
(
project
).
to
receive
(
:prometheus_service
).
and_return
(
prometheus_service
)
project
.
add_master
(
user
)
sign_in
(
user
)
...
...
spec/models/deployment_spec.rb
View file @
6e4d5334
...
...
@@ -30,7 +30,7 @@ describe Deployment, models: true do
end
describe
'#includes_commit?'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
let
(
:deployment
)
do
create
(
:deployment
,
environment:
environment
,
sha:
project
.
commit
.
id
)
...
...
@@ -91,7 +91,8 @@ describe Deployment, models: true do
end
describe
'#additional_metrics'
do
let
(
:deployment
)
{
create
(
:deployment
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:deployment
)
{
create
(
:deployment
,
project:
project
)
}
subject
{
deployment
.
additional_metrics
}
...
...
@@ -111,7 +112,7 @@ describe Deployment, models: true do
let
(
:prometheus_service
)
{
double
(
'prometheus_service'
)
}
before
do
allow
(
deploymen
t
).
to
receive
(
:prometheus_service
).
and_return
(
prometheus_service
)
allow
(
projec
t
).
to
receive
(
:prometheus_service
).
and_return
(
prometheus_service
)
allow
(
prometheus_service
).
to
receive
(
:additional_deployment_metrics
).
and_return
(
simple_metrics
)
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