大型仓库 PR 高效合并解决方案 #13
Locked
Rustin170506
started this conversation in
Ideas
Replies: 0 comments 7 replies
-
@tidb-community-bots/bots-maintainers @tidb-community-bots/bots-reviewers PTAL~ |
Beta Was this translation helpful? Give feedback.
0 replies
-
来自 @zhouqiang-cl 的问题:
|
Beta Was this translation helpful? Give feedback.
1 reply
-
方案三 LGTM |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
大型仓库 PR 高效合并解决方案
Date: 2020-12-09
Authors: Rustin Liu
Status: Draft
背景回顾
在 TiDB 社区中,存在多个大型仓库(tikv/tidb),这些仓库的 CI 每次运行都会消耗大量的资源。为了保证代码的可靠性,我们在 GitHub 上打开了 Require branches to be up to date before merging 分支保护选项,这保证我们每次合并之前都要确保将上游的 Base 合并到 PR 中才能合并。但是也带来浪费 CI 资源测试的问题,例如有 n 个同时可以 merge 的 PR,要跑 O(n^2) 次测试,大大浪费了 CI 资源。
在 cherry-bot 我们采取排队合并的方式来解决资源浪费的问题,但是这样导致的问题是我们的合并变为一次性命令,需要人为不停的去干预,并且因为 CI 不稳定的问题,导致触发大量的 /merge 命令重跑所有测试,浪费 CI 资源。
综上,我们决定在新 bot 中探索新的解决方案。
Goals
更高的合并效率
更少的人为干预
良好的 dashboard
高可用性
说明
备选方案1:迁移 CI 至 Prow
简介
Prow 是一个基于 Kubernetes 的 CI/CD 平台。CI 任务可以被各种类型的事件触发并且反馈状态给不同的服务。除了执行任务,Prow 通过 /foo 风格命令以及自动PR合并的策略提供 GitHub 自动化。
在 Prow 中,因为 CI 系统是自己实现的,所以可以获取当前任务是否使用最新的 Base,在合并之前可以重新测试当前 PR 的所有任务。
需要注意的是,Prow 不会每个都单独测试,而是同一仓库的同一分支可以合并的 PR 进行批量重新测试和合并。
所以迁移至 Prow 能解决上述问题。无需人为干预并且具有良好的 dashboard。
成本
我们需要将大型仓库的所有 CI 任务从 Jenkins 迁移至 Prow,可能会有上百个 pipeline 的迁移
需要 Prow 的学习成本,虽然 Prow 在 k8s 社区和众多云原生社区已投入使用,但是它作为一个开源产品,文档上支持上都不如商业化的 Jenkins
不确定因素
备选方案2:配合 tide 开发一个批量测试机器人
简介
我们可以开发一个批量测试机器人:
在此示例中,第一批将如下所示:
该批处理仍将失败,因为第二个 PR 会插入对第一个 PR 删除的函数的调用。结果,它将再次被一分为二。
通过上述方案,我们将 PR 合并的效率提升为 O(E log N),其中 N 是可以合并 PR 的总数,E是失败的PR 的数量。
让该机器人汇报一个测试结果的 status,然后 tide 去检测该 status即可实现完美配合。 并且支持所有 CI,没有 CI 的特殊要求。
需要开发良好的 dashboard 和自动重试机制(因为可能会有 CI 不稳定的因素)。
成本
不确定因素
备选方案3:配合 tide 开发一个排队测试的机器人
简介
延续备选方案 2 的思路,但是将过程简化,每次将可以合并的 PR 进行排队,并且每次只在测试分支上测试一个 PR。
通过上述方案,我们将 PR 合并的效率提升为 O(N),其中 N 是可以合并 PR 的总数
让该机器人汇报一个测试结果的 status,然后 tide 去检测该 status即可实现完美配合。 并且支持所有 CI,没有 CI 的特殊要求。
需要开发良好的 dashboard 和自动重试机制(因为可能会有 CI 不稳定的因素)。
成本
不确定因素
备选方案4:配合 tide 开发一个重新测试的机器人(使用 tide 的排队并重新测试功能)
在实现备选方案3的过程中发现,我们可以利用 tide 在合并之前重新测试的功能,在 CI 任务中重新测试 PR。在 tide 重新测试时,我们可以将它排队合并的 pr 推送到测试分支,在测试分支中获取测试结果,如果全部通过则该 CI 任务通过成功合并,如果失败则 Tide 不会合并该 PR。
通过上述方案,不仅可以借助 tide 提高合并效率,又可以作为 CI 任务,为每个仓库定制化使用。
该工具将作为 prow 的 CI 任务运行,借助 tide 的 dashboard 并且支持自动重试。
成本
不确定因素
参考实现
Bors-ng
Homu
Tide
Beta Was this translation helpful? Give feedback.
All reactions