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
8ad9cd55
Commit
8ad9cd55
authored
Mar 01, 2018
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement PrometheusDeploymentLocator + fix metrics controller
parent
2c090539
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
27 deletions
+31
-27
app/controllers/projects/prometheus/metrics_controller.rb
app/controllers/projects/prometheus/metrics_controller.rb
+2
-4
app/models/concerns/prometheus_adapter_locator.rb
app/models/concerns/prometheus_adapter_locator.rb
+26
-0
app/models/environment.rb
app/models/environment.rb
+2
-21
spec/controllers/projects/prometheus/metrics_controller_spec.rb
...ontrollers/projects/prometheus/metrics_controller_spec.rb
+1
-2
No files found.
app/controllers/projects/prometheus/metrics_controller.rb
View file @
8ad9cd55
module
Projects
module
Prometheus
class
MetricsController
<
Projects
::
ApplicationController
include
PrometheusAdapterLocator
before_action
:authorize_admin_project!
before_action
:require_prometheus_metrics!
...
...
@@ -20,10 +22,6 @@ module Projects
private
def
prometheus_adapter
project
.
prometheus_service
end
def
require_prometheus_metrics!
render_404
unless
prometheus_adapter
.
can_query?
end
...
...
app/models/concerns/prometheus_adapter_locator.rb
0 → 100644
View file @
8ad9cd55
module
PrometheusAdapterLocator
def
deployment_platform
project
.
deployment_platform
end
def
prometheus_adapter
@prometheus_adapter
||=
if
service_prometheus_adapter
.
can_query?
service_prometheus_adapter
else
cluster_prometheus_adapter
end
end
def
service_prometheus_adapter
project
.
find_or_initialize_service
(
'prometheus'
)
end
def
cluster_prometheus_adapter
return
unless
deployment_platform
.
respond_to?
(
:cluster
)
cluster
=
deployment_platform
.
cluster
return
unless
cluster
.
application_prometheus
&
.
installed?
cluster
.
application_prometheus
end
end
\ No newline at end of file
app/models/environment.rb
View file @
8ad9cd55
class
Environment
<
ActiveRecord
::
Base
include
PrometheusAdapterLocator
# Used to generate random suffixes for the slug
LETTERS
=
'a'
..
'z'
NUMBERS
=
'0'
..
'9'
...
...
@@ -224,27 +226,6 @@ class Environment < ActiveRecord::Base
project
.
deployment_platform
end
def
prometheus_adapter
@prometheus_adapter
||=
if
service_prometheus_adapter
.
can_query?
service_prometheus_adapter
else
cluster_prometheus_adapter
end
end
def
service_prometheus_adapter
project
.
find_or_initialize_service
(
'prometheus'
)
end
def
cluster_prometheus_adapter
return
unless
deployment_platform
.
respond_to?
(
:cluster
)
cluster
=
deployment_platform
.
cluster
return
unless
cluster
.
application_prometheus
&
.
installed?
cluster
.
application_prometheus
end
private
# Slugifying a name may remove the uniqueness guarantee afforded by it being
...
...
spec/controllers/projects/prometheus/metrics_controller_spec.rb
View file @
8ad9cd55
...
...
@@ -7,8 +7,7 @@ describe Projects::Prometheus::MetricsController do
let
(
:prometheus_adapter
)
{
double
(
'prometheus_adapter'
,
can_query?:
true
)
}
before
do
allow
(
controller
).
to
receive
(
:project
).
and_return
(
project
)
allow
(
project
).
to
receive
(
:prometheus_service
).
and_return
(
prometheus_adapter
)
allow
(
controller
).
to
receive
(
:prometheus_adapter
).
and_return
(
prometheus_adapter
)
project
.
add_master
(
user
)
sign_in
(
user
)
...
...
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