Skip to content

Commit

Permalink
update according to review comments (#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
localvar committed Jun 28, 2022
1 parent fdce281 commit 4661301
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions pkg/filters/proxy/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func (sp *ServerPool) handleMirror(spCtx *serverPoolContext) {

err := spCtx.prepareRequest(svr, spCtx.req.Context(), true)
if err != nil {
logger.Debugf("failed to prepare request: %v", err)
logger.Debugf("%s: failed to prepare request: %v", sp.name, err)
return
}

Expand Down Expand Up @@ -488,7 +488,7 @@ func (sp *ServerPool) handle(ctx *context.Context, mirror bool) string {
// Circuit breaker is the most outside resiliencer, if the error
// is ErrShortCircuited, we are sure the response is nil.
if err == resilience.ErrShortCircuited {
logger.Debugf("short circuited by circuit break policy")
logger.Debugf("%s: short circuited by circuit break policy", sp.name)
spCtx.AddTag("short circuited")
sp.buildFailureResponse(spCtx, http.StatusServiceUnavailable)
return resultShortCircuited
Expand All @@ -512,21 +512,21 @@ func (sp *ServerPool) doHandle(stdctx stdcontext.Context, spCtx *serverPoolConte

// if there's no available server.
if svr == nil {
logger.Debugf("no available server")
logger.Debugf("%s: no available server", sp.name)
return serverPoolError{http.StatusServiceUnavailable, resultInternalError}
}

// prepare the request to send.
statResult := &gohttpstat.Result{}
stdctx = gohttpstat.WithHTTPStat(stdctx, statResult)
if err := spCtx.prepareRequest(svr, stdctx, false); err != nil {
logger.Debugf("failed to prepare request: %v", err)
logger.Debugf("%s: failed to prepare request: %v", sp.name, err)
return serverPoolError{http.StatusInternalServerError, resultInternalError}
}

resp, err := fnSendRequest(spCtx.stdReq, sp.proxy.client)
if err != nil {
logger.Debugf("failed to send request: %v", err)
logger.Debugf("%s: failed to send request: %v", sp.name, err)

statResult.End(fasttime.Now())
spCtx.LazyAddTag(func() string {
Expand Down Expand Up @@ -581,7 +581,7 @@ func (sp *ServerPool) buildResponse(spCtx *serverPoolContext) (err error) {

resp, err := httpprot.NewResponse(spCtx.stdResp)
if err != nil {
logger.Debugf("NewResponse returns an error: %v", err)
logger.Debugf("%s: NewResponse returns an error: %v", sp.name, err)
body.Close()
return err
}
Expand All @@ -591,7 +591,7 @@ func (sp *ServerPool) buildResponse(spCtx *serverPoolContext) (err error) {
maxBodySize = sp.proxy.spec.ServerMaxBodySize
}
if err = resp.FetchPayload(maxBodySize); err != nil {
logger.Debugf("failed to fetch response payload: %v", err)
logger.Debugf("%s: failed to fetch response payload: %v", sp.name, err)
body.Close()
return err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/object/httpserver/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,10 @@ func (mi *muxInstance) serveHTTP(stdw http.ResponseWriter, stdr *http.Request) {
defer func() {
var resp *httpprot.Response
if v := ctx.GetResponse(context.DefaultNamespace); v == nil {
logger.Errorf("response is nil")
logger.Errorf("%s: response is nil", mi.superSpec.Name())
resp = buildFailureResponse(ctx, http.StatusServiceUnavailable)
} else if r, ok := v.(*httpprot.Response); !ok {
logger.Errorf("expect an HTTP response")
logger.Errorf("%s: expect an HTTP response", mi.superSpec.Name())
resp = buildFailureResponse(ctx, http.StatusServiceUnavailable)
} else {
resp = r
Expand Down Expand Up @@ -487,14 +487,14 @@ func (mi *muxInstance) serveHTTP(stdw http.ResponseWriter, stdr *http.Request) {

route := mi.search(req)
if route.code != 0 {
logger.Debugf("status code of result route: %d", route.code)
logger.Debugf("%s: status code of result route: %d", mi.superSpec.Name(), route.code)
buildFailureResponse(ctx, route.code)
return
}

handler, ok := mi.muxMapper.GetHandler(route.path.backend)
if !ok {
logger.Debugf("backend %q not found", route.path.backend)
logger.Debugf("%s: backend %q not found", mi.superSpec.Name(), route.path.backend)
buildFailureResponse(ctx, http.StatusServiceUnavailable)
return
}
Expand All @@ -510,12 +510,12 @@ func (mi *muxInstance) serveHTTP(stdw http.ResponseWriter, stdr *http.Request) {
}
err := req.FetchPayload(maxBodySize)
if err == httpprot.ErrRequestEntityTooLarge {
logger.Debugf(err.Error())
logger.Debugf("%s: %s", mi.superSpec.Name(), err.Error())
buildFailureResponse(ctx, http.StatusRequestEntityTooLarge)
return
}
if err != nil {
logger.Debugf("failed to read request body: %v", err)
logger.Debugf("%s: failed to read request body: %v", mi.superSpec.Name(), err)
buildFailureResponse(ctx, http.StatusBadRequest)
return
}
Expand Down

0 comments on commit 4661301

Please sign in to comment.