mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-30 20:31:01 +08:00
优化运行日志上传功能,最近N条重复的不再上传
This commit is contained in:
@@ -6,7 +6,9 @@ import (
|
|||||||
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeNode/internal/const"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/trackers"
|
"github.com/TeaOSLab/EdgeNode/internal/trackers"
|
||||||
|
"github.com/cespare/xxhash"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -159,11 +161,33 @@ func ServerSuccess(serverId int64, tag string, description string) {
|
|||||||
// 上传日志
|
// 上传日志
|
||||||
func uploadLogs() error {
|
func uploadLogs() error {
|
||||||
logList := []*pb.NodeLog{}
|
logList := []*pb.NodeLog{}
|
||||||
|
|
||||||
|
const hashSize = 5
|
||||||
|
var hashList = []uint64{}
|
||||||
|
|
||||||
Loop:
|
Loop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case log := <-logChan:
|
case log := <-logChan:
|
||||||
|
// 是否已存在
|
||||||
|
var hash = xxhash.Sum64String(types.String(log.ServerId) + "_" + log.Description)
|
||||||
|
var found = false
|
||||||
|
for _, h := range hashList {
|
||||||
|
if h == hash {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加入
|
||||||
|
if !found {
|
||||||
|
hashList = append(hashList, hash)
|
||||||
|
if len(hashList) > hashSize {
|
||||||
|
hashList = hashList[1:]
|
||||||
|
}
|
||||||
|
|
||||||
logList = append(logList, log)
|
logList = append(logList, log)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break Loop
|
break Loop
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user