Skip to content

Commit 930ccaf

Browse files
committed
Finish switchover on timeout
1 parent 2e575dc commit 930ccaf

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

internal/app/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (app *App) stateManager() appState {
7373
if err := app.dcs.Get(pathCurrentSwitch, &switchover); err == nil {
7474
if !switchover.InitiatedAt.IsZero() && time.Since(switchover.InitiatedAt) > app.config.Valkey.SwitchoverTimeout {
7575
app.logger.Error().Msgf("Switchover: %s => %s timed out after %s", switchover.From, switchover.To, time.Since(switchover.InitiatedAt))
76-
err = app.failSwitchover(&switchover, fmt.Errorf("switchover timed out after %s", time.Since(switchover.InitiatedAt)))
76+
err = app.finishSwitchover(&switchover, fmt.Errorf("switchover timed out after %s", time.Since(switchover.InitiatedAt)))
7777
if err != nil {
7878
app.logger.Error().Err(err).Msg("Failed to report switchover timeout")
7979
}

internal/app/switchover.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,6 @@ func (app *App) failSwitchover(switchover *Switchover, err error) error {
7171
switchover.Result.Error = err.Error()
7272
switchover.Result.FinishedAt = time.Now()
7373

74-
// Report failure timing
75-
dur := time.Since(switchover.StartedAt)
76-
eventName := "switchover_failed"
77-
if switchover.Cause == CauseAuto {
78-
eventName = "failover_failed"
79-
}
80-
app.timings.reportTiming(eventName, dur)
81-
8274
return app.dcs.Set(pathCurrentSwitch, switchover)
8375
}
8476

@@ -106,17 +98,23 @@ func (app *App) finishSwitchover(switchover *Switchover, switchErr error) error
10698
switchover.Result.Ok = result
10799
switchover.Result.FinishedAt = time.Now()
108100

101+
var eventName string
102+
109103
if switchErr != nil {
104+
eventName = "switchover_failed"
105+
if switchover.Cause == CauseAuto {
106+
eventName = "failover_failed"
107+
}
110108
switchover.Result.Error = switchErr.Error()
111109
} else {
112110
// Report success timing
113-
dur := time.Since(switchover.StartedAt)
114-
eventName := "switchover_complete"
111+
eventName = "switchover_complete"
115112
if switchover.Cause == CauseAuto {
116113
eventName = "failover_complete"
117114
}
118-
app.timings.reportTiming(eventName, dur)
119115
}
116+
dur := time.Since(switchover.StartedAt)
117+
app.timings.reportTiming(eventName, dur)
120118

121119
err := app.dcs.Delete(pathCurrentSwitch)
122120
if err != nil {

0 commit comments

Comments
 (0)