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
6ca07bf8
Commit
6ca07bf8
authored
Apr 19, 2019
by
syasonik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make EE interactions and transformations cleaner
parent
9b746b4a
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
32 additions
and
26 deletions
+32
-26
app/controllers/projects/environments_controller.rb
app/controllers/projects/environments_controller.rb
+1
-1
lib/gitlab/metrics_dashboard/processor.rb
lib/gitlab/metrics_dashboard/processor.rb
+16
-9
lib/gitlab/metrics_dashboard/service.rb
lib/gitlab/metrics_dashboard/service.rb
+1
-1
lib/gitlab/metrics_dashboard/stages/base_stage.rb
lib/gitlab/metrics_dashboard/stages/base_stage.rb
+4
-5
lib/gitlab/metrics_dashboard/stages/common_metrics_inserter.rb
...itlab/metrics_dashboard/stages/common_metrics_inserter.rb
+2
-2
lib/gitlab/metrics_dashboard/stages/project_metrics_inserter.rb
...tlab/metrics_dashboard/stages/project_metrics_inserter.rb
+1
-1
lib/gitlab/metrics_dashboard/stages/sorter.rb
lib/gitlab/metrics_dashboard/stages/sorter.rb
+5
-5
spec/lib/gitlab/metrics_dashboard/processor_spec.rb
spec/lib/gitlab/metrics_dashboard/processor_spec.rb
+2
-2
No files found.
app/controllers/projects/environments_controller.rb
View file @
6ca07bf8
...
...
@@ -10,7 +10,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
before_action
:environment
,
only:
[
:show
,
:edit
,
:update
,
:stop
,
:terminal
,
:terminal_websocket_authorize
,
:metrics
]
before_action
:verify_api_request!
,
only: :terminal_websocket_authorize
before_action
:expire_etag_cache
,
only:
[
:index
]
before_action
only:
[
:metrics
,
:additional_metrics
]
do
before_action
only:
[
:metrics
,
:additional_metrics
,
:metrics_dashboard
]
do
push_frontend_feature_flag
(
:metrics_time_window
)
push_frontend_feature_flag
(
:environment_metrics_use_prometheus_endpoint
)
end
...
...
lib/gitlab/metrics_dashboard/processor.rb
View file @
6ca07bf8
...
...
@@ -2,26 +2,33 @@
module
Gitlab
module
MetricsDashboard
# Responsible for processesing a dashboard hash, inserting
# relevantDB records & sorting for proper rendering in
# the UI. These includes shared metric info, custom metrics
# info, and alerts (only in EE).
class
Processor
def
initialize
(
dashboard
,
project
,
environment
)
@dashboard
=
dashboard
.
deep_transform_keys
(
&
:to_sym
)
def
initialize
(
project
,
environment
)
@project
=
project
@environment
=
environment
end
def
s
tages
@stages
||=
[
def
s
equence
[
Stages
::
CommonMetricsInserter
,
Stages
::
ProjectMetricsInserter
,
Stages
::
Sorter
]
.
freeze
]
end
def
process
stage_params
=
[
@dashboard
,
@project
,
@environment
]
stages
.
each
{
|
stage
|
stage
.
new
(
*
stage_params
).
transform!
}
# Returns a new dashboard hash with the results of
# running transforms on the dashboard.
def
process
(
dashboard
)
dashboard
=
dashboard
.
deep_transform_keys
(
&
:to_sym
)
@dashboard
stage_params
=
[
@project
,
@environment
]
sequence
.
each
{
|
stage
|
stage
.
new
(
*
stage_params
).
transform!
(
dashboard
)
}
dashboard
end
end
end
...
...
lib/gitlab/metrics_dashboard/service.rb
View file @
6ca07bf8
...
...
@@ -28,7 +28,7 @@ module Gitlab
end
def
process_dashboard
(
dashboard
)
Processor
.
new
(
dashboard
,
project
,
params
[
:environment
]).
process
Processor
.
new
(
project
,
params
[
:environment
]).
process
(
dashboard
)
end
end
end
...
...
lib/gitlab/metrics_dashboard/stages/base_stage.rb
View file @
6ca07bf8
...
...
@@ -6,10 +6,9 @@ module Gitlab
class
BaseStage
DEFAULT_PANEL_TYPE
=
'area-chart'
attr_reader
:
dashboard
,
:
project
,
:environment
attr_reader
:project
,
:environment
def
initialize
(
dashboard
,
project
,
environment
)
@dashboard
=
dashboard
def
initialize
(
project
,
environment
)
@project
=
project
@environment
=
environment
end
...
...
@@ -18,13 +17,13 @@ module Gitlab
# @param dashboard [Hash]
# @param project [Project]
# @param environment [Environment]
def
transform!
def
transform!
(
_dashboard
)
raise
NotImplementedError
end
protected
def
for_metrics
def
for_metrics
(
dashboard
)
dashboard
[
:panel_groups
].
each
do
|
panel_group
|
panel_group
[
:panels
].
each
do
|
panel
|
panel
[
:metrics
].
each
do
|
metric
|
...
...
lib/gitlab/metrics_dashboard/stages/common_metrics_inserter.rb
View file @
6ca07bf8
...
...
@@ -7,10 +7,10 @@ module Gitlab
# For each metric in the dashboard config, attempts to
# find a corresponding database record. If found,
# includes the record's id in the dashboard config.
def
transform!
def
transform!
(
dashboard
)
common_metrics
=
::
PrometheusMetric
.
common
for_metrics
do
|
metric
|
for_metrics
(
dashboard
)
do
|
metric
|
metric_record
=
common_metrics
.
find
{
|
m
|
m
.
identifier
==
metric
[
:id
]
}
metric
[
:metric_id
]
=
metric_record
.
id
if
metric_record
end
...
...
lib/gitlab/metrics_dashboard/stages/project_metrics_inserter.rb
View file @
6ca07bf8
...
...
@@ -7,7 +7,7 @@ module Gitlab
# Inserts project-specific metrics into the dashboard
# config. If there are no project-specific metrics,
# this will have no effect.
def
transform!
def
transform!
(
dashboard
)
project
.
prometheus_metrics
.
each
do
|
project_metric
|
group
=
find_or_create_panel_group
(
dashboard
[
:panel_groups
],
project_metric
)
panel
=
find_or_create_panel
(
group
[
:panels
],
project_metric
)
...
...
lib/gitlab/metrics_dashboard/stages/sorter.rb
View file @
6ca07bf8
...
...
@@ -4,20 +4,20 @@ module Gitlab
module
MetricsDashboard
module
Stages
class
Sorter
<
BaseStage
def
transform!
sort_groups!
sort_panels!
def
transform!
(
dashboard
)
sort_groups!
(
dashboard
)
sort_panels!
(
dashboard
)
end
private
# Sorts the groups in the dashboard by the :priority key
def
sort_groups!
def
sort_groups!
(
dashboard
)
dashboard
[
:panel_groups
]
=
dashboard
[
:panel_groups
].
sort_by
{
|
group
|
-
group
[
:priority
].
to_i
}
end
# Sorts the panels in the dashboard by the :weight key
def
sort_panels!
def
sort_panels!
(
dashboard
)
dashboard
[
:panel_groups
].
each
do
|
group
|
group
[
:panels
]
=
group
[
:panels
].
sort_by
{
|
panel
|
-
panel
[
:weight
].
to_i
}
end
...
...
spec/lib/gitlab/metrics_dashboard/processor_spec.rb
View file @
6ca07bf8
...
...
@@ -8,8 +8,8 @@ describe Gitlab::MetricsDashboard::Processor do
let
(
:dashboard_yml
)
{
YAML
.
load_file
(
'spec/fixtures/lib/gitlab/metrics_dashboard/sample_dashboard.yml'
)
}
describe
'process'
do
let
(
:process_params
)
{
[
dashboard_yml
,
project
,
environment
]
}
let
(
:dashboard
)
{
described_class
.
new
(
*
process_params
).
process
}
let
(
:process_params
)
{
[
project
,
environment
]
}
let
(
:dashboard
)
{
described_class
.
new
(
*
process_params
).
process
(
dashboard_yml
)
}
context
'when dashboard config corresponds to common metrics'
do
let!
(
:common_metric
)
{
create
(
:prometheus_metric
,
:common
,
identifier:
'metric_a1'
)
}
...
...
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