Skip to content

Commit

Permalink
removing values.Map from BaseMessage proto as Beholder only supports …
Browse files Browse the repository at this point in the history
…root level protos (#876)

* removing values.Map from BaseMessage proto as Beholder only supports root level protos

* fixing import

* lint
  • Loading branch information
patrickhuie19 authored Oct 22, 2024
1 parent 8b1c952 commit b772997
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 43 deletions.
41 changes: 22 additions & 19 deletions pkg/beholder/pb/base_message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions pkg/beholder/pb/base_message.proto
Original file line number Diff line number Diff line change
@@ -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<string, string> labels = 2;
}
30 changes: 20 additions & 10 deletions pkg/capabilities/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions pkg/custmsg/custom_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b772997

Please sign in to comment.