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
05d55d88
Commit
05d55d88
authored
May 16, 2018
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract EE-specific code from Projects::Prometheus::MetricsController
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
4adccb3e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
77 deletions
+88
-77
app/controllers/projects/prometheus/metrics_controller.rb
app/controllers/projects/prometheus/metrics_controller.rb
+2
-77
ee/app/controllers/ee/projects/prometheus/metrics_controller.rb
.../controllers/ee/projects/prometheus/metrics_controller.rb
+86
-0
No files found.
app/controllers/projects/prometheus/metrics_controller.rb
View file @
05d55d88
module
Projects
module
Prometheus
class
MetricsController
<
Projects
::
ApplicationController
prepend
EE
::
Projects
::
Prometheus
::
MetricsController
before_action
:authorize_admin_project!
before_action
:require_prometheus_metrics!
...
...
@@ -18,85 +20,8 @@ module Projects
end
end
def
validate_query
respond_to
do
|
format
|
format
.
json
do
result
=
prometheus_adapter
.
query
(
:validate
,
params
[
:query
])
if
result
.
any?
render
json:
result
else
head
:no_content
end
end
end
end
def
new
@metric
=
project
.
prometheus_metrics
.
new
end
def
index
respond_to
do
|
format
|
format
.
json
do
metrics
=
project
.
prometheus_metrics
response
=
{}
if
metrics
.
any?
response
[
:metrics
]
=
PrometheusMetricSerializer
.
new
(
project:
project
)
.
represent
(
metrics
.
order
(
created_at: :asc
))
end
render
json:
response
end
end
end
def
create
@metric
=
project
.
prometheus_metrics
.
create
(
metrics_params
)
if
@metric
.
persisted?
redirect_to
edit_project_service_path
(
project
,
PrometheusService
),
notice:
'Metric was successfully added.'
else
render
'new'
end
end
def
update
@metric
=
project
.
prometheus_metrics
.
find
(
params
[
:id
])
@metric
.
update
(
metrics_params
)
if
@metric
.
persisted?
redirect_to
edit_project_service_path
(
project
,
PrometheusService
),
notice:
'Metric was successfully updated.'
else
render
'edit'
end
end
def
edit
@metric
=
project
.
prometheus_metrics
.
find
(
params
[
:id
])
end
def
destroy
metric
=
project
.
prometheus_metrics
.
find
(
params
[
:id
])
metric
.
destroy
respond_to
do
|
format
|
format
.
html
do
redirect_to
edit_project_service_path
(
project
,
PrometheusService
),
status:
303
end
format
.
json
do
head
:ok
end
end
end
private
def
metrics_params
params
.
require
(
:prometheus_metric
).
permit
(
:title
,
:query
,
:y_label
,
:unit
,
:legend
,
:group
)
end
def
prometheus_adapter
@prometheus_adapter
||=
::
Prometheus
::
AdapterService
.
new
(
project
).
prometheus_adapter
end
...
...
ee/app/controllers/ee/projects/prometheus/metrics_controller.rb
0 → 100644
View file @
05d55d88
module
EE
module
Projects
module
Prometheus
module
MetricsController
def
validate_query
respond_to
do
|
format
|
format
.
json
do
result
=
prometheus_adapter
.
query
(
:validate
,
params
[
:query
])
if
result
.
any?
render
json:
result
else
head
:no_content
end
end
end
end
def
new
@metric
=
project
.
prometheus_metrics
.
new
# rubocop:disable Gitlab/ModuleWithInstanceVariables
end
def
index
respond_to
do
|
format
|
format
.
json
do
metrics
=
project
.
prometheus_metrics
response
=
{}
if
metrics
.
any?
response
[
:metrics
]
=
::
PrometheusMetricSerializer
.
new
(
project:
project
)
.
represent
(
metrics
.
order
(
created_at: :asc
))
end
render
json:
response
end
end
end
def
create
@metric
=
project
.
prometheus_metrics
.
create
(
metrics_params
)
# rubocop:disable Gitlab/ModuleWithInstanceVariables
if
@metric
.
persisted?
# rubocop:disable Gitlab/ModuleWithInstanceVariables
redirect_to
edit_project_service_path
(
project
,
::
PrometheusService
),
notice:
'Metric was successfully added.'
else
render
'new'
end
end
def
update
@metric
=
project
.
prometheus_metrics
.
find
(
params
[
:id
])
# rubocop:disable Gitlab/ModuleWithInstanceVariables
@metric
.
update
(
metrics_params
)
# rubocop:disable Gitlab/ModuleWithInstanceVariables
if
@metric
.
persisted?
# rubocop:disable Gitlab/ModuleWithInstanceVariables
redirect_to
edit_project_service_path
(
project
,
::
PrometheusService
),
notice:
'Metric was successfully updated.'
else
render
'edit'
end
end
def
edit
@metric
=
project
.
prometheus_metrics
.
find
(
params
[
:id
])
# rubocop:disable Gitlab/ModuleWithInstanceVariables
end
def
destroy
metric
=
project
.
prometheus_metrics
.
find
(
params
[
:id
])
metric
.
destroy
respond_to
do
|
format
|
format
.
html
do
redirect_to
edit_project_service_path
(
project
,
::
PrometheusService
),
status:
303
end
format
.
json
do
head
:ok
end
end
end
private
def
metrics_params
params
.
require
(
:prometheus_metric
).
permit
(
:title
,
:query
,
:y_label
,
:unit
,
:legend
,
:group
)
end
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