Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

fix: avoid json unmarshal error in agent client #179

Merged
merged 2 commits into from
Sep 19, 2023
Merged
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: 2 additions & 12 deletions agent/client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"strings"

"github.com/cockroachdb/errors"
"github.com/docker/docker/api/types"
"github.com/sirupsen/logrus"

"github.com/tensorchord/openmodelz/agent/errdefs"
Expand Down Expand Up @@ -128,7 +127,7 @@ func (cli *Client) buildRequest(method, path string, body io.Reader, headers hea
func (cli *Client) sendRequest(ctx context.Context, method, path string, query url.Values, body io.Reader, headers headers) (serverResponse, error) {
req, err := cli.buildRequest(method, cli.getAPIPath(ctx, path, query), body, headers)
if err != nil {
return serverResponse{}, err
return serverResponse{}, errors.Wrap(err, "failed to build request")
}

resp, err := cli.doRequest(ctx, req)
Expand Down Expand Up @@ -216,16 +215,7 @@ func (cli *Client) checkResponseErr(serverResp serverResponse) error {
return fmt.Errorf("request returned %s for API route and version %s, check if the server supports the requested API version", http.StatusText(serverResp.statusCode), serverResp.reqURL)
}

var errorMessage string
if cli.version == "" {
var errorResponse types.ErrorResponse
if err := json.Unmarshal(body, &errorResponse); err != nil {
return errors.Wrap(err, "Error reading JSON")
}
errorMessage = strings.TrimSpace(errorResponse.Message)
} else {
errorMessage = strings.TrimSpace(string(body))
}
errorMessage := strings.TrimSpace(string(body))

return errors.Wrap(errors.New(errorMessage), "Error response from gateway")
}
Expand Down
6 changes: 3 additions & 3 deletions agent/pkg/server/handler_inference_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (s *Server) forward(c *gin.Context, namespace, name string) (int, error) {
}
defer s.endpointResolver.Close(backendURL)

proxyServer := httputil.NewSingleHostReverseProxy(&backendURL)
proxyServer := httputil.ReverseProxy{}
proxyServer.Transport = &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Expand All @@ -106,7 +106,6 @@ func (s *Server) forward(c *gin.Context, namespace, name string) (int, error) {
targetQuery := backendURL.RawQuery
req.URL.Scheme = backendURL.Scheme
req.URL.Host = backendURL.Host
// req.URL.Path, req.URL.RawPath = joinURLPath(target, req.URL)
if targetQuery == "" || req.URL.RawQuery == "" {
req.URL.RawQuery = targetQuery + req.URL.RawQuery
} else {
Expand All @@ -119,7 +118,8 @@ func (s *Server) forward(c *gin.Context, namespace, name string) (int, error) {

s.logger.WithField("url", backendURL.String()).
WithField("path", req.URL.Path).
WithField("raw-query", req.URL.RawQuery).Debug("proxying")
WithField("header", req.Header).
WithField("raw-query", req.URL.RawQuery).Debug("reverse proxy")
}

var statusCode int
Expand Down
Loading