cmd/stunstamp: fix remote write retry (#12348)

Evaluation of remote write errors was using errors.Is() where it should
have been using errors.As().

Updates tailscale/corp#20344

Signed-off-by: Jordan Whited <jordan@tailscale.com>
pull/12363/head
Jordan Whited 6 months ago committed by GitHub
parent 6d3c10579e
commit cf1e6c6e55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -509,20 +509,24 @@ func (r *remoteWriteClient) write(ctx context.Context, ts []prompb.TimeSeries) e
func remoteWriteTimeSeries(client *remoteWriteClient, tsCh chan []prompb.TimeSeries) { func remoteWriteTimeSeries(client *remoteWriteClient, tsCh chan []prompb.TimeSeries) {
bo := backoff.NewBackoff("remote-write", log.Printf, time.Second*30) bo := backoff.NewBackoff("remote-write", log.Printf, time.Second*30)
// writeErr may contribute to bo's backoff schedule across tsCh read ops,
// i.e. if an unrecoverable error occurs for client.write(ctx, A), that
// should be accounted against bo prior to attempting to
// client.write(ctx, B).
var writeErr error
for ts := range tsCh { for ts := range tsCh {
for { for {
bo.BackOff(context.Background(), writeErr)
reqCtx, cancel := context.WithTimeout(context.Background(), time.Second*30) reqCtx, cancel := context.WithTimeout(context.Background(), time.Second*30)
err := client.write(reqCtx, ts) writeErr = client.write(reqCtx, ts)
cancel() cancel()
// we could parse the Retry-After header, but use a simple exp
// backoff for now
bo.BackOff(context.Background(), err)
if err == nil {
break
}
var re recoverableErr var re recoverableErr
if !errors.Is(err, &re) { recoverable := errors.As(writeErr, &re)
log.Printf("unrecoverable remote write error: %v", err) if writeErr != nil {
log.Printf("remote write error(recoverable=%v): %v", recoverable, writeErr)
}
if !recoverable {
// a nil err is not recoverable
break break
} }
} }

Loading…
Cancel
Save