yyqdbngt opened a new pull request, #5318:
URL: https://github.com/apache/rocketmq-dashboard/pull/5318
### Which Issue(s) This PR Fixes
- Fixes #5309
### Brief Description
The audit log is the only high-volume studio table without automatic
retention. The bounded cleanup primitive already existed but had exactly one
caller, the manual endpoint — `AuditService.cleanupLogs(int)` was reachable
only from `POST /api/audit-logs/cleanup`, so the table grew without bound on a
multi-instance deployment unless an administrator kept remembering to click
"清理". Every comparable table (expired sessions, metric snapshots, query
history, AI conversations, notification outbox) already has a `@Scheduled`
purge.
This change adds `studio.audit.retention-days` (default **0**, keep forever,
so an upgrade never starts silently deleting compliance evidence) and an hourly
`@Scheduled(fixedDelayString =
"${studio.audit.retention-cleanup-interval:PT1H}")` sweep
`purgeExpiredAuditLogs()` on `AuditService`. The sweep calls the same
`cleanupLogs` primitive, so it inherits the identical `CLEANUP_BATCH_SIZE =
500` / `CLEANUP_MAX_BATCHES = 20` bounds; a value above the manual endpoint's
365-day maximum is clamped to 365 with a warning instead of throwing every
hour; a repository failure is logged and swallowed. The manual endpoint, its
1..365 validation and the audit page are unchanged.
### How Did You Test This Change?
`AuditRetentionSweepTest` (new, mocked `AuditRepository`) drives the sweep
and asserts: nothing at all is deleted while retention is unset; retention 90
deletes with a cutoff ~90 days in the past and the 500x20 batch bounds;
retention 3650 clamps the cutoff to ~365 days; a throwing repository does not
propagate; and the sweep carries the hourly `@Scheduled` default.
```powershell
$ cd server && mvn -B -ntp test -Dtest=AuditRetentionSweepTest
[ERROR] Tests run: 5, Failures: 5, Errors: 0, Skipped: 0 <- before the fix
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0 <- after the fix
[INFO] BUILD SUCCESS
```
Raw red run (before the change):
```
[ERROR] Tests run: 5, Failures: 5, Errors: 0, Skipped: 0, Time elapsed:
2.111 s <<< FAILURE! -- in
org.apache.rocketmq.studio.ops.audit.AuditRetentionSweepTest
java.lang.AssertionError: AuditService has no studio.audit.retention-days
retention setting
java.lang.AssertionError: AuditService has no scheduled audit retention
sweep purgeExpiredAuditLogs()
[ERROR]
AuditRetentionSweepTest.sweepClampsRetentionAboveTheManualMaximum:91->configureRetention:116
AuditService has no studio.audit.retention-days retention setting
[ERROR]
AuditRetentionSweepTest.sweepDeletesRowsOlderThanTheConfiguredRetention:76->configureRetention:116
AuditService has no studio.audit.retention-days retention setting
[ERROR]
AuditRetentionSweepTest.sweepIsScheduledWithAnHourlyDefault:58->sweepMethod:129
AuditService has no scheduled audit retention sweep purgeExpiredAuditLogs()
[ERROR]
AuditRetentionSweepTest.sweepKeepsEveryRowWhileRetentionIsUnset:67->configureRetention:116
AuditService has no studio.audit.retention-days retention setting
[ERROR]
AuditRetentionSweepTest.sweepSwallowsRepositoryFailures:105->configureRetention:116
AuditService has no studio.audit.retention-days retention setting
[ERROR] Tests run: 5, Failures: 5, Errors: 0, Skipped: 0
[INFO] BUILD FAILURE
```
The same test file, resolved reflectively so it compiles against the
unmodified tree, passes after the change; the neighbouring classes stay green
and checkstyle is clean:
```powershell
$ cd server && mvn -B -ntp test
-Dtest='AuditServiceTest,AuditControllerTest,AuditRetentionSweepTest'
[INFO] You have 0 Checkstyle violations.
[INFO] Tests run: 36, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS
```
### Checklist
- [x] One coherent change; unrelated modifications are not bundled in
- [x] Commit subject follows Conventional Commits
- [x] Tests added or updated for non-trivial changes
- [ ] New UI text has both Chinese and English entries under `web/src/i18n/`
— does not apply, this change adds no UI text
- [ ] Architecture constraints stay green — no ArchUnit rule class exists in
the repository and this change adds none; `mvn test -Dtest=...` above reports 0
checkstyle violations
- [x] New source files carry the ASF license header
- [ ] Documentation touched where behaviour changed — not ticked: the new
property is documented by its `@Value("${studio.audit.retention-days:0}")`
placeholder and its javadoc; `server/src/main/resources/application.yml` is
outside the file set this change was scoped to, so no `studio.audit:` block was
added there
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]