Skip to content
Snippets Groups Projects
Commit 99149cd6 authored by Pavel Antonov's avatar Pavel Antonov :asterisk:
Browse files

Merge branch 'feature/PRXS-1896-LogSDKUpd' into 'feature/PRXS-951-Log'

Внесены изменения в Log-SDK, перегенерированны grpc-клиенты после обновления proto

See merge request perxis/perxis-go!150
parents 9fa57aa9 d605c937
No related branches found
No related tags found
No related merge requests found
package log package log
import ( import (
"maps"
"time" "time"
"git.perx.ru/perxis/perxis-go/id"
pb "git.perx.ru/perxis/perxis-go/proto/log" pb "git.perx.ru/perxis/perxis-go/proto/log"
"github.com/mitchellh/mapstructure"
"google.golang.org/protobuf/types/known/timestamppb" "google.golang.org/protobuf/types/known/timestamppb"
) )
...@@ -34,8 +35,8 @@ type Entry struct { ...@@ -34,8 +35,8 @@ type Entry struct {
Category string `json:"category,omitempty" bson:"category,omitempty" mapstructure:"category,omitempty"` Category string `json:"category,omitempty" bson:"category,omitempty" mapstructure:"category,omitempty"`
Component string `json:"component,omitempty" bson:"component,omitempty" mapstructure:"component,omitempty"` Component string `json:"component,omitempty" bson:"component,omitempty" mapstructure:"component,omitempty"`
Event string `json:"event,omitempty" bson:"event,omitempty" mapstructure:"event,omitempty"` Event string `json:"event,omitempty" bson:"event,omitempty" mapstructure:"event,omitempty"`
Object string `json:"object,omitempty" bson:"object,omitempty" mapstructure:"object,omitempty"` ObjectID *id.ID `json:"object_id,omitempty" bson:"object_id,omitempty" mapstructure:"object_id,omitempty"`
Caller string `json:"caller,omitempty" bson:"caller,omitempty" mapstructure:"caller,omitempty"` CallerID *id.ID `json:"caller_id,omitempty" bson:"caller_id,omitempty" mapstructure:"caller_id,omitempty"`
Attr interface{} `json:"attr,omitempty" bson:"attr,omitempty" mapstructure:"attr,omitempty"` Attr interface{} `json:"attr,omitempty" bson:"attr,omitempty" mapstructure:"attr,omitempty"`
Tags []string `json:"tags,omitempty" bson:"tags,omitempty" mapstructure:"tags,omitempty"` Tags []string `json:"tags,omitempty" bson:"tags,omitempty" mapstructure:"tags,omitempty"`
} }
...@@ -59,16 +60,21 @@ func EntryToPB(entry *Entry) *pb.LogEntry { ...@@ -59,16 +60,21 @@ func EntryToPB(entry *Entry) *pb.LogEntry {
Category: entry.Category, Category: entry.Category,
Component: entry.Component, Component: entry.Component,
Event: entry.Event, Event: entry.Event,
Object: entry.Object,
Caller: entry.Caller,
Attr: nil, //implement Attr: nil, //implement
Tags: entry.Tags, Tags: entry.Tags,
} }
if entry.ObjectID != nil {
logEntry.ObjectId = entry.ObjectID.String()
}
if entry.CallerID != nil {
logEntry.CallerId = entry.CallerID.String()
}
return logEntry return logEntry
} }
func EntryFromPB(request *pb.LogEntry) *Entry { func EntryFromPB(request *pb.LogEntry) *Entry {
return &Entry{ logEntry := &Entry{
ID: request.Id, ID: request.Id,
Timestamp: request.Timestamp.AsTime(), Timestamp: request.Timestamp.AsTime(),
LogLevel: Level(request.Level), LogLevel: Level(request.Level),
...@@ -76,15 +82,46 @@ func EntryFromPB(request *pb.LogEntry) *Entry { ...@@ -76,15 +82,46 @@ func EntryFromPB(request *pb.LogEntry) *Entry {
Category: request.Category, Category: request.Category,
Component: request.Component, Component: request.Component,
Event: request.Event, Event: request.Event,
Object: request.Object,
Caller: request.Caller,
Attr: request.Attr, // todo: как с этим работать?
Tags: request.Tags,
} }
if request.ObjectId != "" {
logEntry.ObjectID, _ = id.Parse(request.ObjectId)
}
if request.CallerId != "" {
logEntry.CallerID, _ = id.Parse(request.CallerId)
}
if request.Attr != nil {
logEntry.Attr = request.Attr // todo: как с этим работать?
}
if request.Tags != nil {
logEntry.Tags = request.Tags
} }
func (e *Entry) ToMap() map[string]interface{} { return logEntry
res := make(map[string]interface{}) }
_ = mapstructure.Decode(e, &res)
func (e *Entry) ToMap() map[string]any {
res := map[string]any{
"id": e.ID,
"timestamp": e.Timestamp,
"log_level": e.LogLevel,
"message": e.Message,
"category": e.Category,
"component": e.Component,
"event": e.Event,
}
if e.ObjectID != nil {
res["object_id"] = e.ObjectID.String()
maps.Copy(res, e.ObjectID.ToMap())
}
if e.CallerID != nil {
res["caller_id"] = e.CallerID.String()
}
if e.Attr != nil {
res["attr"] = e.Attr
}
if e.Tags != nil {
res["tags"] = e.Tags
}
return res return res
} }
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"testing" "testing"
"time" "time"
"git.perx.ru/perxis/perxis-go/id"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
...@@ -16,8 +17,8 @@ func TestEntry_ToMap(t *testing.T) { ...@@ -16,8 +17,8 @@ func TestEntry_ToMap(t *testing.T) {
Category string Category string
Component string Component string
Event string Event string
Object string ObjectId *id.ID
Caller string CallerId *id.ID
Attr interface{} Attr interface{}
Tags []string Tags []string
} }
...@@ -29,19 +30,19 @@ func TestEntry_ToMap(t *testing.T) { ...@@ -29,19 +30,19 @@ func TestEntry_ToMap(t *testing.T) {
{ {
"#1", "#1",
fields{ fields{
ID: "1", "1",
Timestamp: time.Time{}, time.Time{},
Message: "message", 0,
Object: "/spaces/<space_id>/envs/<env_id>", "message",
Caller: "/users/<user_id>", "",
}, "",
map[string]interface{}{ "",
"id": "1", id.NewEnvironmentID("<space_id>", "<env_id>"),
"timestamp": map[string]interface{}{}, id.NewUserID("<user_id>"),
"message": "message", nil,
"object": "/spaces/<space_id>/envs/<env_id>", nil,
"caller": "/users/<user_id>",
}, },
map[string]interface{}{"caller_id": "/users/<user_id>", "category": "", "component": "", "event": "", "id": "1", "log_level": Level(0), "message": "message", "object_id": "/spaces/<space_id>/envs/<env_id>", "timestamp": time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)},
}, },
} }
for _, tt := range tests { for _, tt := range tests {
...@@ -54,12 +55,12 @@ func TestEntry_ToMap(t *testing.T) { ...@@ -54,12 +55,12 @@ func TestEntry_ToMap(t *testing.T) {
Category: tt.fields.Category, Category: tt.fields.Category,
Component: tt.fields.Component, Component: tt.fields.Component,
Event: tt.fields.Event, Event: tt.fields.Event,
Object: tt.fields.Object, ObjectID: tt.fields.ObjectId,
Caller: tt.fields.Caller, CallerID: tt.fields.CallerId,
Attr: tt.fields.Attr, Attr: tt.fields.Attr,
Tags: tt.fields.Tags, Tags: tt.fields.Tags,
} }
assert.Equal(t, e.ToMap(), tt.want) assert.Equal(t, tt.want, e.ToMap())
}) })
} }
} }
Subproject commit 63410745d6008eaa9d9b00626b5f5b6891ac9189 Subproject commit 78fe6a1ea7e2fe588e4107bf14ac85293b201163
...@@ -133,14 +133,14 @@ type LogEntry struct { ...@@ -133,14 +133,14 @@ type LogEntry struct {
// /orgs/<org_id> - организация // /orgs/<org_id> - организация
// /users/<user_id> - пользователь // /users/<user_id> - пользователь
// /services/<service_id> - сервис // /services/<service_id> - сервис
Object string `protobuf:"bytes,8,opt,name=object,proto3" json:"object,omitempty"` ObjectId string `protobuf:"bytes,8,opt,name=object_id,json=objectId,proto3" json:"object_id,omitempty"`
// caller содержит идентификатор сущности вызвавшей событиe, аналогично полю object // caller содержит идентификатор сущности вызвавшей событиe, аналогично полю object
// //
// Примеры: // Примеры:
// /users/<user_id> - пользователь // /users/<user_id> - пользователь
// /spaces/<space_id>/clients/<client_id> - клиент // /spaces/<space_id>/clients/<client_id> - клиент
// /services/<service_id> - сервис // /services/<service_id> - сервис
Caller string `protobuf:"bytes,9,opt,name=caller,proto3" json:"caller,omitempty"` CallerId string `protobuf:"bytes,9,opt,name=caller_id,json=callerId,proto3" json:"caller_id,omitempty"`
// attr содержит дополнительные связанные с событием атрибуты в формате Any // attr содержит дополнительные связанные с событием атрибуты в формате Any
// позволяет добавить дополнительные данные в событие // позволяет добавить дополнительные данные в событие
Attr *anypb.Any `protobuf:"bytes,10,opt,name=attr,proto3" json:"attr,omitempty"` Attr *anypb.Any `protobuf:"bytes,10,opt,name=attr,proto3" json:"attr,omitempty"`
...@@ -229,16 +229,16 @@ func (x *LogEntry) GetEvent() string { ...@@ -229,16 +229,16 @@ func (x *LogEntry) GetEvent() string {
return "" return ""
} }
func (x *LogEntry) GetObject() string { func (x *LogEntry) GetObjectId() string {
if x != nil { if x != nil {
return x.Object return x.ObjectId
} }
return "" return ""
} }
func (x *LogEntry) GetCaller() string { func (x *LogEntry) GetCallerId() string {
if x != nil { if x != nil {
return x.Caller return x.CallerId
} }
return "" return ""
} }
...@@ -266,7 +266,7 @@ var file_log_log_proto_rawDesc = []byte{ ...@@ -266,7 +266,7 @@ var file_log_log_proto_rawDesc = []byte{
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x19, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 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, 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, 0x1a, 0x12, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd1, 0x02, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xdb, 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, 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, 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, 0x70, 0x72, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72,
...@@ -280,22 +280,22 @@ var file_log_log_proto_rawDesc = []byte{ ...@@ -280,22 +280,22 @@ var file_log_log_proto_rawDesc = []byte{
0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e,
0x65, 0x6e, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x65, 0x6e, 0x74, 0x18, 0x06, 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, 0x07, 0x20, 0x6e, 0x65, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x07, 0x20,
0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x62, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x6f, 0x62,
0x6a, 0x65, 0x63, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x62, 0x6a, 0x65, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6f,
0x63, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x61, 0x6c, 0x6c, 0x65,
0x28, 0x09, 0x52, 0x06, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x72, 0x12, 0x28, 0x0a, 0x04, 0x61, 0x74, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x61, 0x6c, 0x6c,
0x74, 0x72, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x72, 0x49, 0x64, 0x12, 0x28, 0x0a, 0x04, 0x61, 0x74, 0x74, 0x72, 0x18, 0x0a, 0x20, 0x01,
0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x61, 0x74, 0x74, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x61, 0x67, 0x73, 0x18, 0x0b, 0x20, 0x03, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x61, 0x74, 0x74, 0x72, 0x12, 0x12,
0x28, 0x09, 0x52, 0x04, 0x74, 0x61, 0x67, 0x73, 0x2a, 0x45, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x4c, 0x0a, 0x04, 0x74, 0x61, 0x67, 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x74, 0x61,
0x65, 0x76, 0x65, 0x6c, 0x12, 0x08, 0x0a, 0x04, 0x49, 0x4e, 0x46, 0x4f, 0x10, 0x00, 0x12, 0x0b, 0x67, 0x73, 0x2a, 0x45, 0x0a, 0x08, 0x4c, 0x6f, 0x67, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x08,
0x0a, 0x07, 0x57, 0x41, 0x52, 0x4e, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x0a, 0x04, 0x49, 0x4e, 0x46, 0x4f, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x57, 0x41, 0x52, 0x4e,
0x52, 0x52, 0x4f, 0x52, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x43, 0x52, 0x49, 0x54, 0x49, 0x43, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x02,
0x41, 0x4c, 0x10, 0x03, 0x12, 0x09, 0x0a, 0x05, 0x46, 0x41, 0x54, 0x41, 0x4c, 0x10, 0x04, 0x42, 0x12, 0x0c, 0x0a, 0x08, 0x43, 0x52, 0x49, 0x54, 0x49, 0x43, 0x41, 0x4c, 0x10, 0x03, 0x12, 0x09,
0x2c, 0x5a, 0x2a, 0x67, 0x69, 0x74, 0x2e, 0x70, 0x65, 0x72, 0x78, 0x2e, 0x72, 0x75, 0x2f, 0x70, 0x0a, 0x05, 0x46, 0x41, 0x54, 0x41, 0x4c, 0x10, 0x04, 0x42, 0x2c, 0x5a, 0x2a, 0x67, 0x69, 0x74,
0x65, 0x72, 0x78, 0x69, 0x73, 0x2f, 0x70, 0x65, 0x72, 0x78, 0x69, 0x73, 0x2d, 0x67, 0x6f, 0x2f, 0x2e, 0x70, 0x65, 0x72, 0x78, 0x2e, 0x72, 0x75, 0x2f, 0x70, 0x65, 0x72, 0x78, 0x69, 0x73, 0x2f,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6c, 0x6f, 0x67, 0x3b, 0x6c, 0x6f, 0x67, 0x62, 0x06, 0x70, 0x70, 0x65, 0x72, 0x78, 0x69, 0x73, 0x2d, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f,
0x72, 0x6f, 0x74, 0x6f, 0x33, 0x6c, 0x6f, 0x67, 0x3b, 0x6c, 0x6f, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment