1717
1818package org .apache .spark .deploy .armada .e2e
1919
20+ import org .slf4j .{Logger , LoggerFactory }
2021import scala .collection .mutable
2122import scala .concurrent .duration ._
2223
2324/** Simple pod monitoring that captures logs and events on failure */
2425class SimplePodMonitor (namespace : String ) {
26+ private val logger = LoggerFactory .getLogger(getClass)
2527 private val capturedLogs = mutable.ArrayBuffer [String ]()
2628
2729 /** Check if any pods have failed and capture their logs if so */
@@ -45,7 +47,7 @@ class SimplePodMonitor(namespace: String) {
4547 val failedPodName = failedPods.head.split(" \\ s+" ).head
4648
4749 // Immediately capture logs for the failed pod
48- println (s " [MONITOR] Pod $failedPodName failed, capturing logs... " )
50+ logger.info (s " [MONITOR] Pod $failedPodName failed, capturing logs... " )
4951 try {
5052 val logsCmd = Seq (
5153 " kubectl" ,
@@ -58,8 +60,8 @@ class SimplePodMonitor(namespace: String) {
5860 )
5961 val logsResult = ProcessExecutor .executeWithResult(logsCmd, 10 .seconds)
6062 if (logsResult.exitCode == 0 && logsResult.stdout.nonEmpty) {
61- println (s " [MONITOR] Pod $failedPodName logs: " )
62- println (logsResult.stdout)
63+ logger.info (s " [MONITOR] Pod $failedPodName logs: " )
64+ logger.info (logsResult.stdout)
6365 }
6466
6567 // Also try to describe the pod
@@ -69,33 +71,33 @@ class SimplePodMonitor(namespace: String) {
6971 val lines = describeResult.stdout.split(" \n " )
7072 val eventsIndex = lines.indexWhere(_.contains(" Events:" ))
7173 if (eventsIndex >= 0 ) {
72- println (s " [MONITOR] Pod $failedPodName events: " )
73- println (lines.slice(eventsIndex, eventsIndex + 20 ).mkString(" \n " ))
74+ logger.info (s " [MONITOR] Pod $failedPodName events: " )
75+ logger.info (lines.slice(eventsIndex, eventsIndex + 20 ).mkString(" \n " ))
7476 }
7577 }
7678 } catch {
7779 case e : Exception =>
78- println (s " [MONITOR] Failed to capture logs for $failedPodName: ${e.getMessage}" )
80+ logger.info (s " [MONITOR] Failed to capture logs for $failedPodName: ${e.getMessage}" )
7981 }
8082
8183 Some (s " Pod $failedPodName failed in namespace $namespace" )
8284 } else {
8385 None
8486 }
8587 } else {
86- println (s " [MONITOR] Failed to get pods: ${podsResult.stderr}" )
88+ logger.info (s " [MONITOR] Failed to get pods: ${podsResult.stderr}" )
8789 None
8890 }
8991 } catch {
9092 case e : Exception =>
91- println (s " [MONITOR] Error checking pods: ${e.getMessage}" )
93+ logger.info (s " [MONITOR] Error checking pods: ${e.getMessage}" )
9294 None
9395 }
9496 }
9597
9698 /** Capture all logs and events for debugging */
9799 def captureDebugInfo (): Unit = {
98- println (s " \n [DEBUG] Capturing debug info for namespace $namespace" )
100+ logger.info (s " [DEBUG] Capturing debug info for namespace $namespace" )
99101
100102 try {
101103 val podsCmd = Seq (" kubectl" , " get" , " pods" , " -n" , namespace, " -o" , " name" )
@@ -107,7 +109,7 @@ class SimplePodMonitor(namespace: String) {
107109
108110 podNames.foreach { podName =>
109111 try {
110- println (s " [DEBUG] Capturing logs for pod $podName" )
112+ logger.info (s " [DEBUG] Capturing logs for pod $podName" )
111113
112114 val logsCmd = Seq (
113115 " kubectl" ,
@@ -150,7 +152,7 @@ class SimplePodMonitor(namespace: String) {
150152 }
151153 } catch {
152154 case e : Exception =>
153- println (s " [DEBUG] Failed to capture info for pod $podName: ${e.getMessage}" )
155+ logger.info (s " [DEBUG] Failed to capture info for pod $podName: ${e.getMessage}" )
154156 }
155157 }
156158 }
@@ -163,16 +165,16 @@ class SimplePodMonitor(namespace: String) {
163165
164166 } catch {
165167 case e : Exception =>
166- println (s " [DEBUG] Failed to capture debug info: ${e.getMessage}" )
168+ logger.info (s " [DEBUG] Failed to capture debug info: ${e.getMessage}" )
167169 }
168170 }
169171
170172 /** Print all captured logs */
171173 def printCapturedLogs (): Unit = {
172174 if (capturedLogs.nonEmpty) {
173- println (s " \n ========== DEBUG INFO FOR NAMESPACE: $namespace ========== " )
174- capturedLogs.foreach(println )
175- println (s " ========== END DEBUG INFO ========== \n " )
175+ logger.info (s " \n ========== DEBUG INFO FOR NAMESPACE: $namespace ========== " )
176+ capturedLogs.foreach(logger.info )
177+ logger.info (s " ========== END DEBUG INFO ========== \n " )
176178 }
177179 }
178180}
0 commit comments