Skip to content

Commit 3f8485e

Browse files
Don't retry request on client errors
1 parent a9bbe06 commit 3f8485e

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

internal/controller/controller.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,20 @@ func (c *Controller) recordContainer(ctx context.Context, pod *corev1.Pod, conta
323323
)
324324

325325
if err := c.apiClient.PostOne(ctx, record); err != nil {
326+
// Make sure to not retry on client error messages
327+
var clientErr *deploymentrecord.ClientError
328+
if errors.As(err, &clientErr) {
329+
slog.Warn("Failed to post record",
330+
"event_type", eventType,
331+
"name", record.Name,
332+
"deployment_name", record.DeploymentName,
333+
"status", record.Status,
334+
"digest", record.Digest,
335+
"error", err,
336+
)
337+
return nil
338+
}
339+
326340
slog.Error("Failed to post record",
327341
"event_type", eventType,
328342
"name", record.Name,

pkg/deploymentrecord/client.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ func WithAPIToken(token string) ClientOption {
6565
}
6666
}
6767

68+
// ClientError represents a client error that can not be retried.
69+
type ClientError struct {
70+
err error
71+
}
72+
73+
func (c *ClientError) Error() string {
74+
return fmt.Sprintf("client_error: %s", c.err.Error())
75+
}
76+
77+
func (c *ClientError) Unwrap() error {
78+
return c.err
79+
}
80+
6881
// PostOne posts a single deployment record to the GitHub deployment
6982
// records API.
7083
func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
@@ -129,11 +142,10 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
129142
// Don't retry on client errors (4xx) except for 429
130143
// (rate limit)
131144
if resp.StatusCode >= 400 && resp.StatusCode < 500 && resp.StatusCode != 429 {
132-
metrics.PostDeploymentRecordHardFail.Inc()
133-
slog.Error("irrecoverable error, aborting",
145+
slog.Warn("client error, aborting",
134146
"attempt", attempt,
135147
"error", lastErr)
136-
return lastErr
148+
return &ClientError{err: lastErr}
137149
}
138150
metrics.PostDeploymentRecordSoftFail.Inc()
139151
}

0 commit comments

Comments
 (0)