From 2f7cc45118c353e57336196927d43af09a2ad1dc Mon Sep 17 00:00:00 2001 From: James Ranson Date: Tue, 7 Jul 2026 11:21:01 -0600 Subject: [PATCH] return 500 on internal failures Signed-off-by: James Ranson --- pkg/proxy/engines/deltaproxycache.go | 14 +++++++++++--- pkg/proxy/engines/deltaproxycache_chunk_test.go | 2 +- pkg/proxy/engines/deltaproxycache_test.go | 12 +++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/pkg/proxy/engines/deltaproxycache.go b/pkg/proxy/engines/deltaproxycache.go index 295d69e9d..5911ae9c6 100644 --- a/pkg/proxy/engines/deltaproxycache.go +++ b/pkg/proxy/engines/deltaproxycache.go @@ -62,6 +62,13 @@ const ( errorBodyCap = 1 << 20 ) +func dpcProxyErrorStatusCode(statusCode int) int { + if statusCode == 0 || (statusCode >= http.StatusOK && statusCode < http.StatusMultipleChoices) { + return http.StatusInternalServerError + } + return statusCode +} + // fetchFastForward executes a fast-forward request and merges the result into rts. // Returns the fast-forward status string ("off", "hit", "miss", or "err"). func fetchFastForward( @@ -301,7 +308,7 @@ func DeltaProxyCacheRequest(w http.ResponseWriter, r *http.Request, modeler *tim // buildErrorResult constructs a dpcResult for error responses. buildErrorResult := func(sc int, h http.Header, body []byte, fext timeseries.ExtentList) *dpcResult { return &dpcResult{ - statusCode: sc, + statusCode: dpcProxyErrorStatusCode(sc), headers: h, body: body, elapsed: float64(time.Since(now).Seconds()), @@ -577,9 +584,10 @@ func DeltaProxyCacheRequest(w http.ResponseWriter, r *http.Request, modeler *tim cts, doc, elapsed, failedExts, severeFault = fetchTimeseries(pr, trq, client, modeler) if len(failedExts) > 0 && severeFault { h := doc.SafeHeaderClone() - recordDPCResult(r, status.LookupStatusProxyError, doc.StatusCode, + sc := dpcProxyErrorStatusCode(doc.StatusCode) + recordDPCResult(r, status.LookupStatusProxyError, sc, r.URL.Path, "", elapsed.Seconds(), nil, failedExts, h) - Respond(w, doc.StatusCode, h, bytes.NewReader(doc.Body)) + Respond(w, sc, h, bytes.NewReader(doc.Body)) return } rts = cts.Clone() diff --git a/pkg/proxy/engines/deltaproxycache_chunk_test.go b/pkg/proxy/engines/deltaproxycache_chunk_test.go index 23d442b71..9e332eff6 100644 --- a/pkg/proxy/engines/deltaproxycache_chunk_test.go +++ b/pkg/proxy/engines/deltaproxycache_chunk_test.go @@ -1348,7 +1348,7 @@ func TestDeltaProxyCacheRequestCacheMissUnmarshalFailedChunks(t *testing.T) { t.Error(err) } - err = testStatusCodeMatch(resp.StatusCode, http.StatusOK) + err = testStatusCodeMatch(resp.StatusCode, http.StatusInternalServerError) if err != nil { t.Error(err) } diff --git a/pkg/proxy/engines/deltaproxycache_test.go b/pkg/proxy/engines/deltaproxycache_test.go index 2a5975568..57b6ea4f1 100644 --- a/pkg/proxy/engines/deltaproxycache_test.go +++ b/pkg/proxy/engines/deltaproxycache_test.go @@ -1397,7 +1397,7 @@ func TestDeltaProxyCacheRequestCacheMissUnmarshalFailed(t *testing.T) { t.Error(err) } - err = testStatusCodeMatch(resp.StatusCode, http.StatusOK) + err = testStatusCodeMatch(resp.StatusCode, http.StatusInternalServerError) if err != nil { t.Error(err) } @@ -2136,12 +2136,14 @@ func TestDPCSingleflightBadPayload(t *testing.T) { t.Errorf("expected 1 origin request, got %d", hits) } - // all callers should get a proxy-error cache status (the unmarshaling failure - // triggers buildErrorResult inside the singleflight closure). - // the HTTP status is 200 because that's what the origin returned, but the - // Trickster-Result header indicates the error. + // all callers should get a proxy-error cache status and an Internal Server Error + // response (the unmarshaling failure triggers buildErrorResult inside the + // singleflight closure). for i, rec := range recorders { resp := rec.Result() + if resp.StatusCode != http.StatusInternalServerError { + t.Errorf("request %d: expected status 500, got %d", i, resp.StatusCode) + } hdr := resp.Header.Get(headers.NameTricksterResult) if !strings.Contains(hdr, "status=proxy-error") { t.Errorf("request %d: expected proxy-error in result header, got %q", i, hdr)