Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
1596e555
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1596e555
编写于
4月 16, 2019
作者:
S
syasonik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cleanup misnamed or unnecessary files
上级
35c41232
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
1 addition
and
117 deletion
+1
-117
app/services/metrics_dashboard_processing_service.rb
app/services/metrics_dashboard_processing_service.rb
+0
-116
spec/fixtures/lib/gitlab/metrics_dashboard/sample_dashboard.yml
...ixtures/lib/gitlab/metrics_dashboard/sample_dashboard.yml
+0
-0
spec/lib/gitlab/metrics_dashboard/processor_spec.rb
spec/lib/gitlab/metrics_dashboard/processor_spec.rb
+1
-1
未找到文件。
app/services/metrics_dashboard_processing_service.rb
已删除
100644 → 0
浏览文件 @
35c41232
# 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_metric_ids!
sort_groups!
sort_panels!
insert_project_metrics!
@dashboard
.
to_json
end
private
# ------- Processing Steps -----------
# 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
insert_metric_ids!
for_metrics
do
|
metric
|
metric_record
=
common_metrics
.
find
{
|
m
|
m
.
identifier
==
metric
[
:id
]
}
metric
[
:metric_id
]
=
metric_record
.
id
if
metric_record
end
end
# Inserts project-specific metrics into the dashboard config.
# If there are no project-specific metrics, this will have no effect.
def
insert_project_metrics!
project_metrics
.
each
do
|
project_metric
|
group
=
find_or_create_group
(
@dashboard
[
:panel_groups
],
project_metric
)
panel
=
find_or_create_panel
(
group
[
:panels
],
project_metric
)
find_or_create_metric
(
panel
[
:metrics
],
project_metric
)
end
end
# Sorts the groups in the dashboard by the :priority key
def
sort_groups!
@dashboard
[
:panel_groups
]
=
@dashboard
[
:panel_groups
].
sort_by
{
|
group
|
group
[
:priority
]
}
end
# Sorts the panels in the dashboard by the :weight key
def
sort_panels!
@dashboard
[
:panel_groups
].
each
do
|
group
|
group
[
:panels
]
=
group
[
:panels
].
sort_by
{
|
panel
|
panel
[
:weight
]
}
end
end
# ------- Processing Helpers -----------
def
project_metrics
@project
.
prometheus_metrics
end
def
common_metrics
@common_metrics
||=
::
PrometheusMetric
.
common
end
def
for_metrics
@dashboard
[
:panel_groups
].
each
do
|
panel_group
|
panel_group
[
:panels
].
each
do
|
panel
|
panel
[
:metrics
].
each
do
|
metric
|
yield
metric
end
end
end
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
spec/fixtures/
services/metrics_dashboard_processing_service
.yml
→
spec/fixtures/
lib/gitlab/metrics_dashboard/sample_dashboard
.yml
浏览文件 @
1596e555
文件已移动
spec/lib/gitlab/metrics_dashboard/processor_spec.rb
浏览文件 @
1596e555
...
...
@@ -2,7 +2,7 @@ require 'spec_helper'
describe
Gitlab
::
MetricsDashboard
::
Processor
do
let
(
:project
)
{
build
(
:project
)
}
let
(
:dashboard_yml
)
{
YAML
.
load_file
(
'spec/fixtures/
services/metrics_dashboard_processing_service
.yml'
)
}
let
(
:dashboard_yml
)
{
YAML
.
load_file
(
'spec/fixtures/
lib/gitlab/metrics_dashboard/sample_dashboard
.yml'
)
}
describe
'process'
do
let
(
:dashboard
)
{
JSON
.
parse
(
described_class
.
new
(
dashboard_yml
,
project
).
process
,
symbolize_names:
true
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录