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'
@@ -234,14 +237,15 @@ def async_job_submit(api_helper, node_id, job_callback):
234
237
if device_id :
235
238
job_node ['data' ]['device' ] = device_id
236
239
# add artifacts uploaded from the running LAVA job
240
+ logger .debug (f"Results: { results } " )
237
241
for result in results .keys ():
238
242
if result .startswith ("artifact-upload:" ):
239
243
artifact = result .split (':' , 2 )
240
244
if len (artifact ) != 3 :
241
- print (f"Failed to extract artifact name and URL from { result } " )
245
+ logger . info (f"Failed to extract artifact name and URL from { result } " )
242
246
continue
243
247
job_node ['artifacts' ][artifact [1 ]] = artifact [2 ]
244
- print (f"Artifact { artifact [1 ]} added with URL { artifact [2 ]} " )
248
+ logger . debug (f"Artifact { artifact [1 ]} added with URL { artifact [2 ]} " )
245
249
hierarchy = job_callback .get_hierarchy (results , job_node )
246
250
api_helper .submit_results (hierarchy , job_node )
247
251
@@ -291,7 +295,7 @@ async def callback(node_id: str, request: Request):
291
295
try :
292
296
data = await request .json ()
293
297
except Exception as e :
294
- logging .error (f'Error decoding JSON: { e } ' )
298
+ logger .error (f'Error decoding JSON: { e } ' )
295
299
item = {}
296
300
item ['message' ] = 'Error decoding JSON'
297
301
return JSONResponse (content = item , status_code = 400 )
@@ -315,7 +319,7 @@ def decode_jwt(jwtstr):
315
319
'''
316
320
secret = SETTINGS .get ('jwt' , {}).get ('secret' )
317
321
if not secret :
318
- logging .error ('No JWT secret configured' )
322
+ logger .error ('No JWT secret configured' )
319
323
return None
320
324
return jwt .decode (jwtstr , secret , algorithms = ['HS256' ])
321
325
@@ -326,17 +330,17 @@ def validate_permissions(jwtoken, permission):
326
330
try :
327
331
decoded = decode_jwt (jwtoken )
328
332
except Exception as e :
329
- logging .error (f'Error decoding JWT: { e } ' )
333
+ logger .error (f'Error decoding JWT: { e } ' )
330
334
return False
331
335
if not decoded :
332
- logging .error ('Invalid JWT' )
336
+ logger .error ('Invalid JWT' )
333
337
return False
334
338
permissions = decoded .get ('permissions' )
335
339
if not permissions :
336
- logging .error ('No permissions in JWT' )
340
+ logger .error ('No permissions in JWT' )
337
341
return False
338
342
if permission not in permissions :
339
- logging .error (f'Permission { permission } not in JWT' )
343
+ logger .error (f'Permission { permission } not in JWT' )
340
344
return False
341
345
return decoded
342
346
@@ -397,7 +401,7 @@ async def jobretry(data: JobRetry, request: Request,
397
401
return JSONResponse (content = item , status_code = 401 )
398
402
399
403
email = decoded .get ('email' )
400
- logging .info (f"User { email } is retrying job { data .nodeid } " )
404
+ logger .info (f"User { email } is retrying job { data .nodeid } " )
401
405
api_config_name = SETTINGS .get ('DEFAULT' , {}).get ('api_config' )
402
406
if not api_config_name :
403
407
item ['message' ] = 'No default API name set'
@@ -407,7 +411,7 @@ async def jobretry(data: JobRetry, request: Request,
407
411
try :
408
412
node = api_helper .api .node .get (data .nodeid )
409
413
except Exception as e :
410
- logging .error (f'Error getting node { data .nodeid } : { e } ' )
414
+ logger .error (f'Error getting node { data .nodeid } : { e } ' )
411
415
item ['message' ] = 'Error getting node'
412
416
return JSONResponse (content = item , status_code = 500 )
413
417
if not node :
@@ -446,7 +450,7 @@ async def jobretry(data: JobRetry, request: Request,
446
450
evnode = {'data' : knode }
447
451
# Now we can submit custom kbuild node to the API(pub/sub)
448
452
api_helper .api .send_event ('node' , evnode )
449
- logging .info (f"Job retry for node { data .nodeid } submitted" )
453
+ logger .info (f"Job retry for node { data .nodeid } submitted" )
450
454
item ['message' ] = 'OK'
451
455
return JSONResponse (content = item , status_code = 200 )
452
456
@@ -533,7 +537,7 @@ async def checkout(data: ManualCheckout, request: Request,
533
537
item ['message' ] = 'Unauthorized'
534
538
return JSONResponse (content = item , status_code = 401 )
535
539
536
- 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 } " )
537
541
api_config_name = SETTINGS .get ('DEFAULT' , {}).get ('api_config' )
538
542
if not api_config_name :
539
543
item ['message' ] = 'No default API name set'
@@ -639,7 +643,7 @@ async def checkout(data: ManualCheckout, request: Request,
639
643
item ['message' ] = 'Failed to submit checkout node'
640
644
return JSONResponse (content = item , status_code = 500 )
641
645
else :
642
- logging .info (f"Checkout node { r ['id' ]} submitted" )
646
+ logger .info (f"Checkout node { r ['id' ]} submitted" )
643
647
item ['message' ] = 'OK'
644
648
item ['node' ] = r
645
649
return JSONResponse (content = item , status_code = 200 )
@@ -668,7 +672,7 @@ async def patchset(data: PatchSet, request: Request,
668
672
item ['message' ] = 'Unauthorized'
669
673
return JSONResponse (content = item , status_code = 401 )
670
674
671
- logging .info (f"User { email } is testing patchset on { data .nodeid } " )
675
+ logger .info (f"User { email } is testing patchset on { data .nodeid } " )
672
676
api_config_name = SETTINGS .get ('DEFAULT' , {}).get ('api_config' )
673
677
if not api_config_name :
674
678
item ['message' ] = 'No default API name set'
@@ -742,7 +746,7 @@ async def patchset(data: PatchSet, request: Request,
742
746
item ['message' ] = 'Failed to submit patchset node'
743
747
return JSONResponse (content = item , status_code = 500 )
744
748
else :
745
- logging .info (f"Patchset node { r ['id' ]} submitted" )
749
+ logger .info (f"Patchset node { r ['id' ]} submitted" )
746
750
item ['message' ] = 'OK'
747
751
item ['node' ] = r
748
752
return JSONResponse (content = item , status_code = 200 )
0 commit comments