Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/app/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
20 changes: 9 additions & 11 deletions internal/app/switchover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down
Loading