1
1
package local
2
2
3
3
import (
4
+ "bufio"
4
5
"context"
5
6
"fmt"
6
7
"net/http"
7
8
"os"
8
9
"path/filepath"
10
+ "regexp"
9
11
"strconv"
10
12
"strings"
11
13
"time"
@@ -378,6 +380,63 @@ func (c *Command) watchEvents(ctx context.Context) {
378
380
}
379
381
}
380
382
383
+ // 2024-09-10 20:16:24 WARN i.m.s.r.u.Loggers$Slf4JLogger(warn):299 - [273....
384
+ var javaLogRx = regexp .MustCompile (`^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \x1b\[(?:1;)?\d+m(?P<level>[A-Z]+)\x1b\[m (?P<msg>\S+ - .*)` )
385
+
386
+ func (c * Command ) streamPodLogs (ctx context.Context , namespace , podName , prefix string , since time.Time ) error {
387
+ r , err := c .k8s .StreamPodLogs (ctx , namespace , podName , since )
388
+ if err != nil {
389
+ return err
390
+ }
391
+ defer r .Close ()
392
+
393
+ level := pterm .Debug
394
+ scanner := bufio .NewScanner (r )
395
+
396
+ for scanner .Scan () {
397
+
398
+ // skip java stacktrace noise
399
+ if strings .HasPrefix (scanner .Text (), "\t at " ) || strings .HasPrefix (scanner .Text (), "\t ... " ) {
400
+ continue
401
+ }
402
+
403
+ m := javaLogRx .FindSubmatch (scanner .Bytes ())
404
+ var msg string
405
+
406
+ if m != nil {
407
+ msg = string (m [2 ])
408
+ if string (m [1 ]) == "ERROR" {
409
+ level = pterm .Error
410
+ } else {
411
+ level = pterm .Debug
412
+ }
413
+ } else {
414
+ msg = scanner .Text ()
415
+ }
416
+
417
+ level .Printfln ("%s: %s" , prefix , msg )
418
+ }
419
+ return scanner .Err ()
420
+ }
421
+
422
+ func (c * Command ) watchBootloaderLogs (ctx context.Context ) {
423
+ pterm .Debug .Printfln ("start streaming bootloader logs" )
424
+ since := time .Now ()
425
+
426
+ for {
427
+ // Wait a few seconds on the first iteration, give the bootloaders some time to start.
428
+ time .Sleep (5 * time .Second )
429
+
430
+ err := c .streamPodLogs (ctx , airbyteNamespace , airbyteBootloaderPodName , "airbyte-bootloader" , since )
431
+ if err == nil {
432
+ break
433
+ } else {
434
+ pterm .Debug .Printfln ("error streaming bootloader logs. will retry: %s" , err )
435
+ }
436
+ }
437
+ pterm .Debug .Printfln ("done streaming bootloader logs" )
438
+ }
439
+
381
440
// now is used to filter out kubernetes events that happened in the past.
382
441
// Kubernetes wants us to use the ResourceVersion on the event watch request itself, but that approach
383
442
// is more complicated as it requires determining which ResourceVersion to initially provide.
@@ -398,6 +457,8 @@ func (c *Command) handleEvent(ctx context.Context, e *eventsv1.Event) {
398
457
case strings .EqualFold (e .Type , "normal" ):
399
458
if strings .EqualFold (e .Reason , "backoff" ) {
400
459
pterm .Warning .Println (e .Note )
460
+ } else if e .Reason == "Started" && e .Regarding .Name == "airbyte-abctl-airbyte-bootloader" {
461
+ go c .watchBootloaderLogs (ctx )
401
462
} else {
402
463
pterm .Debug .Println (e .Note )
403
464
}
0 commit comments