Skip to content
Merged
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
21 changes: 16 additions & 5 deletions pkg/deploymentrecord/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,18 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
continue
}

// Drain and close response body to enable connection reuse
_, _ = io.Copy(io.Discard, resp.Body)
_ = resp.Body.Close()

if resp.StatusCode >= 200 && resp.StatusCode < 300 {
// Drain and close response body to enable connection reuse
_, _ = io.Copy(io.Discard, resp.Body)
_ = resp.Body.Close()
dtmetrics.PostDeploymentRecordOk.Inc()
return nil
}

// Drain and close response body to enable connection reuse by reading body for error logging
body, _ := io.ReadAll(resp.Body)
_ = resp.Body.Close()

lastErr = fmt.Errorf("unexpected status code: %d", resp.StatusCode)

// Don't retry on client errors (4xx) except for 429
Expand All @@ -257,10 +260,18 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
dtmetrics.PostDeploymentRecordClientError.Inc()
slog.Warn("client error, aborting",
"attempt", attempt,
"error", lastErr)
"error", lastErr,
"status_code", resp.StatusCode,
"msg", string(body),
)
return &ClientError{err: lastErr}
}
dtmetrics.PostDeploymentRecordSoftFail.Inc()
slog.Debug("retriable server error",
"attempt", attempt,
"status_code", resp.StatusCode,
"msg", string(body),
)
}

dtmetrics.PostDeploymentRecordHardFail.Inc()
Expand Down
Loading