diff --git a/internal/nodes/http_access_log_queue.go b/internal/nodes/http_access_log_queue.go index 9eb9e82..68994d9 100644 --- a/internal/nodes/http_access_log_queue.go +++ b/internal/nodes/http_access_log_queue.go @@ -4,6 +4,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/rpc" + "strconv" "time" ) @@ -18,7 +19,7 @@ type HTTPAccessLogQueue struct { func NewHTTPAccessLogQueue() *HTTPAccessLogQueue { // 队列中最大的值,超出此数量的访问日志会被丢弃 // TODO 需要可以在界面中设置 - maxSize := 10000 + maxSize := 20000 queue := &HTTPAccessLogQueue{ queue: make(chan *pb.HTTPAccessLog, maxSize), } @@ -49,17 +50,30 @@ func (this *HTTPAccessLogQueue) Push(accessLog *pb.HTTPAccessLog) { // 上传访问日志 func (this *HTTPAccessLogQueue) loop() error { - accessLogs := []*pb.HTTPAccessLog{} - count := 0 + var accessLogs = []*pb.HTTPAccessLog{} + var count = 0 + var timestamp int64 + var requestId = 1_000_000 + Loop: for { select { case accessLog := <-this.queue: + if accessLog.Timestamp > timestamp { + requestId = 10_000_000 + timestamp = accessLog.Timestamp + } else { + requestId++ + } + + // timestamp + requestId + nodeId + accessLog.RequestId = strconv.FormatInt(accessLog.Timestamp, 10) + strconv.Itoa(requestId) + strconv.FormatInt(accessLog.NodeId, 10) + accessLogs = append(accessLogs, accessLog) count++ // 每次只提交 N 条访问日志,防止网络拥堵 - if count > 1000 { + if count > 2000 { break Loop } default: diff --git a/internal/nodes/http_request_log.go b/internal/nodes/http_request_log.go index 6c0e603..a8f197f 100644 --- a/internal/nodes/http_request_log.go +++ b/internal/nodes/http_request_log.go @@ -3,14 +3,10 @@ package nodes import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" - "strconv" "strings" - "sync/atomic" "time" ) -var requestId int64 = 1_0000_0000_0000_0000 - // 日志 func (this *HTTPRequest) log() { if this.disableLog { @@ -85,7 +81,7 @@ func (this *HTTPRequest) log() { } accessLog := &pb.HTTPAccessLog{ - RequestId: strconv.FormatInt(this.requestFromTime.UnixNano(), 10) + strconv.FormatInt(atomic.AddInt64(&requestId, 1), 10) + sharedNodeConfig.PaddedId(), + RequestId: "", NodeId: sharedNodeConfig.Id, ServerId: this.Server.Id, RemoteAddr: this.requestRemoteAddr(true),