feat(api): add timestamp field to LogRecord
Some checks failed
Build DEB Package / Build DEB Package (Debian/Ubuntu) (push) Has been cancelled
Build RPM Package / Build RPM Package (Rocky Linux) (push) Has been cancelled

- Add Timestamp field (int64, nanoseconds since Unix epoch) to LogRecord
- Import time package in api/types.go
- Set timestamp using time.Now().UnixNano() in NewLogRecord()
- Add test assertion to verify timestamp is set

The timestamp is now included in all JSON log outputs

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
Jacquin Antoine
2026-02-27 00:20:40 +01:00
parent dfd5e49dd9
commit f362e325bf
2 changed files with 11 additions and 0 deletions

View File

@ -1,5 +1,7 @@
package api
import "time"
// ServiceLog represents internal service logging for diagnostics
type ServiceLog struct {
Level string `json:"level"`
@ -85,6 +87,9 @@ type LogRecord struct {
JA4Hash string `json:"ja4_hash"`
JA3 string `json:"ja3,omitempty"`
JA3Hash string `json:"ja3_hash,omitempty"`
// Timestamp in nanoseconds since Unix epoch
Timestamp int64 `json:"timestamp"`
}
// OutputConfig defines configuration for a single log output
@ -212,6 +217,7 @@ func NewLogRecord(ch TLSClientHello, fp *Fingerprints) LogRecord {
TCPMSS: mssPtr,
TCPWScale: wScalePtr,
TCPOptions: opts,
Timestamp: time.Now().UnixNano(),
}
if fp != nil {

View File

@ -91,6 +91,11 @@ func TestNewLogRecord(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
rec := NewLogRecord(tt.clientHello, tt.fingerprints)
// Verify timestamp is set
if rec.Timestamp == 0 {
t.Error("Timestamp should be set")
}
// Verify basic fields
if rec.SrcIP != tt.clientHello.SrcIP {
t.Errorf("SrcIP = %v, want %v", rec.SrcIP, tt.clientHello.SrcIP)