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