Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/go-json-experiment/json v0.0.0-20231102232822-2e55bd4e08b0
github.com/go-playground/validator/v10 v10.4.1
github.com/go-viper/mapstructure/v2 v2.2.1
github.com/golang/protobuf v1.5.4
github.com/google/go-cmp v0.7.0
github.com/google/uuid v1.6.0
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
Expand Down Expand Up @@ -85,7 +86,6 @@ require (
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/goccy/go-yaml v1.12.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/flatbuffers v24.3.25+incompatible // indirect
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect
Expand Down
15 changes: 9 additions & 6 deletions pkg/custmsg/custom_message.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package custmsg

import (
"bytes"
"context"
"fmt"
"maps"

"google.golang.org/protobuf/proto"

"github.com/golang/protobuf/jsonpb"
"github.com/smartcontractkit/chainlink-common/pkg/beholder"
"github.com/smartcontractkit/chainlink-common/pkg/beholder/pb"
)
Expand Down Expand Up @@ -99,18 +99,21 @@ func sendLogAsCustomMessageW(ctx context.Context, msg string, labels map[string]
//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,
}
payloadBytes, err := proto.Marshal(payload)

// We marshal to JSON so we can read these messages in Loki
marshaler := &jsonpb.Marshaler{}
var buf bytes.Buffer
err := marshaler.Marshal(&buf, payload)
if err != nil {
return fmt.Errorf("sending custom message failed to marshal protobuf: %w", err)
return fmt.Errorf("sending custom message failed to marshal to JSON: %w", err)
}

err = beholder.GetEmitter().Emit(ctx, payloadBytes,
err = beholder.GetEmitter().Emit(ctx, buf.Bytes(),
"beholder_data_schema", "/beholder-base-message/versions/1", // required
"beholder_domain", "platform", // required
"beholder_entity", "BaseMessage", // required
Expand Down
Loading