fix(postgres): write no audit row when retention prunes nothing (#1810)
This commit is contained in:
1 file changed
+9
-7
@@ -33,7 +33,7 @@ type auditPruneRecord struct {
|
|||||||
|
|
||||||
// PruneAuditEvents deletes events of the given kinds older than cutoff in
|
// PruneAuditEvents deletes events of the given kinds older than cutoff in
|
||||||
// bounded batches and appends one sys_audit row recording the cutoff and the
|
// bounded batches and appends one sys_audit row recording the cutoff and the
|
||||||
// total removed, even when that total is zero. The whole sweep is one
|
// total removed, only when it is non-zero. The whole sweep is one
|
||||||
// transaction under the audit prune lock, so the lock covers every batch and a
|
// transaction under the audit prune lock, so the lock covers every batch and a
|
||||||
// concurrent sweep gets ErrAuditPruneBusy without touching a row. The kind
|
// concurrent sweep gets ErrAuditPruneBusy without touching a row. The kind
|
||||||
// list is the caller's allowlist: this method deletes nothing else.
|
// list is the caller's allowlist: this method deletes nothing else.
|
||||||
@@ -68,12 +68,14 @@ func (s *Store) PruneAuditEvents(ctx context.Context, kinds []string, cutoff tim
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// The sweep is not an RPC, so it attributes its own row: the State Store
|
if total > 0 {
|
||||||
// pruned the events and the retention setting decided how many.
|
// The sweep is not an RPC, so it attributes its own row: the State
|
||||||
ctx = access.WithActor(access.WithSource(ctx, auditRetentionSource), auditRetentionActor)
|
// Store pruned the events and the retention setting decided how many.
|
||||||
if err := insertAuditValues(ctx, q, "audit_retention", "runtime_events", "pruned", nil,
|
ctx = access.WithActor(access.WithSource(ctx, auditRetentionSource), auditRetentionActor)
|
||||||
auditPruneRecord{Cutoff: cutoff.UTC(), Rows: total}, 0, storecontract.DefaultOrgID); err != nil {
|
if err := insertAuditValues(ctx, q, "audit_retention", "runtime_events", "pruned", nil,
|
||||||
return 0, err
|
auditPruneRecord{Cutoff: cutoff.UTC(), Rows: total}, 0, storecontract.DefaultOrgID); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err := tx.Commit(ctx); err != nil {
|
if err := tx.Commit(ctx); err != nil {
|
||||||
return 0, fmt.Errorf("prune audit events: %w", err)
|
return 0, fmt.Errorf("prune audit events: %w", err)
|
||||||
|
|||||||
Reference in new issue
Block a user