Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
41070c6e
未验证
提交
41070c6e
编辑于
4 years ago
作者:
David Fernandez
浏览文件
操作
下载
补丁
差异文件
Move container_expiration_policies_usage to counts
上级
10e35363
No related branches found
No related tags found
无相关合并请求
变更
3
隐藏空白变更内容
行内
左右并排
显示
3 个更改的文件
lib/gitlab/usage_data.rb
+26
-25
26 个添加, 25 个删除
lib/gitlab/usage_data.rb
spec/lib/gitlab/usage_data_spec.rb
+40
-37
40 个添加, 37 个删除
spec/lib/gitlab/usage_data_spec.rb
spec/support/helpers/usage_data_helpers.rb
+18
-19
18 个添加, 19 个删除
spec/support/helpers/usage_data_helpers.rb
有
84 个添加
和
81 个删除
lib/gitlab/usage_data.rb
+
26
−
25
浏览文件 @
41070c6e
...
@@ -141,7 +141,8 @@ def system_usage_data
...
@@ -141,7 +141,8 @@ def system_usage_data
services_usage
,
services_usage
,
usage_counters
,
usage_counters
,
user_preferences_usage
,
user_preferences_usage
,
ingress_modsecurity_usage
ingress_modsecurity_usage
,
container_expiration_policies_usage
)
)
}
}
end
end
...
@@ -182,31 +183,8 @@ def features_usage_data_ce
...
@@ -182,31 +183,8 @@ def features_usage_data_ce
web_ide_clientside_preview_enabled:
alt_usage_data
{
Gitlab
::
CurrentSettings
.
web_ide_clientside_preview_enabled?
},
web_ide_clientside_preview_enabled:
alt_usage_data
{
Gitlab
::
CurrentSettings
.
web_ide_clientside_preview_enabled?
},
ingress_modsecurity_enabled:
Feature
.
enabled?
(
:ingress_modsecurity
),
ingress_modsecurity_enabled:
Feature
.
enabled?
(
:ingress_modsecurity
),
grafana_link_enabled:
alt_usage_data
{
Gitlab
::
CurrentSettings
.
grafana_enabled?
}
grafana_link_enabled:
alt_usage_data
{
Gitlab
::
CurrentSettings
.
grafana_enabled?
}
}.
merge
(
features_usage_data_container_expiration_policies
)
}
end
# rubocop: disable CodeReuse/ActiveRecord
def
features_usage_data_container_expiration_policies
results
=
{}
start
=
::
Project
.
minimum
(
:id
)
finish
=
::
Project
.
maximum
(
:id
)
results
[
:projects_with_expiration_policy_disabled
]
=
distinct_count
(
::
ContainerExpirationPolicy
.
where
(
enabled:
false
),
:project_id
,
start:
start
,
finish:
finish
)
base
=
::
ContainerExpirationPolicy
.
active
results
[
:projects_with_expiration_policy_enabled
]
=
distinct_count
(
base
,
:project_id
,
start:
start
,
finish:
finish
)
%i[keep_n cadence older_than]
.
each
do
|
option
|
::
ContainerExpirationPolicy
.
public_send
(
"
#{
option
}
_options"
).
keys
.
each
do
|
value
|
# rubocop: disable GitlabSecurity/PublicSend
results
[
"projects_with_expiration_policy_enabled_with_
#{
option
}
_set_to_
#{
value
}
"
.
to_sym
]
=
distinct_count
(
base
.
where
(
option
=>
value
),
:project_id
,
start:
start
,
finish:
finish
)
end
end
results
[
:projects_with_expiration_policy_enabled_with_keep_n_unset
]
=
distinct_count
(
base
.
where
(
keep_n:
nil
),
:project_id
,
start:
start
,
finish:
finish
)
results
[
:projects_with_expiration_policy_enabled_with_older_than_unset
]
=
distinct_count
(
base
.
where
(
older_than:
nil
),
:project_id
,
start:
start
,
finish:
finish
)
results
end
end
# rubocop: enable CodeReuse/ActiveRecord
# @return [Hash<Symbol, Integer>]
# @return [Hash<Symbol, Integer>]
def
usage_counters
def
usage_counters
...
@@ -312,6 +290,29 @@ def ingress_modsecurity_usage
...
@@ -312,6 +290,29 @@ def ingress_modsecurity_usage
}
}
end
end
# rubocop: disable CodeReuse/ActiveRecord
def
container_expiration_policies_usage
results
=
{}
start
=
::
Project
.
minimum
(
:id
)
finish
=
::
Project
.
maximum
(
:id
)
results
[
:projects_with_expiration_policy_disabled
]
=
distinct_count
(
::
ContainerExpirationPolicy
.
where
(
enabled:
false
),
:project_id
,
start:
start
,
finish:
finish
)
base
=
::
ContainerExpirationPolicy
.
active
results
[
:projects_with_expiration_policy_enabled
]
=
distinct_count
(
base
,
:project_id
,
start:
start
,
finish:
finish
)
%i[keep_n cadence older_than]
.
each
do
|
option
|
::
ContainerExpirationPolicy
.
public_send
(
"
#{
option
}
_options"
).
keys
.
each
do
|
value
|
# rubocop: disable GitlabSecurity/PublicSend
results
[
"projects_with_expiration_policy_enabled_with_
#{
option
}
_set_to_
#{
value
}
"
.
to_sym
]
=
distinct_count
(
base
.
where
(
option
=>
value
),
:project_id
,
start:
start
,
finish:
finish
)
end
end
results
[
:projects_with_expiration_policy_enabled_with_keep_n_unset
]
=
distinct_count
(
base
.
where
(
keep_n:
nil
),
:project_id
,
start:
start
,
finish:
finish
)
results
[
:projects_with_expiration_policy_enabled_with_older_than_unset
]
=
distinct_count
(
base
.
where
(
older_than:
nil
),
:project_id
,
start:
start
,
finish:
finish
)
results
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
services_usage
def
services_usage
results
=
Service
.
available_services_names
.
without
(
'jira'
).
each_with_object
({})
do
|
service_name
,
response
|
results
=
Service
.
available_services_names
.
without
(
'jira'
).
each_with_object
({})
do
|
service_name
,
response
|
...
...
此差异已折叠。
点击以展开。
spec/lib/gitlab/usage_data_spec.rb
+
40
−
37
浏览文件 @
41070c6e
...
@@ -97,6 +97,46 @@
...
@@ -97,6 +97,46 @@
)
)
end
end
context
'with existing container expiration policies'
do
let_it_be
(
:disabled
)
{
create
(
:container_expiration_policy
,
enabled:
false
)
}
let_it_be
(
:enabled
)
{
create
(
:container_expiration_policy
,
enabled:
true
)
}
%i[keep_n cadence older_than]
.
each
do
|
attribute
|
ContainerExpirationPolicy
.
send
(
"
#{
attribute
}
_options"
).
keys
.
each
do
|
value
|
let_it_be
(
"container_expiration_policy_with_
#{
attribute
}
_set_to_
#{
value
}
"
)
{
create
(
:container_expiration_policy
,
attribute
=>
value
)
}
end
end
let
(
:inactive_policies
)
{
::
ContainerExpirationPolicy
.
where
(
enabled:
false
)
}
let
(
:active_policies
)
{
::
ContainerExpirationPolicy
.
active
}
subject
{
described_class
.
data
[
:counts
]
}
it
'gathers usage data'
do
expect
(
subject
[
:projects_with_expiration_policy_enabled
]).
to
eq
20
expect
(
subject
[
:projects_with_expiration_policy_disabled
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_unset
]).
to
eq
14
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_set_to_1
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_set_to_5
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_set_to_10
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_set_to_25
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_set_to_50
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_older_than_unset
]).
to
eq
16
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_older_than_set_to_7d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_older_than_set_to_14d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_older_than_set_to_30d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_older_than_set_to_90d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_cadence_set_to_1d
]).
to
eq
12
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_cadence_set_to_7d
]).
to
eq
5
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_cadence_set_to_14d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_cadence_set_to_1month
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_cadence_set_to_3month
]).
to
eq
1
end
end
it
'works when queries time out'
do
it
'works when queries time out'
do
allow_any_instance_of
(
ActiveRecord
::
Relation
)
allow_any_instance_of
(
ActiveRecord
::
Relation
)
.
to
receive
(
:count
).
and_raise
(
ActiveRecord
::
StatementInvalid
.
new
(
''
))
.
to
receive
(
:count
).
and_raise
(
ActiveRecord
::
StatementInvalid
.
new
(
''
))
...
@@ -190,43 +230,6 @@
...
@@ -190,43 +230,6 @@
expect
(
subject
[
:grafana_link_enabled
]).
to
eq
(
false
)
expect
(
subject
[
:grafana_link_enabled
]).
to
eq
(
false
)
end
end
end
end
context
'with existing container expiration policies'
do
let_it_be
(
:disabled
)
{
create
(
:container_expiration_policy
,
enabled:
false
)
}
let_it_be
(
:enabled
)
{
create
(
:container_expiration_policy
,
enabled:
true
)
}
%i[keep_n cadence older_than]
.
each
do
|
attribute
|
ContainerExpirationPolicy
.
send
(
"
#{
attribute
}
_options"
).
keys
.
each
do
|
value
|
let_it_be
(
"container_expiration_policy_with_
#{
attribute
}
_set_to_
#{
value
}
"
)
{
create
(
:container_expiration_policy
,
attribute
=>
value
)
}
end
end
let
(
:inactive_policies
)
{
::
ContainerExpirationPolicy
.
where
(
enabled:
false
)
}
let
(
:active_policies
)
{
::
ContainerExpirationPolicy
.
active
}
it
'gathers usage data'
do
expect
(
subject
[
:projects_with_expiration_policy_enabled
]).
to
eq
16
expect
(
subject
[
:projects_with_expiration_policy_disabled
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_unset
]).
to
eq
10
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_set_to_1
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_set_to_5
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_set_to_10
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_set_to_25
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_keep_n_set_to_50
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_older_than_unset
]).
to
eq
12
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_older_than_set_to_7d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_older_than_set_to_14d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_older_than_set_to_30d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_older_than_set_to_90d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_cadence_set_to_1d
]).
to
eq
12
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_cadence_set_to_7d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_cadence_set_to_14d
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_cadence_set_to_1month
]).
to
eq
1
expect
(
subject
[
:projects_with_expiration_policy_enabled_with_cadence_set_to_3month
]).
to
eq
1
end
end
end
end
describe
'#components_usage_data'
do
describe
'#components_usage_data'
do
...
...
此差异已折叠。
点击以展开。
spec/support/helpers/usage_data_helpers.rb
+
18
−
19
浏览文件 @
41070c6e
...
@@ -99,6 +99,24 @@ module UsageDataHelpers
...
@@ -99,6 +99,24 @@ module UsageDataHelpers
projects_with_error_tracking_enabled
projects_with_error_tracking_enabled
projects_with_alerts_service_enabled
projects_with_alerts_service_enabled
projects_with_prometheus_alerts
projects_with_prometheus_alerts
projects_with_expiration_policy_enabled
projects_with_expiration_policy_disabled
projects_with_expiration_policy_enabled_with_keep_n_unset
projects_with_expiration_policy_enabled_with_keep_n_set_to_1
projects_with_expiration_policy_enabled_with_keep_n_set_to_5
projects_with_expiration_policy_enabled_with_keep_n_set_to_10
projects_with_expiration_policy_enabled_with_keep_n_set_to_25
projects_with_expiration_policy_enabled_with_keep_n_set_to_50
projects_with_expiration_policy_enabled_with_older_than_unset
projects_with_expiration_policy_enabled_with_older_than_set_to_7d
projects_with_expiration_policy_enabled_with_older_than_set_to_14d
projects_with_expiration_policy_enabled_with_older_than_set_to_30d
projects_with_expiration_policy_enabled_with_older_than_set_to_90d
projects_with_expiration_policy_enabled_with_cadence_set_to_1d
projects_with_expiration_policy_enabled_with_cadence_set_to_7d
projects_with_expiration_policy_enabled_with_cadence_set_to_14d
projects_with_expiration_policy_enabled_with_cadence_set_to_1month
projects_with_expiration_policy_enabled_with_cadence_set_to_3month
pages_domains
pages_domains
protected_branches
protected_branches
releases
releases
...
@@ -137,25 +155,6 @@ module UsageDataHelpers
...
@@ -137,25 +155,6 @@ module UsageDataHelpers
prometheus_metrics_enabled
prometheus_metrics_enabled
web_ide_clientside_preview_enabled
web_ide_clientside_preview_enabled
ingress_modsecurity_enabled
ingress_modsecurity_enabled
projects_with_expiration_policy_disabled
projects_with_expiration_policy_enabled
projects_with_expiration_policy_enabled_with_keep_n_unset
projects_with_expiration_policy_enabled_with_older_than_unset
projects_with_expiration_policy_enabled_with_keep_n_set_to_1
projects_with_expiration_policy_enabled_with_keep_n_set_to_5
projects_with_expiration_policy_enabled_with_keep_n_set_to_10
projects_with_expiration_policy_enabled_with_keep_n_set_to_25
projects_with_expiration_policy_enabled_with_keep_n_set_to_50
projects_with_expiration_policy_enabled_with_keep_n_set_to_100
projects_with_expiration_policy_enabled_with_cadence_set_to_1d
projects_with_expiration_policy_enabled_with_cadence_set_to_7d
projects_with_expiration_policy_enabled_with_cadence_set_to_14d
projects_with_expiration_policy_enabled_with_cadence_set_to_1month
projects_with_expiration_policy_enabled_with_cadence_set_to_3month
projects_with_expiration_policy_enabled_with_older_than_set_to_7d
projects_with_expiration_policy_enabled_with_older_than_set_to_14d
projects_with_expiration_policy_enabled_with_older_than_set_to_30d
projects_with_expiration_policy_enabled_with_older_than_set_to_90d
object_store
object_store
)
.
freeze
)
.
freeze
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录