fix(server): 修复 Agent 上报访问日志的 bytes_sent 在 Server 入库链路丢失,导致 Zone 概览“已提供的数据总计”长期为 0 的问题。

This commit is contained in:
ryan
2026-07-12 19:02:52 +08:00
parent c624512da6
commit 69467914fc
5 changed files with 48 additions and 9 deletions
@@ -19,13 +19,13 @@ import (
)
const (
healthEventStatusActive = "active"
healthEventStatusResolved = "resolved"
healthSeverityInfo = "info"
healthSeverityWarning = "warning"
healthSeverityCritical = "critical"
accessLogPathMaxLength = 100
healthEventMessageMaxLength = 4096
healthEventStatusActive = "active"
healthEventStatusResolved = "resolved"
healthSeverityInfo = "info"
healthSeverityWarning = "warning"
healthSeverityCritical = "critical"
accessLogPathMaxLength = 100
healthEventMessageMaxLength = 4096
)
// PersistHeartbeatObservability stores profile, snapshots, traffic, access logs, and health events.
@@ -221,6 +221,7 @@ func buildNodeAccessLogRecords(nodeID string, direct []NodeAccessLog, buffered [
Host: strings.TrimSpace(item.Host),
Path: truncateForDatabase(strings.TrimSpace(item.Path), accessLogPathMaxLength),
StatusCode: item.StatusCode,
BytesSent: item.BytesSent,
}
if resolver != nil {
record.Region = resolver.Resolve(record.RemoteAddr)
@@ -0,0 +1,33 @@
// Copyright 2026 Arctel.net
// SPDX-License-Identifier: Apache-2.0
package agent
import (
"testing"
"time"
)
func TestBuildNodeAccessLogRecordsPreservesBytesSent(t *testing.T) {
reportedAt := time.Date(2026, 7, 12, 10, 0, 0, 0, time.UTC)
records, err := buildNodeAccessLogRecords("node-a", []NodeAccessLog{
{
LoggedAtUnix: reportedAt.Unix(),
RemoteAddr: "203.0.113.10",
Host: "api.example.com",
Path: "/v1/ping",
StatusCode: 200,
BytesSent: 4096,
},
}, nil, reportedAt)
if err != nil {
t.Fatalf("buildNodeAccessLogRecords() error = %v", err)
}
if len(records) != 1 {
t.Fatalf("expected one access log record, got %d", len(records))
}
if records[0].BytesSent != 4096 {
t.Fatalf("BytesSent = %d, want 4096", records[0].BytesSent)
}
}