-
Notifications
You must be signed in to change notification settings - Fork 835
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
Add Seldon PUID Header to gRPC context + tests #1790
Changes from 3 commits
1dccd80
33f0e82
0b8dad6
60a02af
5e03400
1d3ca47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,11 @@ import ( | |
"context" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/golang/protobuf/jsonpb" | ||
. "github.com/onsi/gomega" | ||
"github.com/seldonio/seldon-core/executor/api/grpc" | ||
|
@@ -12,11 +17,7 @@ import ( | |
"github.com/seldonio/seldon-core/executor/api/test" | ||
"github.com/seldonio/seldon-core/executor/logger" | ||
v1 "github.com/seldonio/seldon-core/operator/apis/machinelearning.seldon.io/v1" | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" | ||
"testing" | ||
) | ||
|
||
const ( | ||
|
@@ -50,6 +51,13 @@ func createPredictorProcessWithError(t *testing.T, errMethod *v1.PredictiveUnitM | |
return &pp | ||
} | ||
|
||
func createPredictorProcessWithoutPUID(t *testing.T) *PredictorProcess { | ||
url, _ := url.Parse(testSourceUrl) | ||
ctx := context.WithValue(context.TODO(), payload.SeldonPUIDHeader, nil) | ||
pp := NewPredictorProcess(ctx, &test.SeldonMessageTestClient{}, logf.Log.WithName("SeldonMessageRestClient"), url, "default", map[string][]string{testCustomMetaKey: []string{testCustomMetaValue}}) | ||
return &pp | ||
} | ||
|
||
func createPredictPayload(g *GomegaWithT) payload.SeldonPayload { | ||
var sm proto.SeldonMessage | ||
var data = ` {"data":{"ndarray":[1.1,2.0]}}` | ||
|
@@ -455,3 +463,85 @@ func TestModelWithLogResponses(t *testing.T) { | |
g.Expect(smRes.GetData().GetNdarray().Values[1].GetNumberValue()).Should(Equal(2.0)) | ||
g.Eventually(func() bool { return logged }).Should(Equal(true)) | ||
} | ||
|
||
func TestModelWithLogRequestsNilPUIDError(t *testing.T) { | ||
t.Logf("Started") | ||
g := NewGomegaWithT(t) | ||
modelName := "foo" | ||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
//g.Expect(r.Header.Get(logger.CloudEventsIdHeader)).Should(Equal(testEventId)) | ||
g.Expect(r.Header.Get(logger.CloudEventsTypeHeader)).To(Equal(logger.CEInferenceRequest)) | ||
g.Expect(r.Header.Get(logger.CloudEventsTypeSource)).To(Equal(testSourceUrl)) | ||
g.Expect(r.Header.Get(modelIdHeaderName)).To(Equal(modelName)) | ||
g.Expect(r.Header.Get(contentTypeHeaderName)).To(Equal(grpc.ProtobufContentType)) | ||
g.Expect(r.Header.Get(requestIdHeaderName)).To(Equal(testSeldonPuid)) | ||
w.Write([]byte("")) | ||
fmt.Printf("%+v\n", r.Header) | ||
fmt.Printf("%+v\n", r.Body) | ||
}) | ||
server := httptest.NewServer(handler) | ||
defer server.Close() | ||
|
||
logf.SetLogger(logf.ZapLogger(false)) | ||
log := logf.Log.WithName("entrypoint") | ||
logger.StartDispatcher(1, log, "", "", "") | ||
|
||
model := v1.MODEL | ||
graph := &v1.PredictiveUnit{ | ||
Name: modelName, | ||
Type: &model, | ||
Endpoint: &v1.Endpoint{ | ||
ServiceHost: "foo", | ||
ServicePort: 9000, | ||
Type: v1.REST, | ||
}, | ||
Logger: &v1.Logger{ | ||
Mode: v1.LogRequest, | ||
Url: &server.URL, | ||
}, | ||
} | ||
|
||
_, err := createPredictorProcessWithoutPUID(t).Predict(graph, createPredictPayload(g)) | ||
g.Expect(err).NotTo(BeNil()) | ||
g.Expect(err.Error()).Should(Equal("context value Seldon PUID Header is nil: interface to string conversion failed")) | ||
} | ||
|
||
func TestModelWithLogResponsesNilPUIDError(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems to be almost a duplicate of above test - can't they be combined? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
t.Logf("Started") | ||
g := NewGomegaWithT(t) | ||
modelName := "foo" | ||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
//g.Expect(r.Header.Get(logger.CloudEventsIdHeader)).Should(Equal(testEventId)) | ||
g.Expect(r.Header.Get(logger.CloudEventsTypeHeader)).To(Equal(logger.CEInferenceResponse)) | ||
g.Expect(r.Header.Get(logger.CloudEventsTypeSource)).To(Equal(testSourceUrl)) | ||
g.Expect(r.Header.Get(modelIdHeaderName)).To(Equal(modelName)) | ||
g.Expect(r.Header.Get(contentTypeHeaderName)).To(Equal(grpc.ProtobufContentType)) | ||
g.Expect(r.Header.Get(requestIdHeaderName)).To(Equal(testSeldonPuid)) | ||
w.Write([]byte("")) | ||
}) | ||
server := httptest.NewServer(handler) | ||
defer server.Close() | ||
|
||
logf.SetLogger(logf.ZapLogger(false)) | ||
log := logf.Log.WithName("entrypoint") | ||
logger.StartDispatcher(1, log, "", "", "") | ||
|
||
model := v1.MODEL | ||
graph := &v1.PredictiveUnit{ | ||
Name: modelName, | ||
Type: &model, | ||
Endpoint: &v1.Endpoint{ | ||
ServiceHost: "foo", | ||
ServicePort: 9000, | ||
Type: v1.REST, | ||
}, | ||
Logger: &v1.Logger{ | ||
Mode: v1.LogResponse, | ||
Url: &server.URL, | ||
}, | ||
} | ||
|
||
_, err := createPredictorProcessWithoutPUID(t).Predict(graph, createPredictPayload(g)) | ||
g.Expect(err).NotTo(BeNil()) | ||
g.Expect(err.Error()).Should(Equal("context value Seldon PUID Header is nil: interface to string conversion failed")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The message should be turned into a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. See #1841 for follow up changes |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed