Repository navigation
fix 不符合actuator命名规范 报错问题 - #827
CrazyLionCat wants to merge 1 commit into
Conversation
|
感谢贡献!本仓库的日常开发分支是 Thanks for contributing! Please retarget this PR from |
|
感谢你的第一个 PR!/ Thanks for your first pull request! |
huayanYu
left a comment
There was a problem hiding this comment.
感谢贡献!问题定位准确——确实是 @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.
同一份源码里:
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): ...)。
上述几点调整后我再来看一版。
变更类型 / What kind of change does this PR introduce?
描述 / The description of the PR
说明为什么需要这个改动,而不只是改了什么;关联对应的 issue(
Fixes #123)。影响面 / Impact on the core contracts
本框架的核心契约很窄,改动通常会波及其中之一,请勾选并说明:
@DS解析 /DynamicDataSourceContextHolder的切换与栈语义(含多层嵌套、同类内部调用)@DSTransactional、savepoint、XA/Atomikos、Seata)GroupDataSource、strategy)ENC(...)加解密 / 配置属性(新增或改名配置项)新增/改名配置项时,请同步文档 https://doc.xiuceyun.cn 与
DynamicDataSourceProperties的 Javadoc。自检清单 / Checklist
./gradlew clean test通过(Gradle 客户端要求 17+;Boot 2 线模块由 JDK 8 toolchain 编译测试)./gradlew buildCopyright © 2018 organization baomidou)fix:/feat:/build:/docs:…),一个 commit 做一件事其他信息 / Other information