40
40
app = FastAPI ()
41
41
executor = ThreadPoolExecutor (max_workers = 16 )
42
42
43
+ logger = logging .getLogger ('uvicorn.error' )
44
+ logger .setLevel (logging .DEBUG )
45
+
43
46
44
47
class ManualCheckout (BaseModel ):
45
48
commit : str
@@ -200,7 +203,7 @@ def async_job_submit(api_helper, node_id, job_callback):
200
203
job_node = api_helper .api .node .get (node_id )
201
204
if not job_node :
202
205
metrics .add ('lava_callback_late_fail_total' , 1 )
203
- logging .error (f'Node { node_id } not found' )
206
+ logger .error (f'Node { node_id } not found' )
204
207
return
205
208
# TODO: Verify lab_name matches job node lab name
206
209
# Also extract job_id and compare with node job_id (future)
@@ -215,14 +218,14 @@ def async_job_submit(api_helper, node_id, job_callback):
215
218
log_txt_url = _upload_log (log_parser , job_node , storage )
216
219
if log_txt_url :
217
220
job_node ['artifacts' ]['lava_log' ] = log_txt_url
218
- print (f"Log uploaded to { log_txt_url } " )
221
+ logger . debug (f"Log uploaded to { log_txt_url } " )
219
222
else :
220
- print ("Failed to upload log" )
223
+ logger . info ("Failed to upload log" )
221
224
metrics .add ('lava_callback_late_fail_total' , 1 )
222
225
callback_json_url = _upload_callback_data (callback_data , job_node , storage )
223
226
if callback_json_url :
224
227
job_node ['artifacts' ]['callback_data' ] = callback_json_url
225
- print (f"Callback data uploaded to { callback_json_url } " )
228
+ logger . debug (f"Callback data uploaded to { callback_json_url } " )
226
229
else :
227
230
metrics .add ('lava_callback_late_fail_total' , 1 )
228
231
# failed LAVA job should have result set to 'incomplete'
@@ -239,10 +242,10 @@ def async_job_submit(api_helper, node_id, job_callback):
239
242
if name .startswith ("artifact-upload:" ) and state == 'pass' :
240
243
artifact = name .split (':' , 2 )
241
244
if len (artifact ) != 3 :
242
- print (f"Failed to extract artifact name and URL from { result } " )
245
+ logger . info (f"Failed to extract artifact name and URL from { result } " )
243
246
continue
244
247
job_node ['artifacts' ][artifact [1 ]] = artifact [2 ]
245
- print (f"Artifact { artifact [1 ]} added with URL { artifact [2 ]} " )
248
+ logger . debug (f"Artifact { artifact [1 ]} added with URL { artifact [2 ]} " )
246
249
hierarchy = job_callback .get_hierarchy (results , job_node )
247
250
api_helper .submit_results (hierarchy , job_node )
248
251
@@ -292,7 +295,7 @@ async def callback(node_id: str, request: Request):
292
295
try :
293
296
data = await request .json ()
294
297
except Exception as e :
295
- logging .error (f'Error decoding JSON: { e } ' )
298
+ logger .error (f'Error decoding JSON: { e } ' )
296
299
item = {}
297
300
item ['message' ] = 'Error decoding JSON'
298
301
return JSONResponse (content = item , status_code = 400 )
@@ -316,7 +319,7 @@ def decode_jwt(jwtstr):
316
319
'''
317
320
secret = SETTINGS .get ('jwt' , {}).get ('secret' )
318
321
if not secret :
319
- logging .error ('No JWT secret configured' )
322
+ logger .error ('No JWT secret configured' )
320
323
return None
321
324
return jwt .decode (jwtstr , secret , algorithms = ['HS256' ])
322
325
@@ -327,17 +330,17 @@ def validate_permissions(jwtoken, permission):
327
330
try :
328
331
decoded = decode_jwt (jwtoken )
329
332
except Exception as e :
330
- logging .error (f'Error decoding JWT: { e } ' )
333
+ logger .error (f'Error decoding JWT: { e } ' )
331
334
return False
332
335
if not decoded :
333
- logging .error ('Invalid JWT' )
336
+ logger .error ('Invalid JWT' )
334
337
return False
335
338
permissions = decoded .get ('permissions' )
336
339
if not permissions :
337
- logging .error ('No permissions in JWT' )
340
+ logger .error ('No permissions in JWT' )
338
341
return False
339
342
if permission not in permissions :
340
- logging .error (f'Permission { permission } not in JWT' )
343
+ logger .error (f'Permission { permission } not in JWT' )
341
344
return False
342
345
return decoded
343
346
@@ -398,7 +401,7 @@ async def jobretry(data: JobRetry, request: Request,
398
401
return JSONResponse (content = item , status_code = 401 )
399
402
400
403
email = decoded .get ('email' )
401
- logging .info (f"User { email } is retrying job { data .nodeid } " )
404
+ logger .info (f"User { email } is retrying job { data .nodeid } " )
402
405
api_config_name = SETTINGS .get ('DEFAULT' , {}).get ('api_config' )
403
406
if not api_config_name :
404
407
item ['message' ] = 'No default API name set'
@@ -408,7 +411,7 @@ async def jobretry(data: JobRetry, request: Request,
408
411
try :
409
412
node = api_helper .api .node .get (data .nodeid )
410
413
except Exception as e :
411
- logging .error (f'Error getting node { data .nodeid } : { e } ' )
414
+ logger .error (f'Error getting node { data .nodeid } : { e } ' )
412
415
item ['message' ] = 'Error getting node'
413
416
return JSONResponse (content = item , status_code = 500 )
414
417
if not node :
@@ -447,7 +450,7 @@ async def jobretry(data: JobRetry, request: Request,
447
450
evnode = {'data' : knode }
448
451
# Now we can submit custom kbuild node to the API(pub/sub)
449
452
api_helper .api .send_event ('node' , evnode )
450
- logging .info (f"Job retry for node { data .nodeid } submitted" )
453
+ logger .info (f"Job retry for node { data .nodeid } submitted" )
451
454
item ['message' ] = 'OK'
452
455
return JSONResponse (content = item , status_code = 200 )
453
456
@@ -534,7 +537,7 @@ async def checkout(data: ManualCheckout, request: Request,
534
537
item ['message' ] = 'Unauthorized'
535
538
return JSONResponse (content = item , status_code = 401 )
536
539
537
- logging .info (f"User { email } is checking out { data .nodeid } at custom commit { data .commit } " )
540
+ logger .info (f"User { email } is checking out { data .nodeid } at custom commit { data .commit } " )
538
541
api_config_name = SETTINGS .get ('DEFAULT' , {}).get ('api_config' )
539
542
if not api_config_name :
540
543
item ['message' ] = 'No default API name set'
@@ -640,7 +643,7 @@ async def checkout(data: ManualCheckout, request: Request,
640
643
item ['message' ] = 'Failed to submit checkout node'
641
644
return JSONResponse (content = item , status_code = 500 )
642
645
else :
643
- logging .info (f"Checkout node { r ['id' ]} submitted" )
646
+ logger .info (f"Checkout node { r ['id' ]} submitted" )
644
647
item ['message' ] = 'OK'
645
648
item ['node' ] = r
646
649
return JSONResponse (content = item , status_code = 200 )
@@ -669,7 +672,7 @@ async def patchset(data: PatchSet, request: Request,
669
672
item ['message' ] = 'Unauthorized'
670
673
return JSONResponse (content = item , status_code = 401 )
671
674
672
- logging .info (f"User { email } is testing patchset on { data .nodeid } " )
675
+ logger .info (f"User { email } is testing patchset on { data .nodeid } " )
673
676
api_config_name = SETTINGS .get ('DEFAULT' , {}).get ('api_config' )
674
677
if not api_config_name :
675
678
item ['message' ] = 'No default API name set'
@@ -743,7 +746,7 @@ async def patchset(data: PatchSet, request: Request,
743
746
item ['message' ] = 'Failed to submit patchset node'
744
747
return JSONResponse (content = item , status_code = 500 )
745
748
else :
746
- logging .info (f"Patchset node { r ['id' ]} submitted" )
749
+ logger .info (f"Patchset node { r ['id' ]} submitted" )
747
750
item ['message' ] = 'OK'
748
751
item ['node' ] = r
749
752
return JSONResponse (content = item , status_code = 200 )
0 commit comments