fix(agent): 观测缓冲去重纳入 cache_status 并保留原始 -

避免同一请求不同缓存状态被合并丢弃;OpenResty 的 - 原样入库便于详情区分。
This commit is contained in:
ryan
2026-07-18 22:56:10 +08:00
parent fb5a4e5b59
commit 6f221b042e
6 changed files with 25 additions and 12 deletions
+2 -5
View File
@@ -205,11 +205,8 @@ func parseJSONAccessLogRecord(raw string) (parsedAccessLogRecord, bool) {
}
func normalizeCacheStatus(value string) string {
trimmed := strings.TrimSpace(value)
if trimmed == "-" {
return ""
}
return trimmed
// Keep OpenResty "-" as-is so details can distinguish it from a missing field.
return strings.TrimSpace(value)
}
func parseCombinedAccessLogRecord(raw string) (parsedAccessLogRecord, bool) {
@@ -56,6 +56,18 @@ func TestCollectAccessLogsReturnsFactsOnly(t *testing.T) {
}
}
func TestNormalizeCacheStatusKeepsDash(t *testing.T) {
if got := normalizeCacheStatus(" - "); got != "-" {
t.Fatalf("normalizeCacheStatus dash = %q, want -", got)
}
if got := normalizeCacheStatus(" HIT "); got != "HIT" {
t.Fatalf("normalizeCacheStatus hit = %q, want HIT", got)
}
if got := normalizeCacheStatus(""); got != "" {
t.Fatalf("normalizeCacheStatus empty = %q, want empty", got)
}
}
func TestCollectAccessLogsResetsOffsetAfterTruncate(t *testing.T) {
tempDir := t.TempDir()
logPath := filepath.Join(tempDir, "openflare_access.log")