12
12
from flask import Flask , Response , jsonify , request
13
13
from passlib .hash import pbkdf2_sha256 as pbkdf2
14
14
from playhouse .shortcuts import model_to_dict
15
+ from redis .exceptions import ConnectionError as RedisConnectionError
15
16
from rq .exceptions import NoSuchJobError
16
17
from rq .job import Job as RQJob
17
18
from rq .job import JobStatus
@@ -233,11 +234,21 @@ def get_benches():
233
234
def get_metrics ():
234
235
from agent .exporter import get_metrics
235
236
236
- benches_metrics = [
237
- get_metrics (name , rq_port )
238
- for name , bench in Server ().benches .items ()
239
- if (rq_port := bench .bench_config .get ("rq_port" )) is not None
240
- ]
237
+ benches_metrics = []
238
+ server = Server ()
239
+
240
+ for name , bench in server .benches .items ():
241
+ rq_port = bench .bench_config .get ("rq_port" )
242
+ if rq_port is not None :
243
+ try :
244
+ metrics = get_metrics (name , rq_port )
245
+ benches_metrics .append (metrics )
246
+ except RedisConnectionError as e :
247
+ # This is to specifically catch the error on old benches that had their
248
+ # configs updated to render rq_port but the container doesn't actually
249
+ # expose the rq_port
250
+ log .error (f"Failed to get metrics for { name } on port { rq_port } : { e } " )
251
+
241
252
return Response (benches_metrics , mimetype = "text/plain" )
242
253
243
254
@@ -254,7 +265,15 @@ def get_bench_metrics(bench_str):
254
265
bench = Server ().benches [bench_str ]
255
266
rq_port = bench .bench_config .get ("rq_port" )
256
267
if rq_port :
257
- return Response (get_metrics (bench_str , rq_port ), mimetype = "text/plain" )
268
+ try :
269
+ res = get_metrics (bench_str , rq_port )
270
+ except RedisConnectionError as e :
271
+ # This is to specifically catch the error on old benches that had their
272
+ # configs updated to render rq_port but the container doesn't actually
273
+ # expose the rq_port
274
+ log .error (f"Failed to get metrics for { bench_str } on port { rq_port } : { e } " )
275
+ else :
276
+ return Response (res , mimetype = "text/plain" )
258
277
259
278
return Response ("Unavailable" , status = 400 , mimetype = "text/plain" )
260
279
0 commit comments