Skip to content

Commit

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

This reverts commit b772997.
  • Loading branch information
patrickhuie19 authored Oct 23, 2024
1 parent 84d3ef9 commit c5c856e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 55 deletions.
41 changes: 19 additions & 22 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: 4 additions & 3 deletions pkg/beholder/pb/base_message.proto
Original file line number Diff line number Diff line change
@@ -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<string, string> labels = 2;
values.Map labels = 2;
}
30 changes: 10 additions & 20 deletions pkg/capabilities/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
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,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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c5c856e

Please sign in to comment.