4040app = FastAPI ()
4141executor = ThreadPoolExecutor (max_workers = 16 )
4242
43+ logger = logging .getLogger ('uvicorn.error' )
44+ logger .setLevel (logging .DEBUG )
45+
4346
4447class ManualCheckout (BaseModel ):
4548 commit : str
@@ -200,7 +203,7 @@ def async_job_submit(api_helper, node_id, job_callback):
200203 job_node = api_helper .api .node .get (node_id )
201204 if not job_node :
202205 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' )
204207 return
205208 # TODO: Verify lab_name matches job node lab name
206209 # 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):
215218 log_txt_url = _upload_log (log_parser , job_node , storage )
216219 if log_txt_url :
217220 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 } " )
219222 else :
220- print ("Failed to upload log" )
223+ logger . info ("Failed to upload log" )
221224 metrics .add ('lava_callback_late_fail_total' , 1 )
222225 callback_json_url = _upload_callback_data (callback_data , job_node , storage )
223226 if callback_json_url :
224227 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 } " )
226229 else :
227230 metrics .add ('lava_callback_late_fail_total' , 1 )
228231 # failed LAVA job should have result set to 'incomplete'
@@ -239,10 +242,10 @@ def async_job_submit(api_helper, node_id, job_callback):
239242 if name .startswith ("artifact-upload:" ) and state == 'pass' :
240243 artifact = name .split (':' , 2 )
241244 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 } " )
243246 continue
244247 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 ]} " )
246249 hierarchy = job_callback .get_hierarchy (results , job_node )
247250 api_helper .submit_results (hierarchy , job_node )
248251
@@ -292,7 +295,7 @@ async def callback(node_id: str, request: Request):
292295 try :
293296 data = await request .json ()
294297 except Exception as e :
295- logging .error (f'Error decoding JSON: { e } ' )
298+ logger .error (f'Error decoding JSON: { e } ' )
296299 item = {}
297300 item ['message' ] = 'Error decoding JSON'
298301 return JSONResponse (content = item , status_code = 400 )
@@ -316,7 +319,7 @@ def decode_jwt(jwtstr):
316319 '''
317320 secret = SETTINGS .get ('jwt' , {}).get ('secret' )
318321 if not secret :
319- logging .error ('No JWT secret configured' )
322+ logger .error ('No JWT secret configured' )
320323 return None
321324 return jwt .decode (jwtstr , secret , algorithms = ['HS256' ])
322325
@@ -327,17 +330,17 @@ def validate_permissions(jwtoken, permission):
327330 try :
328331 decoded = decode_jwt (jwtoken )
329332 except Exception as e :
330- logging .error (f'Error decoding JWT: { e } ' )
333+ logger .error (f'Error decoding JWT: { e } ' )
331334 return False
332335 if not decoded :
333- logging .error ('Invalid JWT' )
336+ logger .error ('Invalid JWT' )
334337 return False
335338 permissions = decoded .get ('permissions' )
336339 if not permissions :
337- logging .error ('No permissions in JWT' )
340+ logger .error ('No permissions in JWT' )
338341 return False
339342 if permission not in permissions :
340- logging .error (f'Permission { permission } not in JWT' )
343+ logger .error (f'Permission { permission } not in JWT' )
341344 return False
342345 return decoded
343346
@@ -398,7 +401,7 @@ async def jobretry(data: JobRetry, request: Request,
398401 return JSONResponse (content = item , status_code = 401 )
399402
400403 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 } " )
402405 api_config_name = SETTINGS .get ('DEFAULT' , {}).get ('api_config' )
403406 if not api_config_name :
404407 item ['message' ] = 'No default API name set'
@@ -408,7 +411,7 @@ async def jobretry(data: JobRetry, request: Request,
408411 try :
409412 node = api_helper .api .node .get (data .nodeid )
410413 except Exception as e :
411- logging .error (f'Error getting node { data .nodeid } : { e } ' )
414+ logger .error (f'Error getting node { data .nodeid } : { e } ' )
412415 item ['message' ] = 'Error getting node'
413416 return JSONResponse (content = item , status_code = 500 )
414417 if not node :
@@ -447,7 +450,7 @@ async def jobretry(data: JobRetry, request: Request,
447450 evnode = {'data' : knode }
448451 # Now we can submit custom kbuild node to the API(pub/sub)
449452 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" )
451454 item ['message' ] = 'OK'
452455 return JSONResponse (content = item , status_code = 200 )
453456
@@ -534,7 +537,7 @@ async def checkout(data: ManualCheckout, request: Request,
534537 item ['message' ] = 'Unauthorized'
535538 return JSONResponse (content = item , status_code = 401 )
536539
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 } " )
538541 api_config_name = SETTINGS .get ('DEFAULT' , {}).get ('api_config' )
539542 if not api_config_name :
540543 item ['message' ] = 'No default API name set'
@@ -640,7 +643,7 @@ async def checkout(data: ManualCheckout, request: Request,
640643 item ['message' ] = 'Failed to submit checkout node'
641644 return JSONResponse (content = item , status_code = 500 )
642645 else :
643- logging .info (f"Checkout node { r ['id' ]} submitted" )
646+ logger .info (f"Checkout node { r ['id' ]} submitted" )
644647 item ['message' ] = 'OK'
645648 item ['node' ] = r
646649 return JSONResponse (content = item , status_code = 200 )
@@ -669,7 +672,7 @@ async def patchset(data: PatchSet, request: Request,
669672 item ['message' ] = 'Unauthorized'
670673 return JSONResponse (content = item , status_code = 401 )
671674
672- logging .info (f"User { email } is testing patchset on { data .nodeid } " )
675+ logger .info (f"User { email } is testing patchset on { data .nodeid } " )
673676 api_config_name = SETTINGS .get ('DEFAULT' , {}).get ('api_config' )
674677 if not api_config_name :
675678 item ['message' ] = 'No default API name set'
@@ -743,7 +746,7 @@ async def patchset(data: PatchSet, request: Request,
743746 item ['message' ] = 'Failed to submit patchset node'
744747 return JSONResponse (content = item , status_code = 500 )
745748 else :
746- logging .info (f"Patchset node { r ['id' ]} submitted" )
749+ logger .info (f"Patchset node { r ['id' ]} submitted" )
747750 item ['message' ] = 'OK'
748751 item ['node' ] = r
749752 return JSONResponse (content = item , status_code = 200 )
0 commit comments