From 87178dbc94357bfc2c066bef617bbeba98b7b17e Mon Sep 17 00:00:00 2001 From: Lucas Rayan Date: Mon, 16 Nov 2026 20:57:25 -0300 Subject: [PATCH] fix: head fingerprint covers the whole first line; hub no longer drops traefik generations whose first 64 bytes repeat (2.2.1) Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 6 ++++++ CHANGELOG.pt-BR.md | 6 ++++++ internal/app/probe_test.go | 7 +++++++ internal/app/sources.go | 10 ++++++---- internal/app/version.go | 2 +- internal/tail/tail.go | 5 ++++- internal/tail/tail_test.go | 13 +++++++++++++ 7 files changed, 43 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38d686f..e8c972a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versio ## [Unreleased] +## [2.2.1] - 2026-11-16 + +### Fixed + +- Traffic on probe-fed hosts kept disappearing after Traefik's copytruncate rotation even with 2.2.0: the head fingerprint covered only 64 bytes, and Traefik's first line of every generation starts with the same keep-alive client address and port, so every generation looked like the same file and the hub dropped every line below the previous high-water mark. The fingerprint now covers up to 1024 bytes (the whole first line, with its nanosecond timestamp), and the hub treats fingerprints of different lengths as different generations. Update the probes too. Tests `TestHeadCoversFirstLine` and `TestSameHeadCopytruncate`. + ## [2.2.0] - 2026-11-16 ### Added diff --git a/CHANGELOG.pt-BR.md b/CHANGELOG.pt-BR.md index cfe1af1..b671b85 100644 --- a/CHANGELOG.pt-BR.md +++ b/CHANGELOG.pt-BR.md @@ -6,6 +6,12 @@ Formato baseado no [Keep a Changelog](https://keepachangelog.com/pt-BR/1.1.0/); ## [Não lançado] +## [2.2.1] - 2026-11-16 + +### Corrigido + +- O tráfego dos hosts alimentados por sonda continuava sumindo depois da rotação copytruncate do Traefik mesmo na 2.2.0: a impressão digital do início do arquivo cobria só 64 bytes, e a primeira linha de cada geração do Traefik começa com o mesmo endereço e porta de uma conexão keep-alive, então toda geração parecia o mesmo arquivo e o hub descartava as linhas abaixo da marca anterior. A impressão digital agora cobre até 1024 bytes (a primeira linha inteira, com carimbo de tempo em nanossegundos), e o hub trata impressões de tamanhos diferentes como gerações diferentes. Atualize também as sondas. Testes `TestHeadCoversFirstLine` e `TestSameHeadCopytruncate`. + ## [2.2.0] - 2026-11-16 ### Adicionado diff --git a/internal/app/probe_test.go b/internal/app/probe_test.go index 8b141b9..b650a83 100644 --- a/internal/app/probe_test.go +++ b/internal/app/probe_test.go @@ -91,4 +91,11 @@ func TestSameHeadCopytruncate(t *testing.T) { if sameHead(old, store.Offset{Inode: 7, Offset: 500, FP: 222, FPLen: 64}) { t.Fatal("truncated and regrown file must not be a duplicate") } + // production 2026-11-16: the saved head had 64 bytes, the new probe sends longer ones + if sameHead(old, store.Offset{Inode: 7, Offset: 500, FP: 333, FPLen: 1024}) { + t.Fatal("fingerprints of different lengths must not be taken for the same file") + } + if !sameHead(store.Offset{Inode: 7, Offset: 900}, store.Offset{Inode: 7, Offset: 500, FP: 1, FPLen: 64}) { + t.Fatal("without a saved fingerprint the offset decides") + } } diff --git a/internal/app/sources.go b/internal/app/sources.go index 7d387e7..e6d37f5 100644 --- a/internal/app/sources.go +++ b/internal/app/sources.go @@ -248,12 +248,14 @@ func (r *Runner) feedLocked(src string, text []byte, end store.Offset) bool { // restarts the offsets at 0: without comparing the head fingerprint every new // line below the old high-water mark would be taken for a duplicate and lost // until the file regrew past it. Fingerprints of different lengths cannot be -// compared and count as the same file. +// compared: they count as different generations (at worst a replay across a +// generation start is counted twice, never a whole generation lost). Without a +// fingerprint on either side (old state) the offset alone decides. func sameHead(a, b store.Offset) bool { - if a.FPLen > 0 && a.FPLen == b.FPLen { - return a.FP == b.FP + if a.FPLen == 0 || b.FPLen == 0 { + return true } - return true + return a.FPLen == b.FPLen && a.FP == b.FP } // ApplyBatch applies the lines of a batch under the commit mutex. diff --git a/internal/app/version.go b/internal/app/version.go index e0b7d84..6261f78 100644 --- a/internal/app/version.go +++ b/internal/app/version.go @@ -2,4 +2,4 @@ package app // Version is the release version (SemVer). Release builds may override it with // -ldflags "-X .../internal/app.Version=...". -var Version = "2.2.0" +var Version = "2.2.1" diff --git a/internal/tail/tail.go b/internal/tail/tail.go index c6efd58..29f91df 100644 --- a/internal/tail/tail.go +++ b/internal/tail/tail.go @@ -28,7 +28,10 @@ type Pos struct { FPLen int } -const fpMax = 64 +// fpMax covers a whole first line: Traefik's first 64 bytes (client address and +// port of a keep-alive connection) repeat across rotations, so a short head +// cannot tell two generations of the file apart. +const fpMax = 1024 func fingerprint(b []byte) uint64 { h := uint64(14695981039346656037) diff --git a/internal/tail/tail_test.go b/internal/tail/tail_test.go index e24393e..917e7b7 100644 --- a/internal/tail/tail_test.go +++ b/internal/tail/tail_test.go @@ -155,3 +155,16 @@ func TestStalePosAndBackups(t *testing.T) { t.Fatalf("%v", got) } } + +// Traefik: the first 64 bytes of each rotated generation were identical (same +// keep-alive client address and port), so the head must cover the whole line. +func TestHeadCoversFirstLine(t *testing.T) { + a := []byte(`{"ClientAddr":"195.200.0.252:34352","ClientHost":"195.200.0.252","StartUTC":"2026-11-16T21:06:20.1Z"}` + "\n") + b := []byte(`{"ClientAddr":"195.200.0.252:34352","ClientHost":"195.200.0.252","StartUTC":"2026-11-16T22:48:21.7Z"}` + "\n") + if fingerprint(a[:64]) != fingerprint(b[:64]) { + t.Fatal("fixture: the first 64 bytes should collide") + } + if fpMax < len(a) || fingerprint(a) == fingerprint(b) { + t.Fatal("head fingerprint must tell the two generations apart") + } +}