@@ -63,6 +63,14 @@ func (a *Agent) startLogStreamIfNew(logReq *event.ContainerLogRequest, logCtx *l
63
63
a .inflightMu .Unlock ()
64
64
}()
65
65
66
+ logCtx .WithFields (logrus.Fields {
67
+ "uuid" : logReq .UUID ,
68
+ "namespace" : logReq .Namespace ,
69
+ "pod" : logReq .PodName ,
70
+ "container" : logReq .Container ,
71
+ "follow" : logReq .Follow ,
72
+ }).Info ("Processing log request" )
73
+
66
74
if logReq .Follow {
67
75
// Handle live logs with early ACK
68
76
return a .handleLiveStreaming (ctx , logReq , logCtx )
@@ -213,8 +221,8 @@ func (a *Agent) streamLogsToCompletion(
213
221
logCtx * logrus.Entry ,
214
222
) error {
215
223
const (
216
- chunkMax = 64 * 1024 // 64KiB chunks
217
- flushEvery = 50 * time .Millisecond // keep UI latency small
224
+ chunkMax = 64 * 1024
225
+ flushEvery = 50 * time .Millisecond
218
226
)
219
227
220
228
br := bufio .NewReader (rc )
@@ -272,7 +280,6 @@ func (a *Agent) streamLogsToCompletion(
272
280
// Add each processed line to the buffer
273
281
for _ , processedLine := range processedLines {
274
282
wire := processedLine
275
- // append to chunk buffer, splitting if a single line is larger than remaining space
276
283
for len (wire ) > 0 {
277
284
space := chunkMax - len (buf )
278
285
if space == 0 {
@@ -552,35 +559,28 @@ func (a *Agent) processLogLine(line string) ([]string, error) {
552
559
553
560
// extractTimestamp extracts timestamp from a log line for resume capability
554
561
func extractTimestamp (line string ) * time.Time {
555
- // Look for RFC3339 timestamp at the beginning of the line
556
- // Format: 2023-12-07T10:30:45.123456789Z
557
- if len (line ) < 20 {
562
+ if len (line ) < 20 { // "2006-01-02T15:04:05Z" is 20 chars
558
563
return nil
559
564
}
560
-
561
- // Find the first space or tab after potential timestamp
562
- spaceIdx := strings .IndexAny (line , " \t " )
563
- if spaceIdx == - 1 || spaceIdx > 35 { // RFC3339 with nanoseconds is max ~35 chars
565
+ // Grab the first token (up to whitespace). k8s puts a space after the timestamp.
566
+ space := strings .IndexAny (line , " \t " )
567
+ if space == - 1 {
568
+ // Fall back: try whole line (cheap fast-fail)
569
+ space = len (line )
570
+ }
571
+ // Guard against absurdly long "tokens"
572
+ const maxTSLen = 40 // a tad higher than needed; RFC3339Nano+offset is 35
573
+ if space > maxTSLen {
564
574
return nil
565
575
}
576
+ token := line [:space ]
566
577
567
- timestampStr := strings .TrimSpace (line [:spaceIdx ])
568
-
569
- // Try parsing common timestamp formats
570
- formats := []string {
571
- time .RFC3339Nano ,
572
- time .RFC3339 ,
573
- "2006-01-02T15:04:05.000000000Z" ,
574
- "2006-01-02T15:04:05.000000Z" ,
575
- "2006-01-02T15:04:05.000Z" ,
576
- "2006-01-02T15:04:05Z" ,
578
+ // Try the common RFC3339 flavors (covers with/without fractional seconds and offsets)
579
+ if ts , err := time .Parse (time .RFC3339Nano , token ); err == nil {
580
+ return & ts
577
581
}
578
-
579
- for _ , format := range formats {
580
- if ts , err := time .Parse (format , timestampStr ); err == nil {
581
- return & ts
582
- }
582
+ if ts , err := time .Parse (time .RFC3339 , token ); err == nil {
583
+ return & ts
583
584
}
584
-
585
585
return nil
586
586
}
0 commit comments