优化运行日志上传功能,最近N条重复的不再上传

This commit is contained in:
GoEdgeLab
2021-11-15 16:59:18 +08:00
parent dec5ba8954
commit d8edc0d2bf

View File

@@ -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
} }