diff --git a/events.proto b/events.proto index 3819834..0edb9e4 100644 --- a/events.proto +++ b/events.proto @@ -3,6 +3,8 @@ syntax = "proto3"; package workflow; +import "google/protobuf/timestamp.proto"; + option go_package = "./pb"; service events { @@ -13,11 +15,16 @@ service events { * Details that are captured as an event. */ message Event { - string ID = 1; // Event identifier - string Date = 2; // When the event occurred - string Type = 3; // What type of event occurred - string Source = 4; // The source of the event - string Details = 5; // Details related to the event + string ID = 1; // Event identifier + google.protobuf.Timestamp Timestamp = 2; // When the event occurred + enum EventType { + Normal = 0; // Default type is normal + Warning = 1; // The event was a warning + Error = 2; // The event was an error + } + EventType Type = 3; // What type of event it is (e.g., Warning, Normal) + string Reason = 4; // The reason for the event (e.g., BackupSucceeded, ShellProvisioned) + string Message = 5; // Message contains the specific information about the event } /** diff --git a/internal/server/mock/events/server.go b/internal/server/mock/events/server.go index e4215ae..c74d372 100644 --- a/internal/server/mock/events/server.go +++ b/internal/server/mock/events/server.go @@ -5,6 +5,8 @@ import ( "fmt" "time" + "google.golang.org/protobuf/types/known/timestamppb" + "github.com/skpr/api/pb" ) @@ -15,25 +17,25 @@ type Server struct { var mockEvents = []*pb.Event{ { - Date: time.Date(2025, 3, 1, 0, 0, 0, 0, time.UTC).Round(time.Minute).Format(time.RFC3339), - ID: "ABCD1234", - Type: "ShellEvent", - Source: "skpr-project-1", - Details: "Shell event triggered", + Timestamp: timestamppb.New(time.Date(2025, 3, 1, 0, 0, 0, 0, time.UTC).Round(time.Minute)), + ID: "ABCDXXXX", + Type: pb.Event_Normal, + Reason: "ConfigSet", + Message: "A config was set: api.key", }, { - Date: time.Date(2025, 2, 1, 0, 0, 0, 0, time.UTC).Round(time.Minute).Format(time.RFC3339), - ID: "ABCD1234", - Type: "ShellEvent", - Source: "skpr-project-1", - Details: "Shell event triggered", + Timestamp: timestamppb.New(time.Date(2025, 2, 1, 0, 0, 0, 0, time.UTC).Round(time.Minute)), + ID: "ABCDYYYY", + Type: pb.Event_Warning, + Reason: "ErrorRate", + Message: "Elevated error rate has been detected", }, { - Date: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC).Round(time.Minute).Format(time.RFC3339), - ID: "ABCD1234", - Type: "ShellEvent", - Source: "skpr-project-1", - Details: "Shell event triggered", + Timestamp: timestamppb.New(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC).Round(time.Minute)), + ID: "ABCDZZZZ", + Type: pb.Event_Error, + Reason: "BackupFailed", + Message: "The following backup failed with the ID: xxxxxxxxxxxxxxxxx", }, } @@ -42,7 +44,7 @@ func (s *Server) List(ctx context.Context, req *pb.EventsListRequest) (*pb.Event if req.Environment == "" { return nil, fmt.Errorf("environment not provided") } - + resp := &pb.EventsListResponse{ Events: mockEvents, } diff --git a/pb/events.pb.go b/pb/events.pb.go index 71ed655..a9e8958 100644 --- a/pb/events.pb.go +++ b/pb/events.pb.go @@ -11,6 +11,7 @@ package pb import ( protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" reflect "reflect" sync "sync" ) @@ -22,6 +23,55 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +type Event_EventType int32 + +const ( + Event_Normal Event_EventType = 0 // Default type is normal + Event_Warning Event_EventType = 1 // The event was a warning + Event_Error Event_EventType = 2 // The event was an error +) + +// Enum value maps for Event_EventType. +var ( + Event_EventType_name = map[int32]string{ + 0: "Normal", + 1: "Warning", + 2: "Error", + } + Event_EventType_value = map[string]int32{ + "Normal": 0, + "Warning": 1, + "Error": 2, + } +) + +func (x Event_EventType) Enum() *Event_EventType { + p := new(Event_EventType) + *p = x + return p +} + +func (x Event_EventType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (Event_EventType) Descriptor() protoreflect.EnumDescriptor { + return file_events_proto_enumTypes[0].Descriptor() +} + +func (Event_EventType) Type() protoreflect.EnumType { + return &file_events_proto_enumTypes[0] +} + +func (x Event_EventType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use Event_EventType.Descriptor instead. +func (Event_EventType) EnumDescriptor() ([]byte, []int) { + return file_events_proto_rawDescGZIP(), []int{0, 0} +} + // * // Details that are captured as an event. type Event struct { @@ -29,11 +79,11 @@ type Event struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ID string `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"` // Event identifier - Date string `protobuf:"bytes,2,opt,name=Date,proto3" json:"Date,omitempty"` // When the event occurred - Type string `protobuf:"bytes,3,opt,name=Type,proto3" json:"Type,omitempty"` // What type of event occurred - Source string `protobuf:"bytes,4,opt,name=Source,proto3" json:"Source,omitempty"` // The source of the event - Details string `protobuf:"bytes,5,opt,name=Details,proto3" json:"Details,omitempty"` // Details related to the event + ID string `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"` // Event identifier + Timestamp *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` // When the event occurred + Type Event_EventType `protobuf:"varint,3,opt,name=Type,proto3,enum=workflow.Event_EventType" json:"Type,omitempty"` // What type of event it is (e.g., Warning, Normal) + Reason string `protobuf:"bytes,4,opt,name=Reason,proto3" json:"Reason,omitempty"` // The reason for the event (e.g., BackupSucceeded, ShellProvisioned) + Message string `protobuf:"bytes,5,opt,name=Message,proto3" json:"Message,omitempty"` // Message contains the specific information about the event } func (x *Event) Reset() { @@ -75,30 +125,30 @@ func (x *Event) GetID() string { return "" } -func (x *Event) GetDate() string { +func (x *Event) GetTimestamp() *timestamppb.Timestamp { if x != nil { - return x.Date + return x.Timestamp } - return "" + return nil } -func (x *Event) GetType() string { +func (x *Event) GetType() Event_EventType { if x != nil { return x.Type } - return "" + return Event_Normal } -func (x *Event) GetSource() string { +func (x *Event) GetReason() string { if x != nil { - return x.Source + return x.Reason } return "" } -func (x *Event) GetDetails() string { +func (x *Event) GetMessage() string { if x != nil { - return x.Details + return x.Message } return "" } @@ -205,27 +255,37 @@ var File_events_proto protoreflect.FileDescriptor var file_events_proto_rawDesc = []byte{ 0x0a, 0x0c, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, - 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x22, 0x71, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, - 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x49, - 0x44, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x04, 0x44, 0x61, 0x74, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x53, 0x6f, 0x75, - 0x72, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x53, 0x6f, 0x75, 0x72, 0x63, - 0x65, 0x12, 0x18, 0x0a, 0x07, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x18, 0x05, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x07, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x22, 0x35, 0x0a, 0x11, 0x45, - 0x76, 0x65, 0x6e, 0x74, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x20, 0x0a, 0x0b, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, - 0x6e, 0x74, 0x22, 0x3d, 0x0a, 0x12, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x4c, 0x69, 0x73, 0x74, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x27, 0x0a, 0x06, 0x45, 0x76, 0x65, 0x6e, - 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x77, 0x6f, 0x72, 0x6b, 0x66, - 0x6c, 0x6f, 0x77, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x06, 0x45, 0x76, 0x65, 0x6e, 0x74, - 0x73, 0x32, 0x4d, 0x0a, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x43, 0x0a, 0x04, 0x4c, - 0x69, 0x73, 0x74, 0x12, 0x1b, 0x2e, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x2e, 0x45, - 0x76, 0x65, 0x6e, 0x74, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x1c, 0x2e, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x2e, 0x45, 0x76, 0x65, 0x6e, - 0x74, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, - 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, + 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xe3, 0x01, 0x0a, 0x05, 0x45, 0x76, + 0x65, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x02, 0x49, 0x44, 0x12, 0x38, 0x0a, 0x09, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, + 0x6d, 0x70, 0x52, 0x09, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x2d, 0x0a, + 0x04, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x19, 0x2e, 0x77, 0x6f, + 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x45, 0x76, 0x65, + 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, + 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x52, 0x65, + 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x2f, + 0x0a, 0x09, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0a, 0x0a, 0x06, 0x4e, + 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x57, 0x61, 0x72, 0x6e, 0x69, + 0x6e, 0x67, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x02, 0x22, + 0x35, 0x0a, 0x11, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, + 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x45, 0x6e, 0x76, 0x69, 0x72, + 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x3d, 0x0a, 0x12, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, + 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x27, 0x0a, 0x06, + 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x77, + 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x06, 0x45, + 0x76, 0x65, 0x6e, 0x74, 0x73, 0x32, 0x4d, 0x0a, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x12, + 0x43, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x1b, 0x2e, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, + 0x6f, 0x77, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x2e, + 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x00, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -240,21 +300,26 @@ func file_events_proto_rawDescGZIP() []byte { return file_events_proto_rawDescData } +var file_events_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_events_proto_msgTypes = make([]protoimpl.MessageInfo, 3) var file_events_proto_goTypes = []interface{}{ - (*Event)(nil), // 0: workflow.Event - (*EventsListRequest)(nil), // 1: workflow.EventsListRequest - (*EventsListResponse)(nil), // 2: workflow.EventsListResponse + (Event_EventType)(0), // 0: workflow.Event.EventType + (*Event)(nil), // 1: workflow.Event + (*EventsListRequest)(nil), // 2: workflow.EventsListRequest + (*EventsListResponse)(nil), // 3: workflow.EventsListResponse + (*timestamppb.Timestamp)(nil), // 4: google.protobuf.Timestamp } var file_events_proto_depIdxs = []int32{ - 0, // 0: workflow.EventsListResponse.Events:type_name -> workflow.Event - 1, // 1: workflow.events.List:input_type -> workflow.EventsListRequest - 2, // 2: workflow.events.List:output_type -> workflow.EventsListResponse - 2, // [2:3] is the sub-list for method output_type - 1, // [1:2] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name + 4, // 0: workflow.Event.Timestamp:type_name -> google.protobuf.Timestamp + 0, // 1: workflow.Event.Type:type_name -> workflow.Event.EventType + 1, // 2: workflow.EventsListResponse.Events:type_name -> workflow.Event + 2, // 3: workflow.events.List:input_type -> workflow.EventsListRequest + 3, // 4: workflow.events.List:output_type -> workflow.EventsListResponse + 4, // [4:5] is the sub-list for method output_type + 3, // [3:4] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name } func init() { file_events_proto_init() } @@ -305,13 +370,14 @@ func file_events_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_events_proto_rawDesc, - NumEnums: 0, + NumEnums: 1, NumMessages: 3, NumExtensions: 0, NumServices: 1, }, GoTypes: file_events_proto_goTypes, DependencyIndexes: file_events_proto_depIdxs, + EnumInfos: file_events_proto_enumTypes, MessageInfos: file_events_proto_msgTypes, }.Build() File_events_proto = out.File