Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executor Returns Clearer Errors on HTTP Failures #3626

Merged
merged 4 commits into from
Oct 26, 2021
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
34 changes: 25 additions & 9 deletions executor/api/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import (
"bytes"
"context"
"encoding/json"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
"strconv"
"strings"
"time"

http2 "github.com/cloudevents/sdk-go/pkg/bindings/http"
"github.com/go-logr/logr"
"github.com/golang/protobuf/jsonpb"
Expand All @@ -19,15 +28,7 @@ import (
"github.com/seldonio/seldon-core/executor/api/util"
"github.com/seldonio/seldon-core/executor/k8s"
v1 "github.com/seldonio/seldon-core/operator/apis/machinelearning.seldon.io/v1"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"strconv"
"strings"
"time"
)

const (
Expand All @@ -50,7 +51,13 @@ func (smc *JSONRestClient) IsGrpc() bool {
}

func (smc *JSONRestClient) CreateErrorPayload(err error) payload.SeldonPayload {
respFailed := proto.SeldonMessage{Status: &proto.Status{Code: http.StatusInternalServerError, Info: err.Error()}}
respFailed := proto.SeldonMessage{
Status: &proto.Status{
Code: http.StatusInternalServerError,
Info: err.Error(),
Status: proto.Status_FAILURE,
},
}
m := jsonpb.Marshaler{}
jStr, _ := m.MarshalToString(&respFailed)
res := payload.BytesPayload{Msg: []byte(jStr)}
Expand Down Expand Up @@ -291,7 +298,16 @@ func (smc *JSONRestClient) call(ctx context.Context, modelName string, method st
contentType = req.GetContentType()
contentEncoding = req.GetContentEncoding()
}

sm, contentType, contentEncoding, err := smc.doHttp(ctx, modelName, method, &url, bytes, meta, contentType, contentEncoding)

// Check if a httpStatusError was returned.
if err != nil {
if _, ok := err.(*httpStatusError); !ok {
return smc.CreateErrorPayload(err), err
}
}

res := payload.BytesPayload{Msg: sm, ContentType: contentType, ContentEncoding: contentEncoding}
return &res, err
}
Expand Down
10 changes: 9 additions & 1 deletion executor/api/rest/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,16 @@ func TestTimeout(t *testing.T) {
seldonRestClient, err := NewJSONRestClient(api.ProtocolSeldon, "test", &predictor, annotations)
g.Expect(err).To(BeNil())

_, err = seldonRestClient.Status(createTestContext(), "model", host, int32(port), nil, map[string][]string{})
r, err := seldonRestClient.Status(createTestContext(), "model", host, int32(port), nil, map[string][]string{})
g.Expect(err).ToNot(BeNil())
g.Expect(r).ToNot((BeNil()))

data := r.GetPayload().([]byte)
var smRes proto.SeldonMessage
err = jsonpb.UnmarshalString(string(data), &smRes)
g.Expect(err).Should(BeNil())
g.Expect(smRes.GetStatus().GetCode()).Should(BeEquivalentTo(int32(500)))
g.Expect(smRes.GetStatus().GetInfo()).Should(ContainSubstring("Client.Timeout exceeded while awaiting headers"))
}

func TestMarshall(t *testing.T) {
Expand Down