@@ -6,6 +6,15 @@ import cors from 'cors';
66import { Writable } from 'stream' ;
77import { DOMAIN } from './config' ;
88import { prismaClient } from "db/client" ;
9+ import promClient from 'prom-client' ;
10+
11+ const containerCreateBucket = new promClient . Histogram ( {
12+ name : 'container_create_bucket' ,
13+ help : 'Number of times a container was created' ,
14+ labelNames : [ 'type' ] ,
15+ buckets : [ 50 , 100 , 250 , 500 , 1000 , 2500 , 5000 , 10000 , 20000 ] ,
16+ } ) ;
17+
918
1019const kc = new KubeConfig ( ) ;
1120const app = express ( ) ;
@@ -16,8 +25,6 @@ const PROJECT_TYPE_TO_BASE_FOLDER = {
1625 REACT_NATIVE : "/tmp/mobile-app"
1726}
1827
19- const POD_EXPIRY = 1000 * 60 * 5 ; // 5 minutes
20- const EMPTY_POD_BUFFER_SIZE = 3 ;
2128kc . loadFromDefault ( ) ;
2229
2330app . use ( cors ( ) ) ;
@@ -192,8 +199,10 @@ app.get("/worker/:projectId", async (req, res) => {
192199 }
193200
194201 console . log ( "Project found, assigning to pod" ) ;
195- await assignPodToProject ( projectId , "REACT" ) ; // project.type);
202+ const startTime = Date . now ( ) ;
203+ await assignPodToProject ( projectId , "REACT" ) ;
196204 console . log ( "Pod assigned, sending response" ) ;
205+ containerCreateBucket . observe ( { type : project . type } , Date . now ( ) - startTime ) ;
197206
198207 res . json ( {
199208 sessionUrl : `https://session-${ projectId } .${ DOMAIN } ` ,
@@ -202,6 +211,11 @@ app.get("/worker/:projectId", async (req, res) => {
202211 } ) ;
203212} ) ;
204213
214+ app . get ( "/metrics" , async ( req , res ) => {
215+ res . setHeader ( 'Content-Type' , promClient . register . contentType ) ;
216+ res . end ( await promClient . register . metrics ( ) ) ;
217+ } ) ;
218+
205219app . listen ( 7001 , ( ) => {
206220 console . log ( "Server is running on port 7001" ) ;
207221} ) ;
0 commit comments