Skip to content
Open
Show file tree
Hide file tree
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
14 changes: 11 additions & 3 deletions pkg/proxy/engines/deltaproxycache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/engines/deltaproxycache_chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/proxy/engines/deltaproxycache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
Loading