diff --git a/core/capabilities/beholder/client.go b/core/capabilities/beholder/client.go new file mode 100644 index 00000000000..b8e4ebda9a2 --- /dev/null +++ b/core/capabilities/beholder/client.go @@ -0,0 +1,55 @@ +package beholder + +import ( + "context" + "log" + "time" + + "google.golang.org/protobuf/proto" + + "github.com/smartcontractkit/chainlink-common/pkg/beholder" + "github.com/smartcontractkit/chainlink/v2/core/capabilities/beholder/pb" +) + +func init() { + +} + +func Emit(participant, role, model, component, event string) error { + beholderConfig := beholder.TestDefaultConfig() + // Bootstrap Beholder Client + client, err := beholder.NewClient(beholderConfig) + if err != nil { + log.Println(err.Error()) + } + + beholder.SetClient(client) + + tm := time.Now().Format("2006-01-02 15:04:05") + + // Define a custom protobuf payload to emit + payload := &pb.Event{ + Participant: participant, + Role: role, + Model: model, + Component: component, + Event: event, + Timestamp: tm, + } + payloadBytes, err := proto.Marshal(payload) + if err != nil { + return err + } + + return beholder.GetEmitter().Emit(context.Background(), payloadBytes, + "beholder_data_schema", "/event/versions/1", // required + "beholder_data_type", "custom_message", + "package_name", "capabilities_test", + "participant", participant, + "role", role, + "model", model, + "component", component, + "event", event, + "timestamp", tm, + ) +} diff --git a/core/capabilities/beholder/pb/event.pb.go b/core/capabilities/beholder/pb/event.pb.go new file mode 100644 index 00000000000..2e605a70ee8 --- /dev/null +++ b/core/capabilities/beholder/pb/event.pb.go @@ -0,0 +1,193 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v4.25.2 +// source: event.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Event struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Participant string `protobuf:"bytes,1,opt,name=participant,proto3" json:"participant,omitempty"` + Role string `protobuf:"bytes,2,opt,name=role,proto3" json:"role,omitempty"` + Model string `protobuf:"bytes,3,opt,name=model,proto3" json:"model,omitempty"` + Component string `protobuf:"bytes,4,opt,name=component,proto3" json:"component,omitempty"` + Event string `protobuf:"bytes,5,opt,name=event,proto3" json:"event,omitempty"` + Timestamp string `protobuf:"bytes,6,opt,name=timestamp,proto3" json:"timestamp,omitempty"` +} + +func (x *Event) Reset() { + *x = Event{} + if protoimpl.UnsafeEnabled { + mi := &file_event_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Event) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Event) ProtoMessage() {} + +func (x *Event) ProtoReflect() protoreflect.Message { + mi := &file_event_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Event.ProtoReflect.Descriptor instead. +func (*Event) Descriptor() ([]byte, []int) { + return file_event_proto_rawDescGZIP(), []int{0} +} + +func (x *Event) GetParticipant() string { + if x != nil { + return x.Participant + } + return "" +} + +func (x *Event) GetRole() string { + if x != nil { + return x.Role + } + return "" +} + +func (x *Event) GetModel() string { + if x != nil { + return x.Model + } + return "" +} + +func (x *Event) GetComponent() string { + if x != nil { + return x.Component + } + return "" +} + +func (x *Event) GetEvent() string { + if x != nil { + return x.Event + } + return "" +} + +func (x *Event) GetTimestamp() string { + if x != nil { + return x.Timestamp + } + return "" +} + +var File_event_proto protoreflect.FileDescriptor + +var file_event_proto_rawDesc = []byte{ + 0x0a, 0x0b, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, + 0x62, 0x22, 0xa5, 0x01, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x70, + 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x12, 0x12, 0x0a, + 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x72, 0x6f, 0x6c, + 0x65, 0x12, 0x14, 0x0a, 0x05, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6d, 0x70, 0x6f, + 0x6e, 0x65, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6f, 0x6d, 0x70, + 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x74, + 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, + 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x42, 0x45, 0x5a, 0x43, 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, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x63, 0x61, 0x70, 0x61, 0x62, 0x69, 0x6c, 0x69, + 0x74, 0x69, 0x65, 0x73, 0x2f, 0x62, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x2f, 0x70, 0x62, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_event_proto_rawDescOnce sync.Once + file_event_proto_rawDescData = file_event_proto_rawDesc +) + +func file_event_proto_rawDescGZIP() []byte { + file_event_proto_rawDescOnce.Do(func() { + file_event_proto_rawDescData = protoimpl.X.CompressGZIP(file_event_proto_rawDescData) + }) + return file_event_proto_rawDescData +} + +var file_event_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_event_proto_goTypes = []any{ + (*Event)(nil), // 0: pb.Event +} +var file_event_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_event_proto_init() } +func file_event_proto_init() { + if File_event_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_event_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*Event); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_event_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_event_proto_goTypes, + DependencyIndexes: file_event_proto_depIdxs, + MessageInfos: file_event_proto_msgTypes, + }.Build() + File_event_proto = out.File + file_event_proto_rawDesc = nil + file_event_proto_goTypes = nil + file_event_proto_depIdxs = nil +} diff --git a/core/capabilities/beholder/pb/event.proto b/core/capabilities/beholder/pb/event.proto new file mode 100644 index 00000000000..fabd70a9822 --- /dev/null +++ b/core/capabilities/beholder/pb/event.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +option go_package = "github.com/smartcontractkit/chainlink/core/capabilities/beholder/pb"; + +package pb; + +message Event { + string participant=1; + string role=2; + string model=3; + string component=4; + string event=5; + string timestamp=6; +} \ No newline at end of file diff --git a/core/capabilities/beholder/pb/generate.go b/core/capabilities/beholder/pb/generate.go new file mode 100644 index 00000000000..ffafffe440a --- /dev/null +++ b/core/capabilities/beholder/pb/generate.go @@ -0,0 +1,3 @@ +//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative event.proto + +package pb