Skip to content

Commit a274979

Browse files
committed
httpmonitorscanner: improve retries
1 parent 2916d8b commit a274979

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

cmd/alertmanager/httpmonitorscanner.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ type retryScanner struct {
105105
actualScanner HttpMonitorScanner
106106
}
107107

108-
// retries once, but only if it looks retryable
108+
// retries once
109109
func newRetryScanner(actual HttpMonitorScanner) HttpMonitorScanner {
110110
return &retryScanner{actual}
111111
}
@@ -115,12 +115,17 @@ func (r *retryScanner) Scan(ctx context.Context, monitor amstate.HttpMonitor) er
115115
defer cancel()
116116

117117
if err := r.actualScanner.Scan(firstTryCtx, monitor); err != nil {
118-
if err != context.DeadlineExceeded { // non-retryable error
119-
return err
120-
}
118+
time.Sleep(2 * time.Second)
119+
120+
// it'd be hard to detect if we shouldn't retry this at all, since timeouts,
121+
// HTTP gateway errors, internal server errors etc. all can be transient
121122

122123
// now use the longer context
123-
return r.actualScanner.Scan(ctx, monitor)
124+
if err2 := r.actualScanner.Scan(ctx, monitor); err2 != nil {
125+
return fmt.Errorf("first error: %v; retry error: %v", err, err2)
126+
}
127+
128+
return nil
124129
}
125130

126131
return nil

0 commit comments

Comments
 (0)