feat(api): add timestamp field to LogRecord
- 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:
@ -1,5 +1,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
// ServiceLog represents internal service logging for diagnostics
|
// ServiceLog represents internal service logging for diagnostics
|
||||||
type ServiceLog struct {
|
type ServiceLog struct {
|
||||||
Level string `json:"level"`
|
Level string `json:"level"`
|
||||||
@ -85,6 +87,9 @@ type LogRecord struct {
|
|||||||
JA4Hash string `json:"ja4_hash"`
|
JA4Hash string `json:"ja4_hash"`
|
||||||
JA3 string `json:"ja3,omitempty"`
|
JA3 string `json:"ja3,omitempty"`
|
||||||
JA3Hash string `json:"ja3_hash,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
|
// OutputConfig defines configuration for a single log output
|
||||||
@ -212,6 +217,7 @@ func NewLogRecord(ch TLSClientHello, fp *Fingerprints) LogRecord {
|
|||||||
TCPMSS: mssPtr,
|
TCPMSS: mssPtr,
|
||||||
TCPWScale: wScalePtr,
|
TCPWScale: wScalePtr,
|
||||||
TCPOptions: opts,
|
TCPOptions: opts,
|
||||||
|
Timestamp: time.Now().UnixNano(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if fp != nil {
|
if fp != nil {
|
||||||
|
|||||||
@ -91,6 +91,11 @@ func TestNewLogRecord(t *testing.T) {
|
|||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
rec := NewLogRecord(tt.clientHello, tt.fingerprints)
|
rec := NewLogRecord(tt.clientHello, tt.fingerprints)
|
||||||
|
|
||||||
|
// Verify timestamp is set
|
||||||
|
if rec.Timestamp == 0 {
|
||||||
|
t.Error("Timestamp should be set")
|
||||||
|
}
|
||||||
|
|
||||||
// Verify basic fields
|
// Verify basic fields
|
||||||
if rec.SrcIP != tt.clientHello.SrcIP {
|
if rec.SrcIP != tt.clientHello.SrcIP {
|
||||||
t.Errorf("SrcIP = %v, want %v", rec.SrcIP, tt.clientHello.SrcIP)
|
t.Errorf("SrcIP = %v, want %v", rec.SrcIP, tt.clientHello.SrcIP)
|
||||||
|
|||||||
Reference in New Issue
Block a user