Skip to content

Commit

Permalink
refactor proto (#2173)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpango authored Sep 11, 2023
1 parent 5b9dd88 commit 7f5b8ea
Show file tree
Hide file tree
Showing 33 changed files with 6,064 additions and 534 deletions.
16 changes: 11 additions & 5 deletions Makefile.d/functions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ pink = printf "\x1b[35m\#\# %s\x1b[0m\n" $1
cyan = printf "\x1b[36m\#\# %s\x1b[0m\n" $1

define go-install
GO111MODULE=on go install $1@latest
GO111MODULE=on go install \
-mod=readonly \
$1@latest
endef

define mkdir
Expand All @@ -31,12 +33,16 @@ endef
define proto-code-gen
protoc \
$(PROTO_PATHS:%=-I %) \
--go_out=$(GOPATH)/src --plugin protoc-gen-go="$(GOBIN)/protoc-gen-go" \
--go-vtproto_out=$(GOPATH)/src --plugin protoc-gen-go-vtproto="$(GOBIN)/protoc-gen-go-vtproto" \
--go-vtproto_opt=features=grpc+marshal+unmarshal+size+equal+clone \
--go_out=$(GOPATH)/src \
--plugin protoc-gen-go="$(GOBIN)/protoc-gen-go" \
--go-vtproto_out=$(GOPATH)/src \
--plugin protoc-gen-go-vtproto="$(GOBIN)/protoc-gen-go-vtproto" \
--go-vtproto_opt=features=grpc+marshal+unmarshal+size+equal+clone+pool \
--go-vtproto_opt=pool=$(ROOTDIR)/apis/proto/v1/payload.Object.Vector \
$1
endef
# --go-vtproto_opt=pool=$(ROOTDIR)/apis/proto/v1/payload.Object.Vector \
# --go-grpc_out=$(GOPATH)/src \
# --plugin protoc-gen-go-grpc="${GOBIN}/protoc-gen-go-grpc" \
# --go-vtproto_opt=pool=$(ROOTDIR)/apis/proto/v1/payload.Insert.MultiRequest \
# --go-vtproto_opt=pool=$(ROOTDIR)/apis/proto/v1/payload.Insert.Request \
# --go-vtproto_opt=pool=$(ROOTDIR)/apis/proto/v1/payload.Object.Vector \
Expand Down
33 changes: 32 additions & 1 deletion Makefile.d/proto.mk
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,30 @@ proto/deps: \
$(GOPATH)/src/github.com/planetscale/vtprotobuf \
$(GOPATH)/src/github.com/protocolbuffers/protobuf \
$(GOPATH)/src/google.golang.org/genproto \
$(GOPATH)/src/google.golang.org/protobuf
$(GOPATH)/src/google.golang.org/protobuf \
$(ROOTDIR)/apis/proto/v1/rpc/error_details.proto

.PHONY: proto/clean/deps
## uninstall all protobuf dependencies
proto/clean/deps:
rm -rf $(GOBIN)/protoc-gen-doc \
$(GOBIN)/protoc-gen-go \
$(GOBIN)/protoc-gen-go-grpc \
$(GOBIN)/protoc-gen-go-vtproto \
$(GOBIN)/protoc-gen-grpc-gateway \
$(GOBIN)/protoc-gen-swagger \
$(GOBIN)/protoc-gen-validate \
$(GOBIN)/prototool \
$(GOBIN)/swagger \
$(GOPATH)/src/github.com/envoyproxy/protoc-gen-validate \
$(GOPATH)/src/github.com/golang/protobuf \
$(GOPATH)/src/github.com/googleapis/googleapis \
$(GOPATH)/src/github.com/planetscale/vtprotobuf \
$(GOPATH)/src/github.com/protocolbuffers/protobuf \
$(GOPATH)/src/google.golang.org/genproto \
$(GOPATH)/src/google.golang.org/protobuf \
$(ROOTDIR)/apis/proto/v1/rpc/error_details.proto


$(GOPATH)/src/github.com/protocolbuffers/protobuf:
git clone \
Expand Down Expand Up @@ -129,6 +152,12 @@ $(GOBIN)/protoc-gen-go-vtproto:
$(GOBIN)/swagger:
$(call go-install, github.com/go-swagger/go-swagger/cmd/swagger)

$(ROOTDIR)/apis/proto/v1/rpc/error_details.proto:
curl -fsSL https://raw.githubusercontent.com/googleapis/googleapis/master/google/rpc/error_details.proto -o $(ROOTDIR)/apis/proto/v1/rpc/error_details.proto
sed -i -e "s/package google.rpc/package rpc.v1/" $(ROOTDIR)/apis/proto/v1/rpc/error_details.proto
sed -i -e "s%google.golang.org/genproto/googleapis/rpc/errdetails;errdetails%github.com/vdaas/vald/apis/grpc/v1/rpc/errdetails%" $(ROOTDIR)/apis/proto/v1/rpc/error_details.proto
sed -i -e "s/com.google.rpc/org.vdaas.vald.api.v1.rpc/" $(ROOTDIR)/apis/proto/v1/rpc/error_details.proto

$(PBGOS): \
$(PROTOS) \
proto/deps
Expand All @@ -139,6 +168,8 @@ $(PBGOS): \
find $(ROOTDIR)/apis/grpc/* -name '*.go' | xargs sed -i -E "s%google.golang.org/grpc/status%github.com/vdaas/vald/internal/net/grpc/status%g"
find $(ROOTDIR)/apis/grpc/* -name '*.go' | xargs sed -i -E "s%\"io\"%\"github.com/vdaas/vald/internal/io\"%g"
find $(ROOTDIR)/apis/grpc/* -name '*.go' | xargs sed -i -E "s%\"sync\"%\"github.com/vdaas/vald/internal/sync\"%g"
find $(ROOTDIR)/apis/grpc/* -name '*.go' | xargs sed -i -E "s/Vector = &Object_Vector\{\}/Vector = Object_VectorFromVTPool\(\)/g"
find $(ROOTDIR)/apis/grpc/* -name '*.go' | xargs sed -i -E "s/v := &Object_Vector\{\}/v := Object_VectorFromVTPool\(\)/g"

$(SWAGGERS): \
$(PROTOS) \
Expand Down
263 changes: 263 additions & 0 deletions apis/docs/v1/docs.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions apis/grpc/v1/filter/egress/egress_filter_vtproto.pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (c *filterClient) FilterDistance(ctx context.Context, in *payload.Object_Di
}

func (c *filterClient) FilterVector(ctx context.Context, in *payload.Object_Vector, opts ...grpc.CallOption) (*payload.Object_Vector, error) {
out := new(payload.Object_Vector)
out := payload.Object_VectorFromVTPool()
err := c.cc.Invoke(ctx, "/filter.egress.v1.Filter/FilterVector", in, out, opts...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -127,7 +127,7 @@ func _Filter_FilterDistance_Handler(srv interface{}, ctx context.Context, dec fu
}

func _Filter_FilterVector_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(payload.Object_Vector)
in := payload.Object_VectorFromVTPool()
if err := dec(in); err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions apis/grpc/v1/filter/ingress/ingress_filter_vtproto.pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewFilterClient(cc grpc.ClientConnInterface) FilterClient {
}

func (c *filterClient) GenVector(ctx context.Context, in *payload.Object_Blob, opts ...grpc.CallOption) (*payload.Object_Vector, error) {
out := new(payload.Object_Vector)
out := payload.Object_VectorFromVTPool()
err := c.cc.Invoke(ctx, "/filter.ingress.v1.Filter/GenVector", in, out, opts...)
if err != nil {
return nil, err
Expand All @@ -66,7 +66,7 @@ func (c *filterClient) GenVector(ctx context.Context, in *payload.Object_Blob, o
}

func (c *filterClient) FilterVector(ctx context.Context, in *payload.Object_Vector, opts ...grpc.CallOption) (*payload.Object_Vector, error) {
out := new(payload.Object_Vector)
out := payload.Object_VectorFromVTPool()
err := c.cc.Invoke(ctx, "/filter.ingress.v1.Filter/FilterVector", in, out, opts...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -127,7 +127,7 @@ func _Filter_GenVector_Handler(srv interface{}, ctx context.Context, dec func(in
}

func _Filter_FilterVector_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(payload.Object_Vector)
in := payload.Object_VectorFromVTPool()
if err := dec(in); err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 7f5b8ea

Please sign in to comment.