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
7eb796e6
Commit
7eb796e6
authored
Apr 11, 2019
by
syasonik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inject dashboard response with db info
parent
185ec807
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
2 deletions
+94
-2
app/services/metrics_dashboard_processing_service.rb
app/services/metrics_dashboard_processing_service.rb
+88
-0
app/services/metrics_dashboard_service.rb
app/services/metrics_dashboard_service.rb
+6
-2
No files found.
app/services/metrics_dashboard_processing_service.rb
0 → 100644
View file @
7eb796e6
# frozen_string_literal: true
class
MetricsDashboardProcessingService
DEFAULT_PANEL_TYPE
=
'area-chart'
def
initialize
(
dashboard
,
project
)
@dashboard
=
dashboard
.
deep_transform_keys
(
&
:to_sym
)
@project
=
project
end
def
process
insert_persisted_metrics!
insert_metric_ids!
@dashboard
.
to_json
end
private
# Inserts project-specific metrics into the dashboard config.
# If there are no project-specific metrics, this will have no effect.
def
insert_persisted_metrics!
@project
.
prometheus_metrics
.
each
do
|
persisted_metric
|
group
=
find_or_create_group
(
@dashboard
[
:panel_groups
],
persisted_metric
)
panel
=
find_or_create_panel
(
group
[
:panels
],
persisted_metric
)
find_or_create_metric
(
panel
[
:metrics
],
persisted_metric
)
end
end
# For each metric in the dashboard config, attempts to find a corresponding
# persisted record. If found, includes the record id in the config.
def
insert_metric_ids!
@dashboard
[
:panel_groups
].
each
do
|
group
|
group
[
:panels
].
each
do
|
panel
|
panel
[
:metrics
].
each
do
|
metric
|
metric_record
=
common_metrics
.
find
{
|
m
|
m
.
identifier
==
metric
[
:id
]
}
metric
[
:metric_id
]
=
metric_record
.
id
if
metric_record
end
end
end
end
def
common_metrics
@common_metrics
||=
::
PrometheusMetric
.
common
end
def
find_or_create_group
(
panel_groups
,
metric
)
target_group
=
panel_groups
.
find
{
|
group
|
group
[
:group
]
==
metric
.
group_title
}
unless
target_group
target_group
=
{
group:
metric
.
group_title
,
priority:
metric
.
priority
,
panels:
[]
}
panel_groups
<<
target_group
end
target_group
end
def
find_or_create_panel
(
panels
,
metric
)
panel_identifiers
=
[
DEFAULT_PANEL_TYPE
,
metric
.
title
,
metric
.
y_label
]
target_panel
=
panels
.
find
{
|
panel
|
panel
.
values_at
(
:type
,
:title
,
:y_label
)
==
panel_identifiers
}
unless
target_panel
target_panel
=
{
type:
DEFAULT_PANEL_TYPE
,
title:
metric
.
title
,
y_label:
metric
.
y_label
,
metrics:
[]
}
panels
<<
target_panel
end
target_panel
end
def
find_or_create_metric
(
metrics
,
metric
)
target_metric
=
metrics
.
find
{
|
m
|
m
[
:id
]
==
metric
.
identifier
}
unless
target_metric
target_metric
=
metric
.
queries
.
first
.
merge
(
metric_id:
metric
.
id
)
metrics
<<
target_metric
end
target_metric
end
end
app/services/metrics_dashboard_service.rb
View file @
7eb796e6
...
@@ -3,7 +3,11 @@
...
@@ -3,7 +3,11 @@
# Fetches the metrics dashboard layout and supplemented the output with DB info.
# Fetches the metrics dashboard layout and supplemented the output with DB info.
class
MetricsDashboardService
class
MetricsDashboardService
SYSTEM_DASHBOARD_NAME
=
'system_dashboard'
SYSTEM_DASHBOARD_NAME
=
'system_dashboard'
SYSTEM_DASHBOARD_PATH
=
Rails
.
root
.
join
(
"config/prometheus"
,
"
#{
SYSTEM_DASHBOARD_NAME
}
.yml"
)
SYSTEM_DASHBOARD_PATH
=
Rails
.
root
.
join
(
'config'
,
'prometheus'
,
"
#{
SYSTEM_DASHBOARD_NAME
}
.yml"
)
def
initialize
(
project
)
@project
=
project
end
# Returns a DB-supplemented json representation of a dashboard config file.
# Returns a DB-supplemented json representation of a dashboard config file.
def
get_dashboard
def
get_dashboard
...
@@ -26,6 +30,6 @@ class MetricsDashboardService
...
@@ -26,6 +30,6 @@ class MetricsDashboardService
# TODO: "Processing" the dashboard needs to include several steps such as
# TODO: "Processing" the dashboard needs to include several steps such as
# inserting metric ids and alert information.
# inserting metric ids and alert information.
def
process_dashboard
(
dashboard
)
def
process_dashboard
(
dashboard
)
dashboard
.
to_json
MetricsDashboardProcessingService
.
new
(
dashboard
,
@project
).
process
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