From 4b9eb5bfb30c90b8bec4b2bb03d610e1dd4bdfb2 Mon Sep 17 00:00:00 2001 From: Yashash H L Date: Mon, 24 Feb 2025 08:33:16 +0530 Subject: [PATCH] chore: add serve response type (#180) Signed-off-by: Yashash H L --- pkg/apis/proto/sink/v1/sink.pb.go | 33 ++++++++++++++++++------------- pkg/apis/proto/sink/v1/sink.proto | 1 + pkg/sinker/service.go | 6 ++++++ pkg/sinker/types.go | 7 +++++-- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/pkg/apis/proto/sink/v1/sink.pb.go b/pkg/apis/proto/sink/v1/sink.pb.go index ea2b3bb8..3565f541 100644 --- a/pkg/apis/proto/sink/v1/sink.pb.go +++ b/pkg/apis/proto/sink/v1/sink.pb.go @@ -29,6 +29,7 @@ const ( Status_SUCCESS Status = 0 Status_FAILURE Status = 1 Status_FALLBACK Status = 2 + Status_SERVE Status = 3 ) // Enum value maps for Status. @@ -37,11 +38,13 @@ var ( 0: "SUCCESS", 1: "FAILURE", 2: "FALLBACK", + 3: "SERVE", } Status_value = map[string]int32{ "SUCCESS": 0, "FAILURE": 1, "FALLBACK": 2, + "SERVE": 3, } ) @@ -451,6 +454,7 @@ type SinkResponse_Result struct { Status Status `protobuf:"varint,2,opt,name=status,proto3,enum=sink.v1.Status" json:"status,omitempty"` // err_msg is the error message, set it if success is set to false. ErrMsg string `protobuf:"bytes,3,opt,name=err_msg,json=errMsg,proto3" json:"err_msg,omitempty"` + ServeResponse []byte `protobuf:"bytes,4,opt,name=serve_response,json=serveResponse,proto3,oneof" json:"serve_response,omitempty"` } @@ -585,22 +589,23 @@ var file_pkg_apis_proto_sink_v1_sink_proto_rawDesc = []byte{ 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x88, 0x01, 0x01, 0x42, 0x11, 0x0a, 0x0f, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x5f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x0c, 0x0a, 0x0a, 0x5f, 0x68, 0x61, 0x6e, 0x64, 0x73, 0x68, 0x61, 0x6b, 0x65, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x73, - 0x74, 0x61, 0x74, 0x75, 0x73, 0x2a, 0x30, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x2a, 0x3b, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x46, 0x41, 0x49, 0x4c, 0x55, 0x52, 0x45, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x46, 0x41, 0x4c, - 0x4c, 0x42, 0x41, 0x43, 0x4b, 0x10, 0x02, 0x32, 0x7c, 0x0a, 0x04, 0x53, 0x69, 0x6e, 0x6b, 0x12, - 0x39, 0x0a, 0x06, 0x53, 0x69, 0x6e, 0x6b, 0x46, 0x6e, 0x12, 0x14, 0x2e, 0x73, 0x69, 0x6e, 0x6b, - 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x69, 0x6e, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x15, 0x2e, 0x73, 0x69, 0x6e, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x69, 0x6e, 0x6b, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01, 0x30, 0x01, 0x12, 0x39, 0x0a, 0x07, 0x49, 0x73, - 0x52, 0x65, 0x61, 0x64, 0x79, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, - 0x73, 0x69, 0x6e, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x79, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x38, 0x5a, 0x36, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, - 0x63, 0x6f, 0x6d, 0x2f, 0x6e, 0x75, 0x6d, 0x61, 0x70, 0x72, 0x6f, 0x6a, 0x2f, 0x6e, 0x75, 0x6d, - 0x61, 0x66, 0x6c, 0x6f, 0x77, 0x2d, 0x67, 0x6f, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x61, 0x70, 0x69, - 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x69, 0x6e, 0x6b, 0x2f, 0x76, 0x31, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x4c, 0x42, 0x41, 0x43, 0x4b, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x45, 0x52, 0x56, 0x45, + 0x10, 0x03, 0x32, 0x7c, 0x0a, 0x04, 0x53, 0x69, 0x6e, 0x6b, 0x12, 0x39, 0x0a, 0x06, 0x53, 0x69, + 0x6e, 0x6b, 0x46, 0x6e, 0x12, 0x14, 0x2e, 0x73, 0x69, 0x6e, 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x53, + 0x69, 0x6e, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x73, 0x69, 0x6e, + 0x6b, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x69, 0x6e, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x28, 0x01, 0x30, 0x01, 0x12, 0x39, 0x0a, 0x07, 0x49, 0x73, 0x52, 0x65, 0x61, 0x64, 0x79, + 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x16, 0x2e, 0x73, 0x69, 0x6e, 0x6b, 0x2e, + 0x76, 0x31, 0x2e, 0x52, 0x65, 0x61, 0x64, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x42, 0x38, 0x5a, 0x36, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6e, + 0x75, 0x6d, 0x61, 0x70, 0x72, 0x6f, 0x6a, 0x2f, 0x6e, 0x75, 0x6d, 0x61, 0x66, 0x6c, 0x6f, 0x77, + 0x2d, 0x67, 0x6f, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x61, 0x70, 0x69, 0x73, 0x2f, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2f, 0x73, 0x69, 0x6e, 0x6b, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( diff --git a/pkg/apis/proto/sink/v1/sink.proto b/pkg/apis/proto/sink/v1/sink.proto index 73e91314..535ae01e 100644 --- a/pkg/apis/proto/sink/v1/sink.proto +++ b/pkg/apis/proto/sink/v1/sink.proto @@ -66,6 +66,7 @@ enum Status { SUCCESS = 0; FAILURE = 1; FALLBACK = 2; + SERVE = 3; } /** diff --git a/pkg/sinker/service.go b/pkg/sinker/service.go index 161638ee..5affe6f7 100644 --- a/pkg/sinker/service.go +++ b/pkg/sinker/service.go @@ -223,6 +223,12 @@ func (fs *Service) processData(ctx context.Context, stream sinkpb.Sink_SinkFnSer Status: sinkpb.Status_SUCCESS, ServeResponse: msg.ServeResponse, }) + } else if msg.Serve { + resultList = append(resultList, &sinkpb.SinkResponse_Result{ + Id: msg.ID, + Status: sinkpb.Status_SERVE, + ServeResponse: msg.ServeResponse, + }) } else { resultList = append(resultList, &sinkpb.SinkResponse_Result{ Id: msg.ID, diff --git a/pkg/sinker/types.go b/pkg/sinker/types.go index 6d0e6dee..454fe50e 100644 --- a/pkg/sinker/types.go +++ b/pkg/sinker/types.go @@ -9,7 +9,10 @@ type Response struct { // Err represents the error message when "success" is false. Err string `json:"err,omitempty"` // Fallback is true if the message to be sent to the fallback sink. - Fallback bool `json:"fallback,omitempty"` + Fallback bool `json:"fallback,omitempty"` + // Serve is true if the message to be sent to serving store. + Serve bool `json:"serve,omitempty"` + // ServeResponse is the response that will be sent to the serving store. ServeResponse []byte `json:"serve_reponse,omitempty"` } @@ -50,5 +53,5 @@ func ResponseFallback(id string) Response { } func ResponseServe(id string, result []byte) Response { - return Response{ID: id, Success: true, ServeResponse: result} + return Response{ID: id, Serve: true, ServeResponse: result} }