From b772997e9a33a83a65a13ee192601610cf2782cf Mon Sep 17 00:00:00 2001 From: Patrick Date: Tue, 22 Oct 2024 13:55:31 -0700 Subject: [PATCH] removing values.Map from BaseMessage proto as Beholder only supports root level protos (#876) * removing values.Map from BaseMessage proto as Beholder only supports root level protos * fixing import * lint --- pkg/beholder/pb/base_message.pb.go | 41 ++++++++++++++++-------------- pkg/beholder/pb/base_message.proto | 7 +++-- pkg/capabilities/events/events.go | 30 ++++++++++++++-------- pkg/custmsg/custom_message.go | 20 +++++++-------- 4 files changed, 55 insertions(+), 43 deletions(-) diff --git a/pkg/beholder/pb/base_message.pb.go b/pkg/beholder/pb/base_message.pb.go index 773d2c873..c9a69c3b0 100644 --- a/pkg/beholder/pb/base_message.pb.go +++ b/pkg/beholder/pb/base_message.pb.go @@ -7,7 +7,6 @@ package pb import ( - pb "github.com/smartcontractkit/chainlink-common/pkg/values/pb" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -23,7 +22,8 @@ const ( // BaseMessage is a basic custom message, allowing the consumer to send // a string msg with some key-value pairs for labels. Consumers can consume -// BaseMessage directly or extend it by addding use-case specific fields +// BaseMessage directly or extend it by adding use-case specific fields +// NOTE: do not compose protos for Beholder until INFOPLAT-1386 is completed type BaseMessage struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -32,7 +32,7 @@ type BaseMessage struct { Msg string `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"` // https://protobuf.dev/programming-guides/proto3/#maps // In go: if Value is empty for a key, nothing will be serialized - Labels *pb.Map `protobuf:"bytes,2,opt,name=labels,proto3" json:"labels,omitempty"` + Labels map[string]string `protobuf:"bytes,2,rep,name=labels,proto3" json:"labels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (x *BaseMessage) Reset() { @@ -74,7 +74,7 @@ func (x *BaseMessage) GetMsg() string { return "" } -func (x *BaseMessage) GetLabels() *pb.Map { +func (x *BaseMessage) GetLabels() map[string]string { if x != nil { return x.Labels } @@ -86,17 +86,20 @@ var File_beholder_pb_base_message_proto protoreflect.FileDescriptor var file_beholder_pb_base_message_proto_rawDesc = []byte{ 0x0a, 0x1e, 0x62, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x2f, 0x70, 0x62, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x12, 0x02, 0x70, 0x62, 0x1a, 0x16, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x2f, 0x70, 0x62, 0x2f, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x44, 0x0a, 0x0b, - 0x42, 0x61, 0x73, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, - 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x23, 0x0a, - 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x2e, 0x4d, 0x61, 0x70, 0x52, 0x06, 0x6c, 0x61, 0x62, 0x65, - 0x6c, 0x73, 0x42, 0x3f, 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, - 0x2f, 0x73, 0x6d, 0x61, 0x72, 0x74, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x6b, 0x69, - 0x74, 0x2f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x2d, 0x63, 0x6f, 0x6d, 0x6d, - 0x6f, 0x6e, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x62, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x2f, - 0x70, 0x62, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x12, 0x02, 0x70, 0x62, 0x22, 0x8f, 0x01, 0x0a, 0x0b, 0x42, 0x61, 0x73, 0x65, 0x4d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x33, 0x0a, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, + 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x70, 0x62, 0x2e, 0x42, 0x61, 0x73, 0x65, + 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x45, 0x6e, + 0x74, 0x72, 0x79, 0x52, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x1a, 0x39, 0x0a, 0x0b, 0x4c, + 0x61, 0x62, 0x65, 0x6c, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x3f, 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x6d, 0x61, 0x72, 0x74, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, + 0x63, 0x74, 0x6b, 0x69, 0x74, 0x2f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x6c, 0x69, 0x6e, 0x6b, 0x2d, + 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x62, 0x65, 0x68, 0x6f, 0x6c, + 0x64, 0x65, 0x72, 0x2f, 0x70, 0x62, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -111,13 +114,13 @@ func file_beholder_pb_base_message_proto_rawDescGZIP() []byte { return file_beholder_pb_base_message_proto_rawDescData } -var file_beholder_pb_base_message_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_beholder_pb_base_message_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_beholder_pb_base_message_proto_goTypes = []interface{}{ (*BaseMessage)(nil), // 0: pb.BaseMessage - (*pb.Map)(nil), // 1: values.Map + nil, // 1: pb.BaseMessage.LabelsEntry } var file_beholder_pb_base_message_proto_depIdxs = []int32{ - 1, // 0: pb.BaseMessage.labels:type_name -> values.Map + 1, // 0: pb.BaseMessage.labels:type_name -> pb.BaseMessage.LabelsEntry 1, // [1:1] is the sub-list for method output_type 1, // [1:1] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name @@ -150,7 +153,7 @@ func file_beholder_pb_base_message_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_beholder_pb_base_message_proto_rawDesc, NumEnums: 0, - NumMessages: 1, + NumMessages: 2, NumExtensions: 0, NumServices: 0, }, diff --git a/pkg/beholder/pb/base_message.proto b/pkg/beholder/pb/base_message.proto index 3d39f8d7a..0913a77ee 100644 --- a/pkg/beholder/pb/base_message.proto +++ b/pkg/beholder/pb/base_message.proto @@ -1,17 +1,16 @@ syntax = "proto3"; -import "values/pb/values.proto"; - option go_package = "github.com/smartcontractkit/chainlink-common/pkg/beholder/pb/"; package pb; // BaseMessage is a basic custom message, allowing the consumer to send // a string msg with some key-value pairs for labels. Consumers can consume -// BaseMessage directly or extend it by addding use-case specific fields +// BaseMessage directly or extend it by adding use-case specific fields +// NOTE: do not compose protos for Beholder until INFOPLAT-1386 is completed message BaseMessage { string msg=1; // https://protobuf.dev/programming-guides/proto3/#maps // In go: if Value is empty for a key, nothing will be serialized - values.Map labels = 2; + map labels = 2; } diff --git a/pkg/capabilities/events/events.go b/pkg/capabilities/events/events.go index bc74422c1..444f45705 100644 --- a/pkg/capabilities/events/events.go +++ b/pkg/capabilities/events/events.go @@ -9,11 +9,10 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/beholder" "github.com/smartcontractkit/chainlink-common/pkg/beholder/pb" - "github.com/smartcontractkit/chainlink-common/pkg/values" ) +// Duplicates the attributes in beholder/message.go::Metadata const ( - // Duplicates the attributes in beholder/message.go::Metadata LabelWorkflowOwner = "workflow_owner_address" LabelWorkflowID = "workflow_id" LabelWorkflowExecutionID = "workflow_execution_id" @@ -167,16 +166,27 @@ func (e *Emitter) Emit(ctx context.Context, msg Message) error { return errors.New("must provide workflow name to emit event") } - wm, err := values.WrapMap(msg.Labels) - if err != nil { - return fmt.Errorf("could not wrap map: %w", err) - } - - pm := values.ProtoMap(wm) + // TODO un-comment after INFOPLAT-1386 + //wm, err := values.WrapMap(msg.Labels) + //if err != nil { + // return fmt.Errorf("could not wrap map: %w", err) + //} + // + //pm := values.ProtoMap(wm) bytes, err := proto.Marshal(&pb.BaseMessage{ - Labels: pm, - Msg: msg.Msg, + // any empty values will not be serialized (including the key) + Labels: map[string]string{ + LabelWorkflowID: nmd.WorkflowID, + LabelWorkflowName: nmd.WorkflowName, + LabelWorkflowOwner: nmd.WorkflowOwner, + LabelCapabilityContractAddress: nmd.CapabilityContractAddress, + LabelCapabilityID: nmd.CapabilityID, + LabelCapabilityVersion: nmd.CapabilityVersion, + LabelCapabilityName: nmd.CapabilityName, + LabelWorkflowExecutionID: nmd.WorkflowExecutionID, + }, + Msg: msg.Msg, }) if err != nil { return fmt.Errorf("could not marshal operational event: %w", err) diff --git a/pkg/custmsg/custom_message.go b/pkg/custmsg/custom_message.go index 67665e499..258c4df89 100644 --- a/pkg/custmsg/custom_message.go +++ b/pkg/custmsg/custom_message.go @@ -8,7 +8,6 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/beholder" "github.com/smartcontractkit/chainlink-common/pkg/beholder/pb" - "github.com/smartcontractkit/chainlink-common/pkg/values" ) type Labeler struct { @@ -80,21 +79,22 @@ func (l Labeler) SendLogAsCustomMessage(msg string) error { } func sendLogAsCustomMessageW(msg string, labels map[string]string) error { + // TODO un-comment after INFOPLAT-1386 // cast to map[string]any - newLabels := map[string]any{} - for k, v := range labels { - newLabels[k] = v - } + //newLabels := map[string]any{} + //for k, v := range labels { + // newLabels[k] = v + //} - m, err := values.NewMap(newLabels) - if err != nil { - return fmt.Errorf("could not wrap labels to map: %w", err) - } + //m, err := values.NewMap(newLabels) + //if err != nil { + // return fmt.Errorf("could not wrap labels to map: %w", err) + //} // Define a custom protobuf payload to emit payload := &pb.BaseMessage{ Msg: msg, - Labels: values.ProtoMap(m), + Labels: labels, } payloadBytes, err := proto.Marshal(payload) if err != nil {