Skip to content

Commit

Permalink
添加创建时间字段
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Dec 29, 2023
1 parent 8ede227 commit dfd2c71
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
19 changes: 19 additions & 0 deletions driver/clickhouse/saveTraceContextConsumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/farseer-go/fs/trace"
"github.com/farseer-go/linkTrace"
"github.com/farseer-go/mapper"
"time"
)

// 写入到clickhouse
Expand All @@ -29,6 +30,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
exceptionStackPO := mapper.Single[ExceptionStackPO](traceContext.Exception)
po.Exception = &exceptionStackPO
}
po.UseDesc = po.UseTs.String()
po.CreateAt = time.UnixMicro(po.StartTs)
lstTraceContext.Add(po)

// 明细
Expand All @@ -41,6 +44,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
if !detailType.Exception.IsNil() {
databasePO.Exception = &detailType.Exception
}
databasePO.UseDesc = databasePO.UseTs.String()
databasePO.CreateAt = time.UnixMicro(databasePO.StartTs)
lstTraceDetailDatabase.Add(databasePO)
case *linkTrace.TraceDetailEs:
esPO := mapper.Single[TraceDetailEsPO](*detailType)
Expand All @@ -49,6 +54,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
if !detailType.Exception.IsNil() {
esPO.Exception = &detailType.Exception
}
esPO.UseDesc = esPO.UseTs.String()
esPO.CreateAt = time.UnixMicro(esPO.StartTs)
lstTraceDetailEs.Add(esPO)
case *linkTrace.TraceDetailEtcd:
etcdPO := mapper.Single[TraceDetailEtcdPO](*detailType)
Expand All @@ -57,6 +64,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
if !detailType.Exception.IsNil() {
etcdPO.Exception = &detailType.Exception
}
etcdPO.UseDesc = etcdPO.UseTs.String()
etcdPO.CreateAt = time.UnixMicro(etcdPO.StartTs)
lstTraceDetailEtcd.Add(etcdPO)
case *linkTrace.TraceDetailHand:
handPO := mapper.Single[TraceDetailHandPO](*detailType)
Expand All @@ -65,6 +74,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
if !detailType.Exception.IsNil() {
handPO.Exception = &detailType.Exception
}
handPO.UseDesc = handPO.UseTs.String()
handPO.CreateAt = time.UnixMicro(handPO.StartTs)
lstTraceDetailHand.Add(handPO)
case *linkTrace.TraceDetailHttp:
httpPO := mapper.Single[TraceDetailHttpPO](*detailType)
Expand All @@ -73,6 +84,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
if !detailType.Exception.IsNil() {
httpPO.Exception = &detailType.Exception
}
httpPO.UseDesc = httpPO.UseTs.String()
httpPO.CreateAt = time.UnixMicro(httpPO.StartTs)
lstTraceDetailHttp.Add(httpPO)
case *linkTrace.TraceDetailGrpc:
grpcPO := mapper.Single[TraceDetailGrpcPO](*detailType)
Expand All @@ -81,6 +94,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
if !detailType.Exception.IsNil() {
grpcPO.Exception = &detailType.Exception
}
grpcPO.UseDesc = grpcPO.UseTs.String()
grpcPO.CreateAt = time.UnixMicro(grpcPO.StartTs)
lstTraceDetailGrpc.Add(grpcPO)
case *linkTrace.TraceDetailMq:
mqPO := mapper.Single[TraceDetailMqPO](*detailType)
Expand All @@ -89,6 +104,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
if !detailType.Exception.IsNil() {
mqPO.Exception = &detailType.Exception
}
mqPO.UseDesc = mqPO.UseTs.String()
mqPO.CreateAt = time.UnixMicro(mqPO.StartTs)
lstTraceDetailMq.Add(mqPO)
case *linkTrace.TraceDetailRedis:
redisPO := mapper.Single[TraceDetailRedisPO](*detailType)
Expand All @@ -97,6 +114,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
if !detailType.Exception.IsNil() {
redisPO.Exception = &detailType.Exception
}
redisPO.UseDesc = redisPO.UseTs.String()
redisPO.CreateAt = time.UnixMicro(redisPO.StartTs)
lstTraceDetailRedis.Add(redisPO)
}
}
Expand Down
7 changes: 4 additions & 3 deletions driver/clickhouse/traceContextPO.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ type TraceContextPO struct {
AppIp string `gorm:"not null;default:'';comment:应用IP"`
ParentAppName string `gorm:"not null;default:'';comment:上游应用"`
StartTs int64 `gorm:"not null;default:0;comment:调用开始时间戳(微秒)"`
EndTs int64 `gorm:"not null;default:0;comment:调用结束时间戳"`
UseTs time.Duration `gorm:"not null;default:0;comment:总共使用时间微秒"`
UseDesc string `gorm:"-"`
EndTs int64 `gorm:"not null;default:0;comment:调用结束时间戳(微秒)"`
UseTs time.Duration `gorm:"not null;default:0;comment:总共使用时间(微秒)"`
UseDesc string `gorm:"not null;default:'';comment:总共使用时间(描述)"`
TraceType eumTraceType.Enum `gorm:"not null;comment:入口类型"`
Exception *ExceptionStackPO `gorm:"json;not null;comment:异常信息"`
List []any `gorm:"json;not null;comment:调用的上下文"`
WebContextPO `gorm:"embedded;not null;comment:Web请求上下文"`
ConsumerContextPO `gorm:"embedded;not null;comment:消费上下文"`
TaskContextPO `gorm:"embedded;not null;comment:任务上下文"`
WatchKeyContextPO `gorm:"embedded;not null;comment:Etcd上下文"`
CreateAt time.Time `gorm:"type:DateTime64(3);not null;comment:请求时间"`
}

type WebContextPO struct {
Expand Down
3 changes: 2 additions & 1 deletion driver/clickhouse/traceDetailPO.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ type BaseTraceDetailPO struct {
StartTs int64 `gorm:"not null;default:0;comment:调用开始时间戳(微秒)"`
EndTs int64 `gorm:"not null;default:0;comment:调用停止时间戳(微秒)"`
UseTs time.Duration `gorm:"not null;default:0;comment:总共使用时间微秒"`
UseDesc string `gorm:"-"`
UseDesc string `gorm:"not null;default:'';comment:总共使用时间(描述)"`
Exception *trace.ExceptionStack `gorm:"json;not null;comment:异常信息"`
MethodName string `gorm:"not null;default:'';comment:调用方法"`
CreateAt time.Time `gorm:"type:DateTime64(3);not null;comment:请求时间"`
}

type TraceDetailDatabasePO struct {
Expand Down
19 changes: 19 additions & 0 deletions driver/elasticSearch/saveTraceContextConsumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/farseer-go/fs/trace"
"github.com/farseer-go/linkTrace"
"github.com/farseer-go/mapper"
"time"
)

// 写入到ES
Expand All @@ -29,6 +30,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
exceptionStackPO := mapper.Single[ExceptionStackPO](traceContext.Exception)
po.Exception = &exceptionStackPO
}
po.UseDesc = po.UseTs.String()
po.CreateAt = time.UnixMicro(po.StartTs)
lstTraceContext.Add(po)

// 明细
Expand All @@ -41,6 +44,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
if !detailType.Exception.IsNil() {
databasePO.Exception = &detailType.Exception
}
databasePO.UseDesc = databasePO.UseTs.String()
databasePO.CreateAt = time.UnixMicro(databasePO.StartTs)
lstTraceDetailDatabase.Add(databasePO)
case *linkTrace.TraceDetailEs:
esPO := mapper.Single[TraceDetailEsPO](*detailType)
Expand All @@ -49,6 +54,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
if !detailType.Exception.IsNil() {
esPO.Exception = &detailType.Exception
}
esPO.UseDesc = esPO.UseTs.String()
esPO.CreateAt = time.UnixMicro(esPO.StartTs)
lstTraceDetailEs.Add(esPO)
case *linkTrace.TraceDetailEtcd:
etcdPO := mapper.Single[TraceDetailEtcdPO](*detailType)
Expand All @@ -57,6 +64,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
if !detailType.Exception.IsNil() {
etcdPO.Exception = &detailType.Exception
}
etcdPO.UseDesc = etcdPO.UseTs.String()
etcdPO.CreateAt = time.UnixMicro(etcdPO.StartTs)
lstTraceDetailEtcd.Add(etcdPO)
case *linkTrace.TraceDetailHand:
handPO := mapper.Single[TraceDetailHandPO](*detailType)
Expand All @@ -65,6 +74,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
if !detailType.Exception.IsNil() {
handPO.Exception = &detailType.Exception
}
handPO.UseDesc = handPO.UseTs.String()
handPO.CreateAt = time.UnixMicro(handPO.StartTs)
lstTraceDetailHand.Add(handPO)
case *linkTrace.TraceDetailHttp:
httpPO := mapper.Single[TraceDetailHttpPO](*detailType)
Expand All @@ -73,6 +84,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
if !detailType.Exception.IsNil() {
httpPO.Exception = &detailType.Exception
}
httpPO.UseDesc = httpPO.UseTs.String()
httpPO.CreateAt = time.UnixMicro(httpPO.StartTs)
lstTraceDetailHttp.Add(httpPO)
case *linkTrace.TraceDetailGrpc:
grpcPO := mapper.Single[TraceDetailGrpcPO](*detailType)
Expand All @@ -81,6 +94,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
if !detailType.Exception.IsNil() {
grpcPO.Exception = &detailType.Exception
}
grpcPO.UseDesc = grpcPO.UseTs.String()
grpcPO.CreateAt = time.UnixMicro(grpcPO.StartTs)
lstTraceDetailGrpc.Add(grpcPO)
case *linkTrace.TraceDetailMq:
mqPO := mapper.Single[TraceDetailMqPO](*detailType)
Expand All @@ -89,6 +104,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
if !detailType.Exception.IsNil() {
mqPO.Exception = &detailType.Exception
}
mqPO.UseDesc = mqPO.UseTs.String()
mqPO.CreateAt = time.UnixMicro(mqPO.StartTs)
lstTraceDetailMq.Add(mqPO)
case *linkTrace.TraceDetailRedis:
redisPO := mapper.Single[TraceDetailRedisPO](*detailType)
Expand All @@ -97,6 +114,8 @@ func saveTraceContextConsumer(subscribeName string, lstMessage collections.ListA
if !detailType.Exception.IsNil() {
redisPO.Exception = &detailType.Exception
}
redisPO.UseDesc = redisPO.UseTs.String()
redisPO.CreateAt = time.UnixMicro(redisPO.StartTs)
lstTraceDetailRedis.Add(redisPO)
}
}
Expand Down
3 changes: 2 additions & 1 deletion driver/elasticSearch/traceContextPO.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ type TraceContextPO struct {
StartTs int64 // 调用开始时间戳(微秒)
EndTs int64 // 调用结束时间戳(微秒)
UseTs time.Duration // 总共使用时间戳(微秒)
UseDesc string `gorm:"-"`
UseDesc string // 总共使用时间(描述)
TraceType eumTraceType.Enum // 状态码
List []trace.ITraceDetail `es_type:"object"` // 调用的上下文
Exception *ExceptionStackPO `es_type:"object"` // 异常信息
Web WebContextPO `es_type:"object"` // Web请求上下文
Consumer ConsumerContextPO `es_type:"object"` // 消费上下文
Task TaskContextPO `es_type:"object"` // 任务上下文
WatchKey WatchKeyContextPO `es_type:"object"` // Etcd上下文
CreateAt time.Time // 请求时间
}

type WebContextPO struct {
Expand Down
3 changes: 2 additions & 1 deletion driver/elasticSearch/traceDetailPO.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ type BaseTraceDetailPO struct {
StartTs int64 // 调用开始时间戳(微秒)
EndTs int64 // 调用停止时间戳(微秒)
UseTs time.Duration // 总共使用时间微秒
UseDesc string `gorm:"-"`
UseDesc string // 总共使用时间(描述)
Exception *trace.ExceptionStack `es_type:"object"` // 异常信息
CreateAt time.Time // 请求时间
}

type TraceDetailDatabasePO struct {
Expand Down

0 comments on commit dfd2c71

Please sign in to comment.