Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
0c615072
未验证
提交
0c615072
编辑于
5 months ago
作者:
Michael Kozono
提交者:
GitLab
5 months ago
浏览文件
操作
下载
补丁
差异文件
Validate Geo queues exist before queue draining checks
上级
37721a2f
No related branches found
分支 包含提交
No related tags found
标签 包含提交
无相关合并请求
变更
2
隐藏空白变更内容
行内
左右并排
显示
2 个更改的文件
ee/lib/gitlab/geo/geo_tasks.rb
+26
-0
26 个添加, 0 个删除
ee/lib/gitlab/geo/geo_tasks.rb
ee/spec/lib/gitlab/geo/geo_tasks_spec.rb
+68
-0
68 个添加, 0 个删除
ee/spec/lib/gitlab/geo/geo_tasks_spec.rb
有
94 个添加
和
0 个删除
ee/lib/gitlab/geo/geo_tasks.rb
+
26
−
0
浏览文件 @
0c615072
...
@@ -66,6 +66,8 @@ def enable_maintenance_mode
...
@@ -66,6 +66,8 @@ def enable_maintenance_mode
# Note that since some non-Geo cron jobs are enabled, empty queues will be a transient state.
# Note that since some non-Geo cron jobs are enabled, empty queues will be a transient state.
# It is a sufficient check when the site is in Maintenance Mode.
# It is a sufficient check when the site is in Maintenance Mode.
def
drain_non_geo_queues
def
drain_non_geo_queues
validate_geo_queues_exist!
puts
'Sidekiq Queues: Disabling all non-Geo cron jobs'
puts
'Sidekiq Queues: Disabling all non-Geo cron jobs'
disable_non_geo_cron_jobs
disable_non_geo_cron_jobs
...
@@ -106,6 +108,8 @@ def wait_until_replicated_and_verified
...
@@ -106,6 +108,8 @@ def wait_until_replicated_and_verified
#
#
# Note that we need this check because e.g. Geo update events may be enqueued in Redis.
# Note that we need this check because e.g. Geo update events may be enqueued in Redis.
def
drain_geo_secondary_queues
def
drain_geo_secondary_queues
validate_geo_queues_exist!
puts
"Sidekiq Queues: Waiting for all Geo queues to be empty"
puts
"Sidekiq Queues: Waiting for all Geo queues to be empty"
poll_selected_queues_until_empty
do
|
queue
|
poll_selected_queues_until_empty
do
|
queue
|
...
@@ -195,6 +199,28 @@ def poll_selected_queues_until_empty
...
@@ -195,6 +199,28 @@ def poll_selected_queues_until_empty
# rubocop:enable Cop/RedisQueueUsage
# rubocop:enable Cop/RedisQueueUsage
end
end
# It's possible to configure GitLab Sidekiq queues and their names. If there are no queues
# with Geo in the name, then raise, because this code assumes that it can easily know if Geo
# or non-Geo jobs are drained, based on queue name.
def
validate_geo_queues_exist!
any_geo_queues
=
false
# Watch Sidekiq Queues on all shards
# rubocop:disable Cop/RedisQueueUsage -- valid usage
Gitlab
::
Redis
::
Queues
.
instances
.
each_value
do
|
inst
|
Sidekiq
::
Client
.
via
(
inst
.
sidekiq_redis
)
do
# scope all Sidekiq operations to use shard's redis pool
# rubocop:disable Cop/SidekiqApiUsage -- valid usage
any_geo_queues
||=
Sidekiq
::
Queue
.
all
.
any?
{
|
queue
|
geo_queue?
(
queue
)
}
# rubocop:enable Cop/SidekiqApiUsage
end
break
if
any_geo_queues
end
# rubocop:enable Cop/RedisQueueUsage
raise
"No Geo queues detected. Unable to check if Geo or non-Geo jobs are drained"
unless
any_geo_queues
end
def
geo_queue?
(
queue
)
def
geo_queue?
(
queue
)
queue
.
name
.
include?
(
'geo'
)
queue
.
name
.
include?
(
'geo'
)
end
end
...
...
此差异已折叠。
点击以展开。
ee/spec/lib/gitlab/geo/geo_tasks_spec.rb
+
68
−
0
浏览文件 @
0c615072
...
@@ -124,6 +124,10 @@
...
@@ -124,6 +124,10 @@
end
end
describe
'.drain_non_geo_queues'
do
describe
'.drain_non_geo_queues'
do
before
do
allow
(
described_class
).
to
receive
(
:validate_geo_queues_exist!
)
end
it
'disables all non-Geo Sidekiq cron jobs'
do
it
'disables all non-Geo Sidekiq cron jobs'
do
cronjob1
=
instance_double
(
Sidekiq
::
Cron
::
Job
)
cronjob1
=
instance_double
(
Sidekiq
::
Cron
::
Job
)
cronjob2
=
instance_double
(
Sidekiq
::
Cron
::
Job
)
cronjob2
=
instance_double
(
Sidekiq
::
Cron
::
Job
)
...
@@ -189,6 +193,7 @@
...
@@ -189,6 +193,7 @@
describe
'.drain_geo_secondary_queues'
do
describe
'.drain_geo_secondary_queues'
do
it
'waits until all Geo queues are empty'
do
it
'waits until all Geo queues are empty'
do
allow
(
described_class
).
to
receive
(
:validate_geo_queues_exist!
)
queue1
=
instance_double
(
Sidekiq
::
Queue
,
name:
'geo_foo'
)
queue1
=
instance_double
(
Sidekiq
::
Queue
,
name:
'geo_foo'
)
queue2
=
instance_double
(
Sidekiq
::
Queue
,
name:
'bar'
)
queue2
=
instance_double
(
Sidekiq
::
Queue
,
name:
'bar'
)
queue3
=
instance_double
(
Sidekiq
::
Queue
,
name:
'geo_baz'
)
queue3
=
instance_double
(
Sidekiq
::
Queue
,
name:
'geo_baz'
)
...
@@ -206,6 +211,7 @@
...
@@ -206,6 +211,7 @@
end
end
it
'outputs what it is doing'
do
it
'outputs what it is doing'
do
allow
(
described_class
).
to
receive
(
:validate_geo_queues_exist!
)
expected_output
=
<<~
MSG
expected_output
=
<<~
MSG
Sidekiq Queues: Waiting for all Geo queues to be empty
Sidekiq Queues: Waiting for all Geo queues to be empty
Sidekiq Queues: Geo queues empty
Sidekiq Queues: Geo queues empty
...
@@ -315,4 +321,66 @@
...
@@ -315,4 +321,66 @@
end
end
end
end
end
end
describe
'.validate_geo_queues_exist!'
do
let
(
:geo_queue
)
{
instance_double
(
Sidekiq
::
Queue
,
name:
'geo:sync'
)
}
let
(
:non_geo_queue
)
{
instance_double
(
Sidekiq
::
Queue
,
name:
'default'
)
}
before
do
allow
(
Gitlab
::
Redis
::
Queues
).
to
receive
(
:instances
)
.
and_return
({
main:
Gitlab
::
Redis
::
Queues
})
allow
(
Gitlab
::
Redis
::
Queues
).
to
receive
(
:sidekiq_redis
)
allow
(
Sidekiq
::
Client
).
to
receive
(
:via
).
and_yield
end
context
'when Geo queues exist'
do
before
do
allow
(
Sidekiq
::
Queue
).
to
receive
(
:all
).
and_return
([
geo_queue
,
non_geo_queue
])
end
it
'does not raise an error'
do
expect
{
described_class
.
validate_geo_queues_exist!
}.
not_to
raise_error
end
end
context
'when no Geo queues exist'
do
before
do
allow
(
Sidekiq
::
Queue
).
to
receive
(
:all
).
and_return
([
non_geo_queue
])
end
it
'raises an error'
do
expect
{
described_class
.
validate_geo_queues_exist!
}.
to
raise_error
(
RuntimeError
,
"No Geo queues detected. Unable to check if Geo or non-Geo jobs are drained"
)
end
end
context
'when multiple Redis instances are present'
do
before
do
allow
(
Gitlab
::
Redis
::
Queues
).
to
receive
(
:instances
)
.
and_return
({
foo:
Gitlab
::
Redis
::
Queues
,
bar:
Gitlab
::
Redis
::
Queues
})
allow
(
Gitlab
::
Redis
::
Queues
).
to
receive
(
:sidekiq_redis
)
end
it
'checks all instances and stops when a Geo queue is found'
do
expect
(
Sidekiq
::
Client
).
to
receive
(
:via
).
ordered
.
and_yield
expect
(
Sidekiq
::
Queue
).
to
receive
(
:all
).
and_return
([
non_geo_queue
])
expect
(
Sidekiq
::
Client
).
to
receive
(
:via
).
ordered
.
and_yield
expect
(
Sidekiq
::
Queue
).
to
receive
(
:all
).
and_return
([
geo_queue
])
expect
{
described_class
.
validate_geo_queues_exist!
}.
not_to
raise_error
end
end
context
'when no Redis instances are present'
do
before
do
allow
(
Gitlab
::
Redis
::
Queues
).
to
receive
(
:instances
).
and_return
({})
end
it
'raises an error'
do
expect
{
described_class
.
validate_geo_queues_exist!
}.
to
raise_error
(
RuntimeError
,
"No Geo queues detected. Unable to check if Geo or non-Geo jobs are drained"
)
end
end
end
end
end
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录