Skip to content

Commit 61f7ea1

Browse files
authored
chore: log event changes for cas backend validation (#2587)
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
1 parent b13f004 commit 61f7ea1

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

app/controlplane/cmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func main() {
178178
// Start around 24h mark to avoid overlap with default checker
179179
go app.casBackendChecker.Start(ctx, &biz.CASBackendCheckerOpts{
180180
CheckInterval: 24 * time.Hour,
181-
InitialDelay: 24 * time.Hour,
181+
InitialDelay: (24 * time.Hour) + jitter,
182182
OnlyDefaults: toPtr(false),
183183
})
184184
}

app/controlplane/pkg/biz/casbackend.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,19 +616,29 @@ func (uc *CASBackendUseCase) PerformValidation(ctx context.Context, id string) e
616616
}
617617

618618
defer func() {
619+
// reload the backend in case some other instance updated it while we were validating
620+
backend, err := uc.repo.FindByID(ctx, backendUUID)
621+
if err != nil {
622+
uc.logger.Errorw("msg", "finding backend after validation", "ID", id, "error", err)
623+
return
624+
} else if backend == nil {
625+
uc.logger.Errorw("msg", "backend not found after validation", "ID", id)
626+
return
627+
}
628+
629+
// Store previous status for audit logging
630+
previousStatus := backend.ValidationStatus
631+
619632
// Update the validation status and error
620633
uc.logger.Infow("msg", "updating validation status", "ID", id, "status", validationStatus, "error", validationError)
621634
if err := uc.repo.UpdateValidationStatus(ctx, backendUUID, validationStatus, validationError); err != nil {
622635
uc.logger.Errorw("msg", "updating validation status", "ID", id, "error", err)
623636
return
624637
}
625638

626-
// Store previous status for audit logging
627-
previousStatus := backend.ValidationStatus
628-
629639
// Log status change as an audit event if status has changed and auditor is available
630640
if uc.auditorUC != nil && previousStatus != validationStatus {
631-
uc.logger.Debugw("msg", "status changed, dispatching audit event",
641+
uc.logger.Infow("msg", "status changed, dispatching audit event",
632642
"backend", backend.ID,
633643
"previousStatus", previousStatus,
634644
"newStatus", validationStatus)

0 commit comments

Comments
 (0)