From 930ccafbcccd26b2c1862d16e2ad5ec130b6eb45 Mon Sep 17 00:00:00 2001 From: secwall Date: Fri, 29 May 2026 11:54:56 +0200 Subject: [PATCH] Finish switchover on timeout --- internal/app/manager.go | 2 +- internal/app/switchover.go | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/internal/app/manager.go b/internal/app/manager.go index f52b7c5..96851d9 100644 --- a/internal/app/manager.go +++ b/internal/app/manager.go @@ -73,7 +73,7 @@ func (app *App) stateManager() appState { if err := app.dcs.Get(pathCurrentSwitch, &switchover); err == nil { if !switchover.InitiatedAt.IsZero() && time.Since(switchover.InitiatedAt) > app.config.Valkey.SwitchoverTimeout { app.logger.Error().Msgf("Switchover: %s => %s timed out after %s", switchover.From, switchover.To, time.Since(switchover.InitiatedAt)) - err = app.failSwitchover(&switchover, fmt.Errorf("switchover timed out after %s", time.Since(switchover.InitiatedAt))) + err = app.finishSwitchover(&switchover, fmt.Errorf("switchover timed out after %s", time.Since(switchover.InitiatedAt))) if err != nil { app.logger.Error().Err(err).Msg("Failed to report switchover timeout") } diff --git a/internal/app/switchover.go b/internal/app/switchover.go index 6740644..62f067f 100644 --- a/internal/app/switchover.go +++ b/internal/app/switchover.go @@ -71,14 +71,6 @@ func (app *App) failSwitchover(switchover *Switchover, err error) error { switchover.Result.Error = err.Error() switchover.Result.FinishedAt = time.Now() - // Report failure timing - dur := time.Since(switchover.StartedAt) - eventName := "switchover_failed" - if switchover.Cause == CauseAuto { - eventName = "failover_failed" - } - app.timings.reportTiming(eventName, dur) - return app.dcs.Set(pathCurrentSwitch, switchover) } @@ -106,17 +98,23 @@ func (app *App) finishSwitchover(switchover *Switchover, switchErr error) error switchover.Result.Ok = result switchover.Result.FinishedAt = time.Now() + var eventName string + if switchErr != nil { + eventName = "switchover_failed" + if switchover.Cause == CauseAuto { + eventName = "failover_failed" + } switchover.Result.Error = switchErr.Error() } else { // Report success timing - dur := time.Since(switchover.StartedAt) - eventName := "switchover_complete" + eventName = "switchover_complete" if switchover.Cause == CauseAuto { eventName = "failover_complete" } - app.timings.reportTiming(eventName, dur) } + dur := time.Since(switchover.StartedAt) + app.timings.reportTiming(eventName, dur) err := app.dcs.Delete(pathCurrentSwitch) if err != nil {