Skip to content

fix 不符合actuator命名规范 报错问题 - #827

Closed
CrazyLionCat wants to merge 1 commit into
baomidou:mainfrom
CrazyLionCat:patch-2
Closed

CrazyLionCat wants to merge 1 commit into
baomidou:mainfrom
CrazyLionCat:patch-2

Conversation

@CrazyLionCat

Copy link
Copy Markdown
Contributor

目标分支 / Target branch:请选 dev(main 只接收来自 dev 的发版合并,误选会被自动提醒)。
Please choose dev as the base branch — main only receives release merges from dev.

变更类型 / What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style (formatting, no behaviour change)
  • Refactor
  • Build / CI
  • Doc
  • Other, please describe:

描述 / The description of the PR

说明为什么需要这个改动,而不只是改了什么;关联对应的 issue(Fixes #123)。

影响面 / Impact on the core contracts

本框架的核心契约很窄,改动通常会波及其中之一,请勾选并说明:

  • @DS 解析 / DynamicDataSourceContextHolder 的切换与栈语义(含多层嵌套、同类内部调用)
  • 数据源创建与连接池参数(creator、Druid/HikariCP/beecp/c3p0/dbcp2/UCP)
  • 事务语义(@DSTransactional、savepoint、XA/Atomikos、Seata)
  • 分组与负载均衡(GroupDataSource、strategy)
  • ENC(...) 加解密 / 配置属性(新增或改名配置项)
  • 构建产物(模块划分、POM 依赖范围 api/compileOnly、JDK 基线)
  • 以上均不涉及

新增/改名配置项时,请同步文档 https://doc.xiuceyun.cn 与 DynamicDataSourceProperties 的 Javadoc。

自检清单 / Checklist

  • 本地在 JDK 17+ 下 ./gradlew clean test 通过(Gradle 客户端要求 17+;Boot 2 线模块由 JDK 8 toolchain 编译测试)
  • 涉及 Boot 3/4 特有 API 时,对应 starter 模块也构建通过:./gradlew build
  • 为行为变更补充/调整了单元测试
  • 新文件带有 license header(Copyright © 2018 organization baomidou)
  • 没有引入新的三方依赖;若必须引入,已在 PR 描述中说明理由与替代方案对比
  • 考虑了 GraalVM Native Image 影响(反射/代理注册),必要时说明为何 nativeTest 可能失败
  • commit message 采用 conventional 前缀(fix: / feat: / build: / docs: …),一个 commit 做一件事

其他信息 / Other information

@github-actions

Copy link
Copy Markdown

感谢贡献!本仓库的日常开发分支是 dev:请把本 PR 的目标分支从 main 改为 dev(标题右侧 Edit → base 分支)。改好后请忽略本条提醒。

Thanks for contributing! Please retarget this PR from main to dev — main only receives release merges from dev. You can change the base branch via Edit next to the title.

@github-actions

Copy link
Copy Markdown

感谢你的第一个 PR!/ Thanks for your first pull request!
提交前请阅读 CONTRIBUTING.md;涉及 @ds 解析、数据源切换栈语义、事务模式的改动,
需同时保持 v1/v3/v4 三套测试有效。

@github-actions github-actions Bot added the starters Spring Boot starter modules label Oct 27, 2026

@huayanYu huayanYu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢贡献!问题定位准确——确实是 @Endpoint(id = ...) 里的横线触发了 Spring Boot 的告警。但这个 PR 目前这样合不进去,有三点需要调整。

1. 规范依据:横线才是"不合规"的那一个

Spring Boot 对 endpoint id 的规范写在 EndpointId 的类注释里:

An identifier for an actuator endpoint. Endpoint IDs may contain only letters and numbers. They must begin with a lower-case letter. Case and syntax characters are ignored when comparing endpoint IDs.

https://github.com/spring-projects/spring-boot/blob/main/module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/EndpointId.java

同一份源码里:

  • VALID_PATTERN = [a-zA-Z0-9.-]+ —— 横线本身合法;
  • WARNING_PATTERN = [.-]+ —— 横线/点号会打 WARN:Endpoint ID 'xxx' contains invalid characters, please migrate to a valid format.;
  • management.endpoints.migrate-legacy-ids=true 时 "one-two-three" → "onetwothree",官方认定的 "valid format" 就是把分隔符去掉。

官方测试用例名也是同样的态度:EndpointIdTests#ofWhenContainsDashIsValid(合法)+ #ofWhenContainsDeprecatedCharsLogsWarning(要告警)。

所以:去掉横线这件事本身是对的,但改成驼峰 dynamicDatasource 还不是规范形态。Spring Boot 自己的端点全是小写连写(threaddump、httptrace、configprops、scheduledtasks、loggers、caches),Spring Cloud 同样是 serviceregistry、busrefresh、busshutdown,dromara 的 dynamictp、liteflow 也是全小写;驼峰只见于 Apereo CAS 的 auditLog、casModules 这类少数派。

结合上面的 javadoc 与生态主流,规范形态应是 dynamictatasource(纯字母数字、首字母小写)。

2. 这是对外 URL 的破坏性变更,不适合在补丁版本里做

DynamicDataSourceEndpoint 已随 v4.6.0 发布(commit 287c8ee),文档站 current 与 version-4.5 / version-4.6(含 i18n/en)都写着 GET /actuator/dynamic-datasource(advanced/observability.md、guide/configuration.md、guide/version-history.md)。

而 URL 直接由 id 的原始字符串生成(PathMapper.getRootPath 兜底返回 endpointId.toString()),所以改 id 就是改 URL,已经接入的用户会直接 404。

两个容易踩的点,顺便提醒:

  • id 的比较是宽松的(EndpointId.equals 只比较小写字母数字,忽略 - / .),所以 management.endpoints.web.exposure.include=dynamic-datasource、management.endpoint.dynamic-datasource.enabled 这类配置不会因此失效——这正是本 PR CI 全绿的原因;但反过来也说明现有测试覆盖不到这个改动:AbstractDynamicDataSourceEndpointTest 只注入 bean 调 summary(),完全不碰 URL。请补一个 URL 级断言(MockMvc 访问端点路径)。
  • 若改 id 后老用户想保留旧路径,可用官方机制:management.endpoints.web.path-mapping.dynamictatasource=dynamic-datasource(属性键会被 EndpointId.fromPropertyValue 去掉横线,写 dynamic-datasource 也能命中)。

因此建议:把规范化放到下一个大版本(4.7.0)一并做——改 id、同步文档站 current 与 version-history.md 的迁移说明、补 URL 级测试。若本 PR 目的只是消掉启动时的 WARN,可以先不动 id(保持 v4.6 行为不变),该 WARN 由用户用 logging.level.org.springframework.boot.actuate.endpoint.EndpointId=ERROR 静音即可。

3. 流程

  • 目标分支请从 main 改为 dev(机器人已提醒;main 只接收来自 dev 的发版合并)。
  • PR 描述还是模板空状态,麻烦补上:变更类型、关联 issue,以及**"报错"的原始日志**。从代码看,带横线的 id 只会打 WARN、不会导致启动失败;如果确实有启动失败,请贴完整堆栈,可能另有原因。
  • commit message 请用 conventional 前缀(如 fix(actuator): ...)。

上述几点调整后我再来看一版。

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

Labels

starters Spring Boot starter modules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants