Skip to content

feat(config): 新增标签表达式灰度规则支持#14685

Open
1lck wants to merge 1 commit intoalibaba:developfrom
1lck:feat/Beta-Config-pro
Open

feat(config): 新增标签表达式灰度规则支持#14685
1lck wants to merge 1 commit intoalibaba:developfrom
1lck:feat/Beta-Config-pro

Conversation

@1lck
Copy link
Copy Markdown
Contributor

@1lck 1lck commented Mar 22, 2026

Please do not create a Pull Request without creating an issue first.

What is the purpose of the change

当前 Nacos 配置中心的灰度能力主要基于 beta/tag 等内置规则,规则类型相对固定,在更复杂的灰度分流场景下扩展性有限。

本次修改在兼容既有 beta/tag 灰度能力的基础上,补充了基于 labels 表达式的通用灰度规则能力,使配置发布与查询链路可以根据请求标签信息匹配灰度配置,支持更灵活的灰度场景。

当前暂未找到完全对应的现有 issue,因此先提交 PR 说明实现方案与验证结果;如有需要,我可以进一步补充对应 issue 并关联。

Brief changelog

  • 新增 LabelExpressionGrayRule 并通过 SPI 注册规则实现
  • 支持标签表达式解析,当前支持 &&||
  • ConfigForm 中新增 labelsgrayType 字段
  • 复用 ConnLabelsUtils 将原始标签字符串解析为应用标签映射
  • ConfigOperationService 中补充通用灰度发布逻辑
  • 在配置查询链路中透传 labels,参与灰度规则匹配
  • 补充规则解析、发布校验、查询链路构建等相关单元测试
  • 修复标签表达式规则初始化过程中解析结果被覆盖的问题,保证运行时能够正确命中灰度规则

Verifying this change

单元测试:

  • ./mvnw -pl config -Dtest=LabelExpressionGrayRuleTest,ConfigOpenApiControllerTest,ConfigOperationServiceTest test

本地联调验证:

  1. 发布正式配置
  2. 发布灰度配置,并指定:
    • grayType=label_expr
    • grayRuleExp=region == 'hz' && env == 'prod'
  3. 不携带 labels 查询配置,确认返回正式配置
  4. 携带 labels=region=hz,env=prod 查询配置,确认返回灰度配置

联调结果:

  • 不带 labels 时返回 mode: formal
  • 带匹配标签时返回 mode: gray

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check spotbugs:check -DskipTests to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

- 在 META-INF/services 中注册新的标签表达式灰度规则实现类
- 为 ConfigForm 新增 labels 和 grayType 字段及其 getter/setter 方法
- 集成 ConnLabelsUtils 工具类用于解析原始标签字符串为应用标签映射
- 实现通用灰度发布逻辑,支持基于标签表达式的灰度配置发布
- 添加标签表达式解析功能,支持 AND 和 OR 逻辑操作符
- 实现标签匹配验证机制,确保灰度规则正确生效
- 完善单元测试覆盖新功能的各种使用场景
@github-actions
Copy link
Copy Markdown

Thanks for your this PR. 🙏
Please check again for your PR changes whether contains any usage/api/configuration change such as Add new API , Add new configuration, Change default value of configuration.
If so, please add or update documents(markdown type) in docs/next/ for repository nacos-group/nacos-group.github.io


感谢您提交的PR。 🙏
请再次查看您的PR内容,确认是否包含任何使用方式/API/配置参数的变更,如:新增API新增配置参数修改默认配置等操作。
如果是,请确保在提交之前,在仓库nacos-group/nacos-group.github.io中的docs/next/目录下添加或更新文档(markdown格式)。

@1lck
Copy link
Copy Markdown
Contributor Author

1lck commented Mar 22, 2026

@KomachiSion 哈喽 有空麻烦看看这个pr呗 谢谢啦😊

@KomachiSion
Copy link
Copy Markdown
Collaborator

Why add this feature?

@1lck
Copy link
Copy Markdown
Contributor Author

1lck commented Mar 23, 2026

因为现有灰度能力已经有规则基础设施,但规则类型主要还是 beta/tag 这类固定模式,扩展性有限。我这次主要是想在兼容原有能力的前提下,补齐基于 labels 的通用匹配能力,支持更灵活的灰度场景,同时也让后续新增灰度规则类型更容易复用现有框架。

@KomachiSion
Copy link
Copy Markdown
Collaborator

@1lck 先提一个issue讨论一下吧

@1lck
Copy link
Copy Markdown
Contributor Author

1lck commented Mar 23, 2026

#14695

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants