Skip to content

Commit

Permalink
Fix experiment bug (#405)
Browse files Browse the repository at this point in the history
* Fix experiment bug

* review fixes
  • Loading branch information
ukclivecox authored Aug 24, 2022
1 parent 24ff144 commit 4b18c43
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 105 deletions.
2 changes: 2 additions & 0 deletions docs/source/contents/kubernetes/resources/experiment/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ For an example see the [local experiments notebook](../../../examples/local-expe

To allow cohorts to get consistent views in an experiment each inference request passes back a response header `x-seldon-route` which can be passed in future requests to an experiment to bypass the random traffic splits and get a prediction from the sequence of models and pipelines used in the initial request.

Note: you must pass the normal `seldon-model` header along with the `x-seldon-route` header.

This is illustrated in the [local experiments notebook](../../../examples/local-experiments.md).

Caveats:
Expand Down
40 changes: 17 additions & 23 deletions operator/pkg/cli/infer.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,21 @@ func decodeV2Error(response *http.Response, b []byte) error {

}

func (ic *InferenceClient) call(resourceName string, path string, data []byte, inferType InferType, showHeaders bool, headers []string, stickySesionKeys []string) ([]byte, error) {
func (ic *InferenceClient) call(resourceName string, path string, data []byte, inferType InferType, showHeaders bool, headers []string, stickySessionKeys []string) ([]byte, error) {
v2Url := ic.getUrl(path)
req, err := http.NewRequest("POST", v2Url.String(), bytes.NewBuffer(data))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
if stickySesionKeys != nil {
for _, stickySessionKey := range stickySesionKeys {
req.Header.Add(SeldonRouteHeader, stickySessionKey)
}
} else {
switch inferType {
case InferModel:
req.Header.Set(SeldonModelHeader, resourceName)
case InferPipeline:
req.Header.Set(SeldonModelHeader, fmt.Sprintf("%s.%s", resourceName, SeldonPipelineHeader))
}
for _, stickySessionKey := range stickySessionKeys {
req.Header.Add(SeldonRouteHeader, stickySessionKey)
}
switch inferType {
case InferModel:
req.Header.Set(SeldonModelHeader, resourceName)
case InferPipeline:
req.Header.Set(SeldonModelHeader, fmt.Sprintf("%s.%s", resourceName, SeldonPipelineHeader))
}

for _, header := range headers {
Expand Down Expand Up @@ -368,17 +365,14 @@ func (ic *InferenceClient) InferGrpc(resourceName string, data []byte, showReque
}
grpcClient := v2_dataplane.NewGRPCInferenceServiceClient(conn)
ctx := context.TODO()
if stickySessionKeys != nil {
for _, stickySessionKey := range stickySessionKeys {
ctx = metadata.AppendToOutgoingContext(ctx, SeldonRouteHeader, stickySessionKey)
}
} else {
switch inferType {
case InferModel:
ctx = metadata.AppendToOutgoingContext(ctx, SeldonModelHeader, resourceName)
case InferPipeline:
ctx = metadata.AppendToOutgoingContext(ctx, SeldonModelHeader, fmt.Sprintf("%s.%s", resourceName, SeldonPipelineHeader))
}
for _, stickySessionKey := range stickySessionKeys {
ctx = metadata.AppendToOutgoingContext(ctx, SeldonRouteHeader, stickySessionKey)
}
switch inferType {
case InferModel:
ctx = metadata.AppendToOutgoingContext(ctx, SeldonModelHeader, resourceName)
case InferPipeline:
ctx = metadata.AppendToOutgoingContext(ctx, SeldonModelHeader, fmt.Sprintf("%s.%s", resourceName, SeldonPipelineHeader))
}

for _, header := range headers {
Expand Down
Loading

0 comments on commit 4b18c43

Please sign in to comment.