diff --git a/Dockerfile b/Dockerfile index b8b9331..bf6bad8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -76,13 +76,15 @@ WORKDIR /opt/app COPY go.mod go.sum ./ -# Install go protoc plugins +# Install go protoc plugins, +# no required module provides package google.golang.org/grpc/cmd/protoc-gen-go-grpc +# to add it run `go get google.golang.org/grpc/cmd/protoc-gen-go-grpc` ENV PATH $HOME/go/bin:$PATH RUN true \ - && go get google.golang.org/protobuf/cmd/protoc-gen-go \ - google.golang.org/grpc/cmd/protoc-gen-go-grpc \ - && go install google.golang.org/protobuf/cmd/protoc-gen-go \ - google.golang.org/grpc/cmd/protoc-gen-go-grpc \ + && go get google.golang.org/grpc/cmd/protoc-gen-go-grpc \ + && go install google.golang.org/grpc/cmd/protoc-gen-go-grpc \ + google.golang.org/protobuf/cmd/protoc-gen-go \ + github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \ && protoc-gen-go --version \ && true diff --git a/Makefile b/Makefile index 57eb5e6..8317090 100644 --- a/Makefile +++ b/Makefile @@ -23,8 +23,17 @@ ifeq (run,$(firstword $(MAKECMDGOALS))) endif .PHONY: all -## Alias for `build` -all: build +## Alias for `generate build test` +all: generate build test + +.PHONY: generate +## Generate GRPC gateway stubs +generate: google/api/annotations.proto google/api/http.proto + protoc -I . --grpc-gateway_out ./gen/ --grpc-gateway_opt logtostderr=true --grpc-gateway_opt paths=source_relative grpc_predict_v2.proto + +google/api/%.proto: + @mkdir -p google/api + @test -f $@ || wget --inet4-only -q -O $@ https://raw.githubusercontent.com/googleapis/googleapis/master/$@ .PHONY: build ## Build runtime Docker image diff --git a/OWNERS b/OWNERS index 50b1c8a..e768919 100644 --- a/OWNERS +++ b/OWNERS @@ -1,12 +1,20 @@ approvers: + - davidesalerno - heyselbi - israel-hdez - Jooho + - rpancham + - spolti + - vaibhavjainwiz - VedantMahabaleshwarkar - Xaenalt reviewers: + - davidesalerno - heyselbi - israel-hdez - Jooho + - rpancham + - spolti + - vaibhavjainwiz - VedantMahabaleshwarkar - Xaenalt diff --git a/README.md b/README.md index 3d06f81..2578ef3 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,50 @@ # KServe V2 REST Proxy -This REST Proxy leverages [gRPC-Gateway](https://github.com/grpc-ecosystem/grpc-gateway) to create a reverse-proxy server which translates a RESTful HTTP API into gRPC. This allows sending inference requests using the [KServe V2 REST Predict Protocol](https://github.com/kserve/kserve/blob/master/docs/predict-api/v2/required_api.md#httprest) to platforms that expect the [gRPC V2 Predict Protocol](https://github.com/kserve/kserve/blob/master/docs/predict-api/v2/required_api.md#grpc). +This REST Proxy leverages [gRPC-Gateway](https://github.com/grpc-ecosystem/grpc-gateway) +to create a reverse-proxy server which translates a RESTful HTTP API into gRPC. +This allows sending inference requests using the [KServe V2 REST Predict Protocol](https://github.com/kserve/kserve/blob/master/docs/predict-api/v2/required_api.md#httprest) +to platforms that expect the [gRPC V2 Predict Protocol](https://github.com/kserve/kserve/blob/master/docs/predict-api/v2/required_api.md#grpc). **Note:** This is currently a work in progress, and is subject to performance and usability issues. -### Generate grpc-gateway stubs +### Install the ProtoBuf compiler + +The protocol buffer compiler, `protoc` is required to compile the `.proto` files. +To install it, follow the instructions [here](https://grpc.io/docs/protoc-installation/). + +### Generate the gRPC gateway stubs + +After changing the `grpc_predict_v2.proto` file, run the `protoc` compiler to regenerate +the gRPC gateway code stubs. It's recommended to use the developer image which has +all the required libraries pre-installed. + +```bash +make run generate +``` + +### Build the Docker image + +After regenerating the gRPC gateway stubs, rebuild the `rest-proxy` Docker image. ```bash -protoc -I . --grpc-gateway_out ./gen/ --grpc-gateway_opt logtostderr=true --grpc-gateway_opt paths=source_relative grpc_predict_v2.proto +make build ``` -### Build Docker image +### Push the Docker image + +Before pushing the new `rest-proxy` image to your container registry, re-tag the +image created by `make build` in the step above. ```bash -docker build -t kserve/rest-proxy:latest . +DOCKER_USER="kserve" +DOCKER_TAG="dev" +docker tag kserve/rest-proxy:latest ${DOCKER_USER}/rest-proxy:${DOCKER_TAG} +docker push ${DOCKER_USER}/rest-proxy:${DOCKER_TAG} ``` + +### Update your ModelMesh deployment + +In order to use the newly built `rest-proxy` image in a [ModelMesh Serving deployment](https://github.com/kserve/modelmesh-serving#modelmesh-serving) update the `restProxy.image` in [config/default/config-defaults.yaml](https://github.com/kserve/modelmesh-serving/blob/v0.11.0/config/default/config-defaults.yaml#L31-L32) and (re)deploy the ModelMesh Serving. + +To update a running deployment of ModelMesh serving, add or update the `restProxy.image` section in the `model-serving-config` `ConfigMap` as described the [ModelMesh Serving configuration instructions](https://github.com/kserve/modelmesh-serving/tree/main/docs/configuration). diff --git a/gen/grpc_predict_v2.pb.gw.go b/gen/grpc_predict_v2.pb.gw.go index 518d1cc..db04147 100644 --- a/gen/grpc_predict_v2.pb.gw.go +++ b/gen/grpc_predict_v2.pb.gw.go @@ -31,6 +31,148 @@ var _ = runtime.String var _ = utilities.NewDoubleArray var _ = metadata.Join +var ( + filter_GRPCInferenceService_ModelMetadata_0 = &utilities.DoubleArray{Encoding: map[string]int{"name": 0}, Base: []int{1, 2, 0, 0}, Check: []int{0, 1, 2, 2}} +) + +func request_GRPCInferenceService_ModelMetadata_0(ctx context.Context, marshaler runtime.Marshaler, client GRPCInferenceServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ModelMetadataRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["name"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") + } + + protoReq.Name, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_GRPCInferenceService_ModelMetadata_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.ModelMetadata(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_GRPCInferenceService_ModelMetadata_0(ctx context.Context, marshaler runtime.Marshaler, server GRPCInferenceServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ModelMetadataRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["name"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") + } + + protoReq.Name, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) + } + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_GRPCInferenceService_ModelMetadata_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.ModelMetadata(ctx, &protoReq) + return msg, metadata, err + +} + +func request_GRPCInferenceService_ModelMetadata_1(ctx context.Context, marshaler runtime.Marshaler, client GRPCInferenceServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ModelMetadataRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["name"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") + } + + protoReq.Name, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) + } + + val, ok = pathParams["version"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "version") + } + + protoReq.Version, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "version", err) + } + + msg, err := client.ModelMetadata(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_GRPCInferenceService_ModelMetadata_1(ctx context.Context, marshaler runtime.Marshaler, server GRPCInferenceServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ModelMetadataRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["name"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") + } + + protoReq.Name, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) + } + + val, ok = pathParams["version"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "version") + } + + protoReq.Version, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "version", err) + } + + msg, err := server.ModelMetadata(ctx, &protoReq) + return msg, metadata, err + +} + func request_GRPCInferenceService_ModelInfer_0(ctx context.Context, marshaler runtime.Marshaler, client GRPCInferenceServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq ModelInferRequest var metadata runtime.ServerMetadata @@ -100,7 +242,7 @@ func local_request_GRPCInferenceService_ModelInfer_0(ctx context.Context, marsha } var ( - filter_GRPCInferenceService_ModelInfer_1 = &utilities.DoubleArray{Encoding: map[string]int{"model_name": 0, "model_version": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} + filter_GRPCInferenceService_ModelInfer_1 = &utilities.DoubleArray{Encoding: map[string]int{"model_name": 0, "modelName": 1, "model_version": 2, "modelVersion": 3}, Base: []int{1, 1, 2, 3, 4, 0, 0, 0, 0}, Check: []int{0, 1, 1, 1, 1, 2, 3, 4, 5}} ) func request_GRPCInferenceService_ModelInfer_1(ctx context.Context, marshaler runtime.Marshaler, client GRPCInferenceServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { @@ -195,49 +337,103 @@ func local_request_GRPCInferenceService_ModelInfer_1(ctx context.Context, marsha // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterGRPCInferenceServiceHandlerFromEndpoint instead. func RegisterGRPCInferenceServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server GRPCInferenceServiceServer) error { - mux.Handle("POST", pattern_GRPCInferenceService_ModelInfer_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_GRPCInferenceService_ModelMetadata_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/inference.GRPCInferenceService/ModelInfer", runtime.WithHTTPPathPattern("/v2/models/{model_name}/infer")) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/inference.GRPCInferenceService/ModelMetadata", runtime.WithHTTPPathPattern("/v2/models/{name}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_GRPCInferenceService_ModelInfer_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_GRPCInferenceService_ModelMetadata_0(annotatedContext, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_GRPCInferenceService_ModelMetadata_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_GRPCInferenceService_ModelMetadata_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/inference.GRPCInferenceService/ModelMetadata", runtime.WithHTTPPathPattern("/v2/models/{name}/versions/{version}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } + resp, md, err := local_request_GRPCInferenceService_ModelMetadata_1(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } - forward_GRPCInferenceService_ModelInfer_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_GRPCInferenceService_ModelMetadata_1(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("POST", pattern_GRPCInferenceService_ModelInfer_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("POST", pattern_GRPCInferenceService_ModelInfer_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/inference.GRPCInferenceService/ModelInfer", runtime.WithHTTPPathPattern("/v2/models/{model_name}/versions/{model_version}/infer")) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/inference.GRPCInferenceService/ModelInfer", runtime.WithHTTPPathPattern("/v2/models/{model_name}/infer")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_GRPCInferenceService_ModelInfer_1(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_GRPCInferenceService_ModelInfer_0(annotatedContext, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_GRPCInferenceService_ModelInfer_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_GRPCInferenceService_ModelInfer_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/inference.GRPCInferenceService/ModelInfer", runtime.WithHTTPPathPattern("/v2/models/{model_name}/versions/{model_version}/infer")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } + resp, md, err := local_request_GRPCInferenceService_ModelInfer_1(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } - forward_GRPCInferenceService_ModelInfer_1(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_GRPCInferenceService_ModelInfer_1(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -282,43 +478,91 @@ func RegisterGRPCInferenceServiceHandler(ctx context.Context, mux *runtime.Serve // "GRPCInferenceServiceClient" to call the correct interceptors. func RegisterGRPCInferenceServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client GRPCInferenceServiceClient) error { - mux.Handle("POST", pattern_GRPCInferenceService_ModelInfer_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_GRPCInferenceService_ModelMetadata_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req, "/inference.GRPCInferenceService/ModelInfer", runtime.WithHTTPPathPattern("/v2/models/{model_name}/infer")) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/inference.GRPCInferenceService/ModelMetadata", runtime.WithHTTPPathPattern("/v2/models/{name}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_GRPCInferenceService_ModelInfer_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) + resp, md, err := request_GRPCInferenceService_ModelMetadata_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_GRPCInferenceService_ModelMetadata_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_GRPCInferenceService_ModelMetadata_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/inference.GRPCInferenceService/ModelMetadata", runtime.WithHTTPPathPattern("/v2/models/{name}/versions/{version}")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } + resp, md, err := request_GRPCInferenceService_ModelMetadata_1(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } - forward_GRPCInferenceService_ModelInfer_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_GRPCInferenceService_ModelMetadata_1(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("POST", pattern_GRPCInferenceService_ModelInfer_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("POST", pattern_GRPCInferenceService_ModelInfer_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req, "/inference.GRPCInferenceService/ModelInfer", runtime.WithHTTPPathPattern("/v2/models/{model_name}/versions/{model_version}/infer")) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/inference.GRPCInferenceService/ModelInfer", runtime.WithHTTPPathPattern("/v2/models/{model_name}/infer")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_GRPCInferenceService_ModelInfer_1(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) + resp, md, err := request_GRPCInferenceService_ModelInfer_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_GRPCInferenceService_ModelInfer_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_GRPCInferenceService_ModelInfer_1, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/inference.GRPCInferenceService/ModelInfer", runtime.WithHTTPPathPattern("/v2/models/{model_name}/versions/{model_version}/infer")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } + resp, md, err := request_GRPCInferenceService_ModelInfer_1(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } - forward_GRPCInferenceService_ModelInfer_1(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_GRPCInferenceService_ModelInfer_1(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -326,12 +570,20 @@ func RegisterGRPCInferenceServiceHandlerClient(ctx context.Context, mux *runtime } var ( + pattern_GRPCInferenceService_ModelMetadata_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v2", "models", "name"}, "")) + + pattern_GRPCInferenceService_ModelMetadata_1 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"v2", "models", "name", "versions", "version"}, "")) + pattern_GRPCInferenceService_ModelInfer_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"v2", "models", "model_name", "infer"}, "")) pattern_GRPCInferenceService_ModelInfer_1 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3, 1, 0, 4, 1, 5, 4, 2, 5}, []string{"v2", "models", "model_name", "versions", "model_version", "infer"}, "")) ) var ( + forward_GRPCInferenceService_ModelMetadata_0 = runtime.ForwardResponseMessage + + forward_GRPCInferenceService_ModelMetadata_1 = runtime.ForwardResponseMessage + forward_GRPCInferenceService_ModelInfer_0 = runtime.ForwardResponseMessage forward_GRPCInferenceService_ModelInfer_1 = runtime.ForwardResponseMessage diff --git a/grpc_predict_v2.proto b/grpc_predict_v2.proto index 8ade2bc..089e07c 100644 --- a/grpc_predict_v2.proto +++ b/grpc_predict_v2.proto @@ -41,7 +41,14 @@ service GRPCInferenceService // The per-model metadata API provides information about a model. Errors are // indicated by the google.rpc.Status returned for the request. The OK code // indicates success and other codes indicate failure. - rpc ModelMetadata(ModelMetadataRequest) returns (ModelMetadataResponse) {} + rpc ModelMetadata(ModelMetadataRequest) returns (ModelMetadataResponse) { + option (google.api.http) = { + get: "/v2/models/{name}" + additional_bindings { + get: "/v2/models/{name}/versions/{version}" + } + }; + } // The ModelInfer API performs inference using the specified model. Errors are // indicated by the google.rpc.Status returned for the request. The OK code diff --git a/scripts/develop.sh b/scripts/develop.sh index 54701d4..c9fbb95 100755 --- a/scripts/develop.sh +++ b/scripts/develop.sh @@ -39,14 +39,14 @@ exit 1 esac DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -cd "${DIR}/.." || +cd "${DIR}/.." # Make sure .bash_history exists and is a file -touch .bash_history +touch ".bash_history" declare -a docker_run_args=( -v "${PWD}:/opt/app" - -v "${PWD}/.bash_history:/opt/app/.bash_history" + -v "${PWD}/.bash_history:/root/.bash_history" ) if [ "${CI}" != "true" ]; then @@ -55,7 +55,7 @@ if [ "${CI}" != "true" ]; then ) else docker_run_args+=( - -e CI=true + "-e CI=true" ) fi