Fix status code for rate limit (#1924)

Co-authored-by: Rahul Bhati <rjbhati009@gmail.com>
Co-authored-by: Vishal <vishal-biyani@users.noreply.github.com>
This commit is contained in:
Harsh Thakur
2021-02-05 16:52:43 +05:30
committed by GitHub
co-authored by Rahul Bhati Vishal
parent e2376c27b4
commit f28799cc4c
3 changed files with 9 additions and 17 deletions
-6
View File
@@ -25,7 +25,6 @@ require (
github.com/go-ini/ini v1.62.0 // indirect
github.com/go-openapi/spec v0.17.2
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/gorilla/mux v1.7.0
github.com/gotestyourself/gotestyourself v2.2.0+incompatible // indirect
github.com/graymeta/stow v0.0.0-20180719215413-7b5498c561bb
@@ -40,8 +39,6 @@ require (
github.com/nats-io/nats.go v1.9.1
github.com/nats-io/stan.go v0.6.0
github.com/nwaples/rardecode v1.1.0 // indirect
github.com/onsi/ginkgo v1.7.0 // indirect
github.com/onsi/gomega v1.4.3 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opencontainers/runc v0.1.1 // indirect
github.com/ory/dockertest v3.3.5+incompatible
@@ -52,15 +49,12 @@ require (
github.com/satori/go.uuid v1.2.0
github.com/spf13/cobra v1.1.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.5.1
github.com/ulikunitz/xz v0.5.9 // indirect
github.com/wcharczuk/go-chart v2.0.1+incompatible
go.opencensus.io v0.22.4
go.uber.org/multierr v1.5.0 // indirect
go.uber.org/zap v1.10.0
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
gopkg.in/jcmturner/goidentity.v3 v3.0.0 // indirect
k8s.io/api v0.0.0-20190620084959-7cf5895f2711
k8s.io/apiextensions-apiserver v0.0.0-20190620085554-14e95df34f1f
+8 -10
View File
@@ -191,11 +191,9 @@ func (roundTripper *RetryingRoundTripper) RoundTrip(req *http.Request) (*http.Re
// We might want a specific error code or header for fission failures as opposed to
// user function bugs.
statusCode, errMsg := ferror.GetHTTPError(err)
// if statusCode == http.StatusTooManyRequests {
// time.Sleep(executingTimeout)
// executingTimeout = executingTimeout * time.Duration(roundTripper.funcHandler.tsRoundTripperParams.timeoutExponent)
// continue
// } else {
if statusCode == http.StatusTooManyRequests {
return nil, err
}
if roundTripper.funcHandler.isDebugEnv {
return &http.Response{
StatusCode: statusCode,
@@ -209,7 +207,7 @@ func (roundTripper *RetryingRoundTripper) RoundTrip(req *http.Request) (*http.Re
}, nil
}
return nil, ferror.MakeError(http.StatusInternalServerError, err.Error())
// }
}
if roundTripper.funcHandler.function.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fv1.ExecutorTypePoolmgr {
defer func(fn *fv1.Function, serviceURL *url.URL) {
@@ -558,7 +556,6 @@ func (fh functionHandler) getProxyErrorHandler(start time.Time, rrt *RetryingRou
return func(rw http.ResponseWriter, req *http.Request, err error) {
var status int
var msg string
switch err {
case context.Canceled:
// 499 CLIENT CLOSED REQUEST
@@ -573,14 +570,15 @@ func (fh functionHandler) getProxyErrorHandler(start time.Time, rrt *RetryingRou
msg = "function not responses before the timeout"
fh.logger.Error(msg, zap.Any("function", fh.function), zap.Any("request_header", req.Header))
default:
status = http.StatusBadGateway
code, msg := ferror.GetHTTPError(err)
status = code
msg = "error sending request to function"
fh.logger.Error(msg, zap.Error(err), zap.Any("function", fh.function), zap.Any("request_header", req.Header))
fh.logger.Error(msg, zap.Error(err), zap.Any("function", fh.function), zap.Any("request_header", req.Header), zap.Any("code", code))
}
go fh.collectFunctionMetric(start, rrt, req, &http.Response{
StatusCode: status,
ContentLength: 0,
ContentLength: req.ContentLength,
})
// TODO: return error message that contains traceable UUID back to user. Issue #693
+1 -1
View File
@@ -65,5 +65,5 @@ func TestProxyErrorHandler(t *testing.T) {
respRecorder = httptest.NewRecorder()
errHandler(respRecorder, req, errors.New("dummy"))
assert.Equal(t, http.StatusBadGateway, respRecorder.Code)
assert.Equal(t, http.StatusInternalServerError, respRecorder.Code)
}