feat: 审计动作按落库策略分级写入,系统过程动作改写应用日志
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 12m8s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 12m8s
- 审计注册表为可由系统任务、定时任务发起的动作声明落库策略(always/on_success/outcome/log_only/none),未声明按 log_only - 人工、开放接口、个人客户、外部系统发起的动作始终写审计表 - log_only 写所在服务 app.log(logger=audit),不含快照 - 对接日志不再补写 integration.attempt_started,无上游审计时 audit_event_id 为空 - 新增 audit.persist_overrides 按动作覆盖策略 - 审计覆盖扫描要求机器动作必须声明策略 - 新增 OpenSpec 提案 refactor-audit-log-persistence 与技术方案文档 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
|
||||
auditinfra "github.com/break/junhong_cmp_fiber/internal/infrastructure/audit"
|
||||
)
|
||||
|
||||
// Entry 是一个必须经过审计分类的 HTTP、Worker 或定时任务入口。
|
||||
@@ -46,6 +48,9 @@ type Entry struct {
|
||||
|
||||
// Scan 扫描当前仓库中对外 HTTP、Asynq Worker 和定时任务注册入口。
|
||||
func Scan(root string) ([]Entry, error) {
|
||||
if missing := auditinfra.NewRegistry().MachineActionsWithoutPolicy(); len(missing) > 0 {
|
||||
return nil, fmt.Errorf("以下可由系统任务或定时任务发起的审计动作未声明落库策略:%s", strings.Join(missing, ", "))
|
||||
}
|
||||
var entries []Entry
|
||||
files := []string{
|
||||
"internal/routes", "internal/application", "internal/domain", "internal/service",
|
||||
@@ -201,7 +206,7 @@ func classifyWorker(file string, line int, taskType, handler string) Entry {
|
||||
entry := Entry{
|
||||
Key: fmt.Sprintf("worker:%s:%d:%s", file, line, taskType), Kind: "worker",
|
||||
CodeEntry: fmt.Sprintf("%s:%d %s", file, line, handler), Owner: owner,
|
||||
Summary: "处理异步任务 " + taskType, AuditEvent: "按状态变化、人工触发、连续失败或高风险异常决定",
|
||||
Summary: "处理异步任务 " + taskType, AuditEvent: "按审计注册表落库策略决定:系统任务未声明策略时只写应用日志",
|
||||
DomainLedger: ledgerDecision(owner), IntegrationLog: workerIntegrationDecision(taskType),
|
||||
Outbox: "任务来源 Outbox/业务任务事实;消费端按稳定事件或任务 ID 幂等",
|
||||
ActionCode: actionCode(owner, handler), ActionName: "处理异步任务(" + taskType + ")",
|
||||
|
||||
Reference in New Issue
Block a user