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
Léo-Paul Géneau
gitlab-ce
Commits
b209fb6f
Commit
b209fb6f
authored
Apr 17, 2019
by
syasonik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor optimization and code clarity
parent
64a1fab7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
17 deletions
+24
-17
lib/gitlab/metrics_dashboard/project_metrics_inserter.rb
lib/gitlab/metrics_dashboard/project_metrics_inserter.rb
+14
-14
lib/gitlab/metrics_dashboard/sorter.rb
lib/gitlab/metrics_dashboard/sorter.rb
+2
-2
spec/lib/gitlab/metrics_dashboard/processor_spec.rb
spec/lib/gitlab/metrics_dashboard/processor_spec.rb
+8
-1
No files found.
lib/gitlab/metrics_dashboard/project_metrics_inserter.rb
View file @
b209fb6f
...
...
@@ -18,20 +18,6 @@ module Gitlab
private
# Looks for a panel corresponding to the provided metric object.
# If unavailable, inserts one.
# @param panels [Array<Hash>]
# @param metric [PrometheusMetric]
def
find_or_create_panel
(
panels
,
metric
)
panel
=
find_panel
(
panels
,
metric
)
return
panel
if
panel
panel
=
new_panel
(
metric
)
panels
<<
panel
panel
end
# Looks for a panel_group corresponding to the provided metric object.
# If unavailable, inserts one.
# @param panel_groups [Array<Hash>]
...
...
@@ -46,6 +32,20 @@ module Gitlab
panel_group
end
# Looks for a panel corresponding to the provided metric object.
# If unavailable, inserts one.
# @param panels [Array<Hash>]
# @param metric [PrometheusMetric]
def
find_or_create_panel
(
panels
,
metric
)
panel
=
find_panel
(
panels
,
metric
)
return
panel
if
panel
panel
=
new_panel
(
metric
)
panels
<<
panel
panel
end
# Looks for a metric corresponding to the provided metric object.
# If unavailable, inserts one.
# @param metrics [Array<Hash>]
...
...
lib/gitlab/metrics_dashboard/sorter.rb
View file @
b209fb6f
...
...
@@ -13,13 +13,13 @@ module Gitlab
# Sorts the groups in the dashboard by the :priority key
def
sort_groups!
(
dashboard
)
dashboard
[
:panel_groups
]
=
dashboard
[
:panel_groups
].
sort_by
{
|
group
|
group
[
:priority
]
}.
reverse
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!
(
dashboard
)
dashboard
[
:panel_groups
].
each
do
|
group
|
group
[
:panels
]
=
group
[
:panels
].
sort_by
{
|
panel
|
panel
[
:weight
]
}.
reverse
group
[
:panels
]
=
group
[
:panels
].
sort_by
{
|
panel
|
-
panel
[
:weight
].
to_i
}
end
end
end
...
...
spec/lib/gitlab/metrics_dashboard/processor_spec.rb
View file @
b209fb6f
...
...
@@ -31,7 +31,14 @@ describe Gitlab::MetricsDashboard::Processor do
end
it
'orders groups by priority and panels by weight'
do
expected_metrics_order
=
[
'metric_a2'
,
'metric_a1'
,
'metric_b'
,
project_business_metric
.
id
,
project_response_metric
.
id
,
project_system_metric
.
id
]
expected_metrics_order
=
[
'metric_a2'
,
# group priority 10, panel weight 2
'metric_a1'
,
# group priority 10, panel weight 1
'metric_b'
,
# group priority 1, panel weight 1
project_business_metric
.
id
,
# group priority 0, panel weight nil (0)
project_response_metric
.
id
,
# group priority -5, panel weight nil (0)
project_system_metric
.
id
,
# group priority -10, panel weight nil (0)
]
actual_metrics_order
=
all_metrics
.
map
{
|
m
|
m
[
:id
]
||
m
[
:metric_id
]
}
expect
(
actual_metrics_order
).
to
eq
expected_metrics_order
...
...
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