@@ -30,7 +30,7 @@ if (env.METRICS_COLLECT_DEFAULTS) {
3030
3131class ManagedSupervisor {
3232 private readonly workerSession : SupervisorSession ;
33- private readonly httpServer : HttpServer ;
33+ private readonly metricsServer ? : HttpServer ;
3434 private readonly workloadServer : WorkloadServer ;
3535 private readonly workloadManager : WorkloadManager ;
3636 private readonly logger = new SimpleStructuredLogger ( "managed-worker" ) ;
@@ -61,6 +61,7 @@ class ManagedSupervisor {
6161 intervalMs : env . POD_CLEANER_INTERVAL_MS ,
6262 } ) ;
6363 this . podCleaner = new PodCleaner ( {
64+ register,
6465 namespace : env . KUBERNETES_NAMESPACE ,
6566 batchSize : env . POD_CLEANER_BATCH_SIZE ,
6667 intervalMs : env . POD_CLEANER_INTERVAL_MS ,
@@ -75,6 +76,7 @@ class ManagedSupervisor {
7576 reconnectIntervalMs : env . FAILED_POD_HANDLER_RECONNECT_INTERVAL_MS ,
7677 } ) ;
7778 this . failedPodHandler = new FailedPodHandler ( {
79+ register,
7880 namespace : env . KUBERNETES_NAMESPACE ,
7981 reconnectIntervalMs : env . FAILED_POD_HANDLER_RECONNECT_INTERVAL_MS ,
8082 } ) ;
@@ -243,16 +245,21 @@ class ManagedSupervisor {
243245 }
244246 } ) ;
245247
246- // Used for health checks and metrics
247- this . httpServer = new HttpServer ( { port : 8080 , host : "0.0.0.0" } ) . route ( "/health" , "GET" , {
248- handler : async ( { reply } ) => {
249- reply . text ( "OK" ) ;
250- } ,
251- } ) ;
248+ if ( env . METRICS_ENABLED ) {
249+ this . metricsServer = new HttpServer ( {
250+ port : env . METRICS_PORT ,
251+ host : env . METRICS_HOST ,
252+ metrics : {
253+ register,
254+ expose : true ,
255+ } ,
256+ } ) ;
257+ }
252258
253259 // Responds to workload requests only
254260 this . workloadServer = new WorkloadServer ( {
255261 port : env . TRIGGER_WORKLOAD_API_PORT_INTERNAL ,
262+ host : env . TRIGGER_WORKLOAD_API_HOST_INTERNAL ,
256263 workerClient : this . workerSession . httpClient ,
257264 checkpointClient : this . checkpointClient ,
258265 } ) ;
@@ -321,6 +328,7 @@ class ManagedSupervisor {
321328 // Optional services
322329 await this . podCleaner ?. start ( ) ;
323330 await this . failedPodHandler ?. start ( ) ;
331+ await this . metricsServer ?. start ( ) ;
324332
325333 if ( env . TRIGGER_WORKLOAD_API_ENABLED ) {
326334 this . logger . log ( "[ManagedWorker] Workload API enabled" , {
@@ -334,16 +342,16 @@ class ManagedSupervisor {
334342 }
335343
336344 await this . workerSession . start ( ) ;
337- await this . httpServer . start ( ) ;
338345 }
339346
340347 async stop ( ) {
341348 this . logger . log ( "[ManagedWorker] Shutting down" ) ;
342- await this . httpServer . stop ( ) ;
349+ await this . workerSession . stop ( ) ;
343350
344351 // Optional services
345352 await this . podCleaner ?. stop ( ) ;
346353 await this . failedPodHandler ?. stop ( ) ;
354+ await this . metricsServer ?. stop ( ) ;
347355 }
348356}
349357
0 commit comments