From b9335a35f6fabfcac60d805b5cec49f1b90c0964 Mon Sep 17 00:00:00 2001 From: Eric Pickard Date: Fri, 13 Mar 2026 15:35:54 -0400 Subject: [PATCH 1/2] update client error logging --- pkg/deploymentrecord/client.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pkg/deploymentrecord/client.go b/pkg/deploymentrecord/client.go index c335e87..fbb384f 100644 --- a/pkg/deploymentrecord/client.go +++ b/pkg/deploymentrecord/client.go @@ -240,15 +240,17 @@ 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 { + _, _ = io.Copy(io.Discard, resp.Body) + _ = resp.Body.Close() dtmetrics.PostDeploymentRecordOk.Inc() return nil } + // Read response body for error messages + 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 @@ -257,10 +259,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() From 80af440d931cad5ac3fb5e50bc39198603901bd4 Mon Sep 17 00:00:00 2001 From: Eric Pickard Date: Fri, 13 Mar 2026 15:41:12 -0400 Subject: [PATCH 2/2] add comments --- pkg/deploymentrecord/client.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/deploymentrecord/client.go b/pkg/deploymentrecord/client.go index fbb384f..fe50b74 100644 --- a/pkg/deploymentrecord/client.go +++ b/pkg/deploymentrecord/client.go @@ -241,13 +241,14 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error { } 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 } - // Read response body for error messages + // Drain and close response body to enable connection reuse by reading body for error logging body, _ := io.ReadAll(resp.Body) _ = resp.Body.Close()