diff --git a/pkg/beholder/pb/base_message.pb.go b/pkg/beholder/pb/base_message.pb.go index c9a69c3b0..773d2c873 100644 --- a/pkg/beholder/pb/base_message.pb.go +++ b/pkg/beholder/pb/base_message.pb.go @@ -7,6 +7,7 @@ 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" @@ -22,8 +23,7 @@ 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 adding use-case specific fields -// NOTE: do not compose protos for Beholder until INFOPLAT-1386 is completed +// BaseMessage directly or extend it by addding use-case specific fields 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 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"` + Labels *pb.Map `protobuf:"bytes,2,opt,name=labels,proto3" json:"labels,omitempty"` } func (x *BaseMessage) Reset() { @@ -74,7 +74,7 @@ func (x *BaseMessage) GetMsg() string { return "" } -func (x *BaseMessage) GetLabels() map[string]string { +func (x *BaseMessage) GetLabels() *pb.Map { if x != nil { return x.Labels } @@ -86,20 +86,17 @@ 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, 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, + 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, } var ( @@ -114,13 +111,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, 2) +var file_beholder_pb_base_message_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_beholder_pb_base_message_proto_goTypes = []interface{}{ (*BaseMessage)(nil), // 0: pb.BaseMessage - nil, // 1: pb.BaseMessage.LabelsEntry + (*pb.Map)(nil), // 1: values.Map } var file_beholder_pb_base_message_proto_depIdxs = []int32{ - 1, // 0: pb.BaseMessage.labels:type_name -> pb.BaseMessage.LabelsEntry + 1, // 0: pb.BaseMessage.labels:type_name -> values.Map 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 @@ -153,7 +150,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: 2, + NumMessages: 1, NumExtensions: 0, NumServices: 0, }, diff --git a/pkg/beholder/pb/base_message.proto b/pkg/beholder/pb/base_message.proto index 0913a77ee..3d39f8d7a 100644 --- a/pkg/beholder/pb/base_message.proto +++ b/pkg/beholder/pb/base_message.proto @@ -1,16 +1,17 @@ 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 adding use-case specific fields -// NOTE: do not compose protos for Beholder until INFOPLAT-1386 is completed +// BaseMessage directly or extend it by addding use-case specific fields 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 - map labels = 2; + values.Map labels = 2; } diff --git a/pkg/capabilities/events/events.go b/pkg/capabilities/events/events.go index 444f45705..bc74422c1 100644 --- a/pkg/capabilities/events/events.go +++ b/pkg/capabilities/events/events.go @@ -9,10 +9,11 @@ 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" @@ -166,27 +167,16 @@ func (e *Emitter) Emit(ctx context.Context, msg Message) error { return errors.New("must provide workflow name to emit event") } - // 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) + 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{ - // 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, + Labels: pm, + 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 258c4df89..67665e499 100644 --- a/pkg/custmsg/custom_message.go +++ b/pkg/custmsg/custom_message.go @@ -8,6 +8,7 @@ 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 { @@ -79,22 +80,21 @@ 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: labels, + Labels: values.ProtoMap(m), } payloadBytes, err := proto.Marshal(payload) if err != nil {