@@ -3,6 +3,8 @@ package framework
33import (
44 "context"
55 "fmt"
6+ "io"
7+ "os"
68 "strings"
79 "sync"
810 "time"
@@ -163,6 +165,12 @@ func (r *Runner) Run(ctx context.Context) error {
163165 }
164166 }
165167
168+ // Step 7: Collect semantic-router logs (always, regardless of test result)
169+ r .log ("📝 Collecting semantic-router logs..." )
170+ if err := r .collectSemanticRouterLogs (ctx , kubeClient ); err != nil {
171+ r .log ("Warning: failed to collect semantic-router logs: %v" , err )
172+ }
173+
166174 if hasFailures {
167175 exitCode = 1
168176 r .log ("❌ Some tests failed, printing all pods status for debugging..." )
@@ -387,6 +395,79 @@ func (r *Runner) printAllPodsDebugInfo(ctx context.Context, client *kubernetes.C
387395 fmt .Printf ("\n " )
388396}
389397
398+ // collectSemanticRouterLogs collects logs from semantic-router pods and saves to file
399+ func (r * Runner ) collectSemanticRouterLogs (ctx context.Context , client * kubernetes.Clientset ) error {
400+ // Find semantic-router pods
401+ pods , err := client .CoreV1 ().Pods ("vllm-semantic-router-system" ).List (ctx , metav1.ListOptions {})
402+ if err != nil {
403+ return fmt .Errorf ("failed to list semantic-router pods: %w" , err )
404+ }
405+
406+ if len (pods .Items ) == 0 {
407+ r .log ("Warning: no semantic-router pods found" )
408+ return nil
409+ }
410+
411+ // Collect logs from all semantic-router pods
412+ var allLogs strings.Builder
413+ allLogs .WriteString ("========================================\n " )
414+ allLogs .WriteString ("Semantic Router Logs\n " )
415+ allLogs .WriteString ("========================================\n \n " )
416+
417+ for _ , pod := range pods .Items {
418+ allLogs .WriteString (fmt .Sprintf ("=== Pod: %s (Namespace: %s) ===\n " , pod .Name , pod .Namespace ))
419+ allLogs .WriteString (fmt .Sprintf ("Status: %s\n " , pod .Status .Phase ))
420+ allLogs .WriteString (fmt .Sprintf ("Node: %s\n " , pod .Spec .NodeName ))
421+ if pod .Status .StartTime != nil {
422+ allLogs .WriteString (fmt .Sprintf ("Started: %s\n " , pod .Status .StartTime .Format (time .RFC3339 )))
423+ }
424+ allLogs .WriteString ("\n " )
425+
426+ // Collect logs from all containers in the pod
427+ for _ , container := range pod .Spec .Containers {
428+ allLogs .WriteString (fmt .Sprintf ("--- Container: %s ---\n " , container .Name ))
429+
430+ logOptions := & corev1.PodLogOptions {
431+ Container : container .Name ,
432+ }
433+
434+ req := client .CoreV1 ().Pods (pod .Namespace ).GetLogs (pod .Name , logOptions )
435+ logs , err := req .Stream (ctx )
436+ if err != nil {
437+ allLogs .WriteString (fmt .Sprintf ("Error getting logs: %v\n " , err ))
438+ continue
439+ }
440+
441+ logBytes , err := io .ReadAll (logs )
442+ logs .Close ()
443+ if err != nil {
444+ allLogs .WriteString (fmt .Sprintf ("Error reading logs: %v\n " , err ))
445+ continue
446+ }
447+
448+ if len (logBytes ) == 0 {
449+ allLogs .WriteString ("(no logs available)\n " )
450+ } else {
451+ allLogs .Write (logBytes )
452+ allLogs .WriteString ("\n " )
453+ }
454+
455+ allLogs .WriteString ("\n " )
456+ }
457+
458+ allLogs .WriteString ("\n " )
459+ }
460+
461+ // Write logs to file
462+ logFilename := "semantic-router-logs.txt"
463+ if err := os .WriteFile (logFilename , []byte (allLogs .String ()), 0644 ); err != nil {
464+ return fmt .Errorf ("failed to write log file: %w" , err )
465+ }
466+
467+ r .log ("✅ Semantic router logs saved to: %s" , logFilename )
468+ return nil
469+ }
470+
390471func getPodReadyStatus (pod corev1.Pod ) string {
391472 readyCount := 0
392473 totalCount := len (pod .Status .ContainerStatuses )
0 commit comments