feat(observability): Actuator 健康端点 + 滚动日志 + base 日志降噪
总览 §10.2 可观测性:
- platform-app 加 spring-boot-starter-actuator,management 只暴露 health(开 liveness/readiness 探针,show-details when-authorized 不泄露 db 等组件细节);不上 Prometheus 全家桶
- SecurityConfig.PUBLIC_PATHS 加 /actuator/health(/**),prod 链探针免认证可达
- 新增 logback-spring.xml(控制台 + 50MB×14 天滚动文件,文件 appender 仅 dev/local/prod 启用,不污染单测)
- base application.yml 日志 com.dsasp/jdbc.core DEBUG→INFO(prod 继承 INFO,dev 仍 DEBUG);.gitignore 忽略 logs/
验证:真启动 dev profile(1.7s)curl /actuator/health=200 {UP,groups:[liveness,readiness]} + readiness/liveness 均 200 UP;SecurityProfileTest 3/3 + ArchitectureRulesTest 6/6 无回归。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -8,6 +8,8 @@ parity-reports/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
# C3 卫生:可再生噪声(2026-06-13)
|
# C3 卫生:可再生噪声(2026-06-13)
|
||||||
|
# 运行时日志(logback 滚动文件;§10.2 可观测性)
|
||||||
|
logs/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.pyc
|
*.pyc
|
||||||
/data/
|
/data/
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ EIP3(Vaadin / 老引擎)→ EIP4(amis 前端 + 保真层 + 转换器)迁
|
|||||||
**【生产交付能力 — 意图与实现最大成体系缺口,对应 A10】**
|
**【生产交付能力 — 意图与实现最大成体系缺口,对应 A10】**
|
||||||
- **Flyway 平台表迁移未实现 · medium · L**:`架构设计.md:36` 承诺 Flyway,全仓零命中;SYS_* 建表散落 bootstrap/`*_upsert.sql`/CLI 内嵌(`bootstrap-ai-agent.sql` 两份易漂移)。→ 引入 Flyway 收敛为 `V{n}__*.sql` 单一真相。
|
- **Flyway 平台表迁移未实现 · medium · L**:`架构设计.md:36` 承诺 Flyway,全仓零命中;SYS_* 建表散落 bootstrap/`*_upsert.sql`/CLI 内嵌(`bootstrap-ai-agent.sql` 两份易漂移)。→ 引入 Flyway 收敛为 `V{n}__*.sql` 单一真相。
|
||||||
- **4 进程交付无 compose/Dockerfile/Nginx 配置 · medium · L**:`find docker-compose*` 零命中,切流/回滚仅停留文档。→ 补 `deploy/`(compose 四服务 + 健康检查 + `nginx.conf` 切流 upstream + `.env.example`)。
|
- **4 进程交付无 compose/Dockerfile/Nginx 配置 · medium · L**:`find docker-compose*` 零命中,切流/回滚仅停留文档。→ 补 `deploy/`(compose 四服务 + 健康检查 + `nginx.conf` 切流 upstream + `.env.example`)。
|
||||||
- **可观测性近零 · medium · M**:pom 无 actuator/micrometer,无健康端点,无 `logback-spring.xml`。→ 加 actuator `/health`(liveness/readiness)+ prod JSON 结构化日志。
|
- **✅【已完成 2026-06-24】可观测性近零**:原状=无 actuator/无健康端点/无 logback 配置/base 日志 DEBUG(prod 继承会刷屏)。**已做**:① platform-app 加 `spring-boot-starter-actuator`,`management` 只暴露 `health`(`probes.enabled` 开 liveness/readiness,`show-details/components: when-authorized` 匿名不泄露 db 等组件细节)——不上 Prometheus 全家桶,守中间件最小化;② `SecurityConfig.PUBLIC_PATHS` 加 `/actuator/health(/**)`,prod 链探针免认证可达;③ 新增 `logback-spring.xml`(控制台 + 50MB×14 天滚动文件,文件 appender 仅 dev/local/prod 启用、不污染单测);④ base `application.yml` 的 `com.dsasp`/`jdbc.core` 日志 DEBUG→INFO(prod 继承 INFO,dev 仍 DEBUG)。**验证**:真启动 dev profile(1.7s 起)curl `/actuator/health`=`200 {"status":"UP","groups":["liveness","readiness"]}`、`/health/readiness`=200 UP、`/health/liveness`=200 UP;SecurityProfileTest 3/3 + ArchitectureRulesTest 6/6 无回归。**残留**:prod JSON 结构化日志需 Spring Boot 3.4 内建或 logstash-encoder 依赖,留作后续(避免现在加依赖)。
|
||||||
|
|
||||||
**【验证体系】**
|
**【验证体系】**
|
||||||
- **逐行对拍框架已冻结 · high · M**:`parity-reports/` 全是 `20260611` 时间戳,对拍 main 末次提交 0611,11 天引擎/转换器改动从未重拍;`--discover`/`--realprivilege` 从不在 CI 跑。→ 接夜间 job + 基线锁定(本次 vs 上次 diff,非 0 即阻断)。
|
- **逐行对拍框架已冻结 · high · M**:`parity-reports/` 全是 `20260611` 时间戳,对拍 main 末次提交 0611,11 天引擎/转换器改动从未重拍;`--discover`/`--realprivilege` 从不在 CI 跑。→ 接夜间 job + 基线锁定(本次 vs 上次 diff,非 0 即阻断)。
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
<dependency><groupId>com.eip4</groupId><artifactId>platform-converter</artifactId></dependency>
|
<dependency><groupId>com.eip4</groupId><artifactId>platform-converter</artifactId></dependency>
|
||||||
<dependency><groupId>com.eip4</groupId><artifactId>platform-ai</artifactId></dependency>
|
<dependency><groupId>com.eip4</groupId><artifactId>platform-ai</artifactId></dependency>
|
||||||
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>
|
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>
|
||||||
|
<!-- 可观测性(总览 §10.2):仅 /actuator/health(含 liveness/readiness 探针),不上 Prometheus 全家桶 -->
|
||||||
|
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency>
|
||||||
<dependency><groupId>org.postgresql</groupId><artifactId>postgresql</artifactId><scope>runtime</scope></dependency>
|
<dependency><groupId>org.postgresql</groupId><artifactId>postgresql</artifactId><scope>runtime</scope></dependency>
|
||||||
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
|
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
|
||||||
<!-- 模块边界纪律:ArchUnit 规则跑在能看到全部类的 app 模块测试里 -->
|
<!-- 模块边界纪律:ArchUnit 规则跑在能看到全部类的 app 模块测试里 -->
|
||||||
|
|||||||
@@ -40,7 +40,22 @@ eip4:
|
|||||||
file:
|
file:
|
||||||
root: ${EIP4_FILE_ROOT:./data/files}
|
root: ${EIP4_FILE_ROOT:./data/files}
|
||||||
|
|
||||||
|
# 可观测性(总览 §10.2):只暴露 health(含 liveness/readiness 探针),不开 env/beans 等敏感端点。
|
||||||
|
# 健康详情仅对已认证者可见(匿名探针只见 UP/DOWN,不泄露 db 等组件细节)。
|
||||||
|
management:
|
||||||
|
endpoints:
|
||||||
|
web:
|
||||||
|
exposure:
|
||||||
|
include: health
|
||||||
|
endpoint:
|
||||||
|
health:
|
||||||
|
probes:
|
||||||
|
enabled: true
|
||||||
|
show-details: when-authorized
|
||||||
|
show-components: when-authorized
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.dsasp: DEBUG
|
# base 默认 INFO(prod 无独立 profile 时继承此处,避免 DEBUG 刷屏);dev profile 覆盖为 DEBUG 调试
|
||||||
org.springframework.jdbc.core: DEBUG
|
com.dsasp: INFO
|
||||||
|
org.springframework.jdbc.core: INFO
|
||||||
|
|||||||
49
platform-app/src/main/resources/logback-spring.xml
Normal file
49
platform-app/src/main/resources/logback-spring.xml
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
日志配置(总览 §10.2 可观测性)。
|
||||||
|
- 控制台:沿用 Spring Boot 默认 pattern。
|
||||||
|
- 滚动文件:50MB/份、保留 14 天、总量封顶 2GB —— 现状只靠 nohup 重定向,无滚动易撑爆磁盘。
|
||||||
|
文件落盘仅在真实运行 profile(dev/local/prod)启用;默认/test profile 只走控制台,避免单测产生 logs/。
|
||||||
|
日志级别由 application*.yml 的 logging.level 控制(base=INFO,dev=DEBUG)。
|
||||||
|
-->
|
||||||
|
<configuration>
|
||||||
|
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
||||||
|
|
||||||
|
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-./logs}/eip4-platform.log}"/>
|
||||||
|
|
||||||
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||||
|
<charset>UTF-8</charset>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${LOG_FILE}</file>
|
||||||
|
<encoder>
|
||||||
|
<pattern>${FILE_LOG_PATTERN}</pattern>
|
||||||
|
<charset>UTF-8</charset>
|
||||||
|
</encoder>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||||
|
<fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
|
||||||
|
<maxFileSize>50MB</maxFileSize>
|
||||||
|
<maxHistory>14</maxHistory>
|
||||||
|
<totalSizeCap>2GB</totalSizeCap>
|
||||||
|
</rollingPolicy>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 真实运行 profile:控制台 + 滚动文件 -->
|
||||||
|
<springProfile name="dev,local,prod">
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
<appender-ref ref="FILE"/>
|
||||||
|
</root>
|
||||||
|
</springProfile>
|
||||||
|
|
||||||
|
<!-- 默认/test profile:仅控制台(不产 logs/) -->
|
||||||
|
<springProfile name="!dev & !local & !prod">
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
</root>
|
||||||
|
</springProfile>
|
||||||
|
</configuration>
|
||||||
@@ -30,11 +30,12 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class SecurityConfig {
|
public class SecurityConfig {
|
||||||
|
|
||||||
/** 始终放行的路径:登录端点 + API 文档(认证前置依赖,不得拦)。 */
|
/** 始终放行的路径:登录端点 + API 文档(认证前置依赖) + 健康探针(LB/k8s 探活,prod 亦免认证)。 */
|
||||||
static final String[] PUBLIC_PATHS = {
|
static final String[] PUBLIC_PATHS = {
|
||||||
"/api/auth/**",
|
"/api/auth/**",
|
||||||
"/swagger-ui/**", "/swagger-ui.html",
|
"/swagger-ui/**", "/swagger-ui.html",
|
||||||
"/v3/api-docs/**", "/v3/api-docs.yaml",
|
"/v3/api-docs/**", "/v3/api-docs.yaml",
|
||||||
|
"/actuator/health", "/actuator/health/**",
|
||||||
};
|
};
|
||||||
|
|
||||||
private final JwtService jwtService;
|
private final JwtService jwtService;
|
||||||
|
|||||||
Reference in New Issue
Block a user