diff --git a/logs/log.go b/logs/log.go index 2de45a30cd98bbd5ce840726b862dbca52fc8480..60f88d3a21869fef323c489af6e45858b3960124 100644 --- a/logs/log.go +++ b/logs/log.go @@ -27,17 +27,18 @@ func (l Level) String() string { } type Entry struct { - ID string `json:"id" bson:"_id" mapstructure:"id"` - Timestamp time.Time `json:"timestamp,omitempty" bson:"timestamp,omitempty" mapstructure:"timestamp,omitempty"` - Level Level `json:"level,omitempty" bson:"level,omitempty" mapstructure:"level,omitempty"` - Message string `json:"message,omitempty" bson:"message,omitempty" mapstructure:"message,omitempty"` - Category string `json:"category,omitempty" bson:"category,omitempty" mapstructure:"category,omitempty"` - Component string `json:"component,omitempty" bson:"component,omitempty" mapstructure:"component,omitempty"` - Event string `json:"event,omitempty" bson:"event,omitempty" mapstructure:"event,omitempty"` - ObjectID *id.ObjectId `json:"object_id,omitempty" bson:"object_id,omitempty" mapstructure:"object_id,omitempty"` - CallerID *id.ObjectId `json:"caller_id,omitempty" bson:"caller_id,omitempty" mapstructure:"caller_id,omitempty"` - Attr interface{} `json:"attr,omitempty" bson:"attr,omitempty" mapstructure:"attr,omitempty"` - Tags []string `json:"tags,omitempty" bson:"tags,omitempty" mapstructure:"tags,omitempty"` + ID string `json:"id" bson:"_id" mapstructure:"id"` + Timestamp time.Time `json:"timestamp,omitempty" bson:"timestamp,omitempty" mapstructure:"timestamp,omitempty"` + Level Level `json:"level,omitempty" bson:"level,omitempty" mapstructure:"level,omitempty"` + Message string `json:"message,omitempty" bson:"message,omitempty" mapstructure:"message,omitempty"` + Category string `json:"category,omitempty" bson:"category,omitempty" mapstructure:"category,omitempty"` + Component string `json:"component,omitempty" bson:"component,omitempty" mapstructure:"component,omitempty"` + Event string `json:"event,omitempty" bson:"event,omitempty" mapstructure:"event,omitempty"` + ObjectID *id.ObjectId `json:"object_id,omitempty" bson:"object_id,omitempty" mapstructure:"object_id,omitempty"` + CallerID *id.ObjectId `json:"caller_id,omitempty" bson:"caller_id,omitempty" mapstructure:"caller_id,omitempty"` + Attr interface{} `json:"attr,omitempty" bson:"attr,omitempty" mapstructure:"attr,omitempty"` + Tags []string `json:"tags,omitempty" bson:"tags,omitempty" mapstructure:"tags,omitempty"` + SearchScore float64 `json:"searchScore,omitempty" bson:"search_score,omitempty"` } //func convertInterfaceToAny(v interface{}) (*any.Any, error) { @@ -52,15 +53,16 @@ type Entry struct { func EntryToPB(entry *Entry) *pb.LogEntry { logEntry := &pb.LogEntry{ - Id: entry.ID, - Timestamp: timestamppb.New(entry.Timestamp), - Level: pb.LogLevel(entry.Level), - Message: entry.Message, - Category: entry.Category, - Component: entry.Component, - Event: entry.Event, - Attr: nil, //implement - Tags: entry.Tags, + Id: entry.ID, + Timestamp: timestamppb.New(entry.Timestamp), + Level: pb.LogLevel(entry.Level), + Message: entry.Message, + Category: entry.Category, + Component: entry.Component, + Event: entry.Event, + Attr: nil, //implement + Tags: entry.Tags, + SearchScore: entry.SearchScore, } if entry.ObjectID != nil { logEntry.ObjectId = entry.ObjectID.String() @@ -74,13 +76,14 @@ func EntryToPB(entry *Entry) *pb.LogEntry { func EntryFromPB(request *pb.LogEntry) *Entry { logEntry := &Entry{ - ID: request.Id, - Timestamp: request.Timestamp.AsTime(), - Level: Level(request.Level), - Message: request.Message, - Category: request.Category, - Component: request.Component, - Event: request.Event, + ID: request.Id, + Timestamp: request.Timestamp.AsTime(), + Level: Level(request.Level), + Message: request.Message, + Category: request.Category, + Component: request.Component, + Event: request.Event, + SearchScore: request.SearchScore, } if request.ObjectId != "" { diff --git a/logs/mocks/Service.go b/logs/mocks/Service.go index af4da73bc4d4c7b088fbfea7e7babc4c1ba30e36..0031c92c3b99e49348bf5c14c54a909f2e9736a7 100644 --- a/logs/mocks/Service.go +++ b/logs/mocks/Service.go @@ -5,7 +5,7 @@ package mocks import ( context "context" - log2 "git.perx.ru/perxis/perxis-go/logs" + logs "git.perx.ru/perxis/perxis-go/logs" mock "github.com/stretchr/testify/mock" options "git.perx.ru/perxis/perxis-go/pkg/options" @@ -17,7 +17,7 @@ type Service struct { } // Delete provides a mock function with given fields: ctx, filter -func (_m *Service) Delete(ctx context.Context, filter *log2.Filter) error { +func (_m *Service) Delete(ctx context.Context, filter *logs.Filter) error { ret := _m.Called(ctx, filter) if len(ret) == 0 { @@ -25,7 +25,7 @@ func (_m *Service) Delete(ctx context.Context, filter *log2.Filter) error { } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *log2.Filter) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *logs.Filter) error); ok { r0 = rf(ctx, filter) } else { r0 = ret.Error(0) @@ -35,27 +35,27 @@ func (_m *Service) Delete(ctx context.Context, filter *log2.Filter) error { } // Find provides a mock function with given fields: ctx, filter, _a2 -func (_m *Service) Find(ctx context.Context, filter *log2.Filter, _a2 *options.FindOptions) (*log2.FindResult, error) { +func (_m *Service) Find(ctx context.Context, filter *logs.Filter, _a2 *options.FindOptions) (*logs.FindResult, error) { ret := _m.Called(ctx, filter, _a2) if len(ret) == 0 { panic("no return value specified for Find") } - var r0 *log2.FindResult + var r0 *logs.FindResult var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *log2.Filter, *options.FindOptions) (*log2.FindResult, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, *logs.Filter, *options.FindOptions) (*logs.FindResult, error)); ok { return rf(ctx, filter, _a2) } - if rf, ok := ret.Get(0).(func(context.Context, *log2.Filter, *options.FindOptions) *log2.FindResult); ok { + if rf, ok := ret.Get(0).(func(context.Context, *logs.Filter, *options.FindOptions) *logs.FindResult); ok { r0 = rf(ctx, filter, _a2) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*log2.FindResult) + r0 = ret.Get(0).(*logs.FindResult) } } - if rf, ok := ret.Get(1).(func(context.Context, *log2.Filter, *options.FindOptions) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *logs.Filter, *options.FindOptions) error); ok { r1 = rf(ctx, filter, _a2) } else { r1 = ret.Error(1) @@ -65,7 +65,7 @@ func (_m *Service) Find(ctx context.Context, filter *log2.Filter, _a2 *options.F } // Log provides a mock function with given fields: ctx, entries -func (_m *Service) Log(ctx context.Context, entries []*log2.Entry) error { +func (_m *Service) Log(ctx context.Context, entries []*logs.Entry) error { ret := _m.Called(ctx, entries) if len(ret) == 0 { @@ -73,7 +73,7 @@ func (_m *Service) Log(ctx context.Context, entries []*log2.Entry) error { } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, []*log2.Entry) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, []*logs.Entry) error); ok { r0 = rf(ctx, entries) } else { r0 = ret.Error(0) diff --git a/logs/mocks/Storage.go b/logs/mocks/Storage.go index 87a6376d47ee44ece2f9d2458ee05e48a162b8ca..e341b0263c2570f508c4088ed1d9d2408b313e18 100644 --- a/logs/mocks/Storage.go +++ b/logs/mocks/Storage.go @@ -5,7 +5,7 @@ package mocks import ( context "context" - log2 "git.perx.ru/perxis/perxis-go/logs" + logs "git.perx.ru/perxis/perxis-go/logs" mock "github.com/stretchr/testify/mock" options "git.perx.ru/perxis/perxis-go/pkg/options" @@ -17,7 +17,7 @@ type Storage struct { } // Delete provides a mock function with given fields: ctx, filter -func (_m *Storage) Delete(ctx context.Context, filter *log2.Filter) error { +func (_m *Storage) Delete(ctx context.Context, filter *logs.Filter) error { ret := _m.Called(ctx, filter) if len(ret) == 0 { @@ -25,7 +25,7 @@ func (_m *Storage) Delete(ctx context.Context, filter *log2.Filter) error { } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *log2.Filter) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *logs.Filter) error); ok { r0 = rf(ctx, filter) } else { r0 = ret.Error(0) @@ -35,34 +35,34 @@ func (_m *Storage) Delete(ctx context.Context, filter *log2.Filter) error { } // Find provides a mock function with given fields: ctx, filter, _a2 -func (_m *Storage) Find(ctx context.Context, filter *log2.Filter, _a2 *options.FindOptions) ([]*log2.Entry, int, error) { +func (_m *Storage) Find(ctx context.Context, filter *logs.Filter, _a2 *options.FindOptions) ([]*logs.Entry, int, error) { ret := _m.Called(ctx, filter, _a2) if len(ret) == 0 { panic("no return value specified for Find") } - var r0 []*log2.Entry + var r0 []*logs.Entry var r1 int var r2 error - if rf, ok := ret.Get(0).(func(context.Context, *log2.Filter, *options.FindOptions) ([]*log2.Entry, int, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, *logs.Filter, *options.FindOptions) ([]*logs.Entry, int, error)); ok { return rf(ctx, filter, _a2) } - if rf, ok := ret.Get(0).(func(context.Context, *log2.Filter, *options.FindOptions) []*log2.Entry); ok { + if rf, ok := ret.Get(0).(func(context.Context, *logs.Filter, *options.FindOptions) []*logs.Entry); ok { r0 = rf(ctx, filter, _a2) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*log2.Entry) + r0 = ret.Get(0).([]*logs.Entry) } } - if rf, ok := ret.Get(1).(func(context.Context, *log2.Filter, *options.FindOptions) int); ok { + if rf, ok := ret.Get(1).(func(context.Context, *logs.Filter, *options.FindOptions) int); ok { r1 = rf(ctx, filter, _a2) } else { r1 = ret.Get(1).(int) } - if rf, ok := ret.Get(2).(func(context.Context, *log2.Filter, *options.FindOptions) error); ok { + if rf, ok := ret.Get(2).(func(context.Context, *logs.Filter, *options.FindOptions) error); ok { r2 = rf(ctx, filter, _a2) } else { r2 = ret.Error(2) @@ -90,7 +90,7 @@ func (_m *Storage) Init(ctx context.Context) error { } // Log provides a mock function with given fields: ctx, entry -func (_m *Storage) Log(ctx context.Context, entry []*log2.Entry) error { +func (_m *Storage) Log(ctx context.Context, entry []*logs.Entry) error { ret := _m.Called(ctx, entry) if len(ret) == 0 { @@ -98,7 +98,7 @@ func (_m *Storage) Log(ctx context.Context, entry []*log2.Entry) error { } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, []*log2.Entry) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, []*logs.Entry) error); ok { r0 = rf(ctx, entry) } else { r0 = ret.Error(0) diff --git a/proto/logs/log.pb.go b/proto/logs/log.pb.go index 8beabf96d64b409bc99ebf0b6e6ecb64b1ae4aa6..e1bbfd784e70ec2a8f0a4c5abee7edf258f41a1b 100644 --- a/proto/logs/log.pb.go +++ b/proto/logs/log.pb.go @@ -146,6 +146,8 @@ type LogEntry struct { Attr *anypb.Any `protobuf:"bytes,10,opt,name=attr,proto3" json:"attr,omitempty"` // tags содержит теги связанные с событием, на усмотрение сервиса Tags []string `protobuf:"bytes,11,rep,name=tags,proto3" json:"tags,omitempty"` + // релевантность элемента при полнотекстовом поиске + SearchScore float64 `protobuf:"fixed64,12,opt,name=search_score,json=searchScore,proto3" json:"search_score,omitempty"` } func (x *LogEntry) Reset() { @@ -257,6 +259,13 @@ func (x *LogEntry) GetTags() []string { return nil } +func (x *LogEntry) GetSearchScore() float64 { + if x != nil { + return x.SearchScore + } + return 0 +} + var File_logs_log_proto protoreflect.FileDescriptor var file_logs_log_proto_rawDesc = []byte{ @@ -266,7 +275,7 @@ var file_logs_log_proto_rawDesc = []byte{ 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x12, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x65, 0x72, 0x72, 0x6f, 0x72, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xdc, 0x02, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x45, 0x6e, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xff, 0x02, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x38, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, @@ -288,15 +297,17 @@ var file_logs_log_proto_rawDesc = []byte{ 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x61, 0x74, 0x74, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x61, 0x67, 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x09, 0x52, - 0x04, 0x74, 0x61, 0x67, 0x73, 0x2a, 0x45, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x4c, 0x65, 0x76, 0x65, - 0x6c, 0x12, 0x08, 0x0a, 0x04, 0x49, 0x4e, 0x46, 0x4f, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x57, - 0x41, 0x52, 0x4e, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x52, 0x52, 0x4f, - 0x52, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x43, 0x52, 0x49, 0x54, 0x49, 0x43, 0x41, 0x4c, 0x10, - 0x03, 0x12, 0x09, 0x0a, 0x05, 0x46, 0x41, 0x54, 0x41, 0x4c, 0x10, 0x04, 0x42, 0x2e, 0x5a, 0x2c, - 0x67, 0x69, 0x74, 0x2e, 0x70, 0x65, 0x72, 0x78, 0x2e, 0x72, 0x75, 0x2f, 0x70, 0x65, 0x72, 0x78, - 0x69, 0x73, 0x2f, 0x70, 0x65, 0x72, 0x78, 0x69, 0x73, 0x2d, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2f, 0x6c, 0x6f, 0x67, 0x73, 0x3b, 0x6c, 0x6f, 0x67, 0x73, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x04, 0x74, 0x61, 0x67, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, + 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x01, 0x52, 0x0b, 0x73, 0x65, 0x61, + 0x72, 0x63, 0x68, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x2a, 0x45, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x4c, + 0x65, 0x76, 0x65, 0x6c, 0x12, 0x08, 0x0a, 0x04, 0x49, 0x4e, 0x46, 0x4f, 0x10, 0x00, 0x12, 0x0b, + 0x0a, 0x07, 0x57, 0x41, 0x52, 0x4e, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x45, + 0x52, 0x52, 0x4f, 0x52, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x43, 0x52, 0x49, 0x54, 0x49, 0x43, + 0x41, 0x4c, 0x10, 0x03, 0x12, 0x09, 0x0a, 0x05, 0x46, 0x41, 0x54, 0x41, 0x4c, 0x10, 0x04, 0x42, + 0x2e, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x2e, 0x70, 0x65, 0x72, 0x78, 0x2e, 0x72, 0x75, 0x2f, 0x70, + 0x65, 0x72, 0x78, 0x69, 0x73, 0x2f, 0x70, 0x65, 0x72, 0x78, 0x69, 0x73, 0x2d, 0x67, 0x6f, 0x2f, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, 0x6f, 0x67, 0x73, 0x3b, 0x6c, 0x6f, 0x67, 0x73, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var (