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
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
Show 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
...
@@ -23,7 +23,7 @@ class Projects::DeploymentsController < Projects::ApplicationController
end
end
def
additional_metrics
def
additional_metrics
return
render_404
unless
deployment
.
prometheus_service
.
present
?
return
render_404
unless
deployment
.
has_additional_metrics
?
metrics
=
deployment
.
additional_metrics
metrics
=
deployment
.
additional_metrics
...
...
app/controllers/projects/prometheus_controller.rb
View file @
6e4d5334
...
@@ -5,7 +5,7 @@ class Projects::PrometheusController < Projects::ApplicationController
...
@@ -5,7 +5,7 @@ class Projects::PrometheusController < Projects::ApplicationController
def
active_metrics
def
active_metrics
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
json
do
format
.
json
do
matched_metrics
=
prometheus_service
.
matched_metrics
||
{}
matched_metrics
=
pro
ject
.
pro
metheus_service
.
matched_metrics
||
{}
if
matched_metrics
.
any?
if
matched_metrics
.
any?
render
json:
matched_metrics
render
json:
matched_metrics
...
@@ -22,11 +22,7 @@ class Projects::PrometheusController < Projects::ApplicationController
...
@@ -22,11 +22,7 @@ class Projects::PrometheusController < Projects::ApplicationController
render_404
render_404
end
end
def
prometheus_service
@prometheus_service
||=
project
.
monitoring_services
.
reorder
(
nil
).
find_by
(
active:
true
,
type:
PrometheusService
.
name
)
end
def
require_prometheus_metrics!
def
require_prometheus_metrics!
render_404
unless
prometheus_service
.
present?
render_404
unless
pro
ject
.
pro
metheus_service
.
present?
end
end
end
end
app/models/deployment.rb
View file @
6e4d5334
...
@@ -114,17 +114,17 @@ class Deployment < ActiveRecord::Base
...
@@ -114,17 +114,17 @@ class Deployment < ActiveRecord::Base
project
.
monitoring_service
.
deployment_metrics
(
self
)
project
.
monitoring_service
.
deployment_metrics
(
self
)
end
end
def
has_additional_metrics?
project
.
prometheus_service
.
present?
end
def
additional_metrics
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
)
||
{}
metrics
&
.
merge
(
deployment_time:
created_at
.
to_i
)
||
{}
end
end
def
prometheus_service
@prometheus_service
||=
project
.
monitoring_services
.
reorder
(
nil
).
find_by
(
active:
true
,
type:
PrometheusService
.
name
)
end
private
private
def
ref_path
def
ref_path
...
...
app/models/environment.rb
View file @
6e4d5334
...
@@ -158,19 +158,15 @@ class Environment < ActiveRecord::Base
...
@@ -158,19 +158,15 @@ class Environment < ActiveRecord::Base
end
end
def
has_additional_metrics?
def
has_additional_metrics?
prometheus_service
.
present?
&&
available?
&&
last_deployment
.
present?
pro
ject
.
pro
metheus_service
.
present?
&&
available?
&&
last_deployment
.
present?
end
end
def
additional_metrics
def
additional_metrics
if
has_additional_metrics?
if
has_additional_metrics?
prometheus_service
.
additional_environment_metrics
(
self
)
pro
ject
.
pro
metheus_service
.
additional_environment_metrics
(
self
)
end
end
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
# 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
# or other third-party contexts, so provide a slugified version. A slug has
# the following properties:
# the following properties:
...
...
app/models/project.rb
View file @
6e4d5334
...
@@ -798,6 +798,10 @@ class Project < ActiveRecord::Base
...
@@ -798,6 +798,10 @@ class Project < ActiveRecord::Base
@monitoring_service
||=
monitoring_services
.
reorder
(
nil
).
find_by
(
active:
true
)
@monitoring_service
||=
monitoring_services
.
reorder
(
nil
).
find_by
(
active:
true
)
end
end
def
prometheus_service
@prometheus_service
||=
monitoring_services
.
find_by
(
active:
true
,
type:
PrometheusService
.
name
)
end
def
jira_tracker?
def
jira_tracker?
issues_tracker
.
to_param
==
'jira'
issues_tracker
.
to_param
==
'jira'
end
end
...
...
spec/controllers/projects/deployments_controller_spec.rb
View file @
6e4d5334
...
@@ -132,7 +132,7 @@ describe Projects::DeploymentsController do
...
@@ -132,7 +132,7 @@ describe Projects::DeploymentsController do
let
(
:prometheus_service
)
{
double
(
'prometheus_service'
)
}
let
(
:prometheus_service
)
{
double
(
'prometheus_service'
)
}
before
do
before
do
allow
(
deployment
).
to
receive
(
:prometheus_service
).
and_return
(
prometheus_service
)
allow
(
deployment
.
project
).
to
receive
(
:prometheus_service
).
and_return
(
prometheus_service
)
end
end
context
'when environment has no metrics'
do
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
...
@@ -8,7 +8,7 @@ describe Projects::PrometheusController do
before
do
before
do
allow
(
controller
).
to
receive
(
:project
).
and_return
(
project
)
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
)
project
.
add_master
(
user
)
sign_in
(
user
)
sign_in
(
user
)
...
...
spec/models/deployment_spec.rb
View file @
6e4d5334
...
@@ -91,7 +91,8 @@ describe Deployment, models: true do
...
@@ -91,7 +91,8 @@ describe Deployment, models: true do
end
end
describe
'#additional_metrics'
do
describe
'#additional_metrics'
do
let
(
:deployment
)
{
create
(
:deployment
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:deployment
)
{
create
(
:deployment
,
project:
project
)
}
subject
{
deployment
.
additional_metrics
}
subject
{
deployment
.
additional_metrics
}
...
@@ -111,7 +112,7 @@ describe Deployment, models: true do
...
@@ -111,7 +112,7 @@ describe Deployment, models: true do
let
(
:prometheus_service
)
{
double
(
'prometheus_service'
)
}
let
(
:prometheus_service
)
{
double
(
'prometheus_service'
)
}
before
do
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
)
allow
(
prometheus_service
).
to
receive
(
:additional_deployment_metrics
).
and_return
(
simple_metrics
)
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