diff --git a/resctl-bench/src/lambda.rs b/resctl-bench/src/lambda.rs index 4fbc890..80e7e45 100644 --- a/resctl-bench/src/lambda.rs +++ b/resctl-bench/src/lambda.rs @@ -48,8 +48,25 @@ pub fn init_lambda() { pub async fn run() -> Result<()> { let handler = |event: LambdaEvent| async move { let helper = LambdaHelper::new().await; - let request: Request = serde_json::from_str(event.payload.body.as_ref().unwrap().as_str())?; - + let Some(event_body) = event.payload.body else { + error!("No body found in event payload: {:?}", event.payload); + return Ok(Response { + issue: None, + error_type: Some(format!("Custom")), + error_message: Some(format!("No body found in event payload.")), + }); + }; + let request: Request = match serde_json::from_str(event_body.as_str()) { + Ok(req) => req, + Err(e) => { + error!("Error parsing event body: {}", e); + return Ok(Response { + issue: None, + error_type: Some(format!("Custom")), + error_message: Some(format!("Error parsing event body: {}", e)), + }); + } + }; // Unpack the base64 encoded gz-compressed file. This is safe because Lambda has a hard // limit on the size of the requests (6MB at the moment). let data = base64::decode(&request.data)?; @@ -65,6 +82,7 @@ pub async fn run() -> Result<()> { let object_name = helper.object_name_from_hash(&data)?; if helper.s3_object_exists(&object_name).await? { + error!("File {} has already been submitted", object_name); return Ok(Response { issue: None, error_type: Some(format!("Custom")), @@ -81,10 +99,18 @@ pub async fn run() -> Result<()> { &sysinfo, &format!("{}\n\n{}```\n{}\n```", s3_url, identification, summary), ) - .await?; + .await; + if let Err(e) = issue_url { + error!("Error creating Github issue: {:#}", e); + return Ok(Response { + issue: None, + error_type: Some(format!("Custom")), + error_message: Some(format!("Error creating Github issue: {}", e)), + }); + } Ok::<_, Error>(Response { - issue: Some(issue_url), + issue: Some(issue_url.unwrap()), error_type: None, error_message: None, }) @@ -158,11 +184,11 @@ impl LambdaHelper { .set_name(Some("/iocost-bot/appid".to_string())) .send() .await - .expect("Failed to query parameter") + .context("Failed to query AWS parameter /iocost-bot/appid")? .parameter - .expect("Could not find parameter") + .context("Could not find AWS parameter /iocost-bot/appid")? .value - .expect("Parameter value is None"); + .context("Value of parameter AWS /iocost-bot/appid is None")?; let pem = self .ssm @@ -170,15 +196,16 @@ impl LambdaHelper { .set_name(Some("/iocost-bot/privatekey".to_string())) .send() .await - .expect("Failed to query parameter") + .context("Failed to query parameter AWS /iocost-bot/privatekey")? .parameter - .expect("Could not find parameter") + .context("Could not find parameter AWS /iocost-bot/privatekey")? .value - .expect("Parameter value is None"); + .context("Value of parameter AWS /iocost-bot/privatekey is None")?; let token = octocrab::auth::create_jwt( app_id.parse::().unwrap().into(), - &jsonwebtoken::EncodingKey::from_rsa_pem(pem.as_bytes()).unwrap(), + &jsonwebtoken::EncodingKey::from_rsa_pem(pem.as_bytes()) + .context("Couldn't create a JWT for Github authentication")?, ) .unwrap(); diff --git a/resctl-bench/src/main.rs b/resctl-bench/src/main.rs index c283616..4ae0edc 100644 --- a/resctl-bench/src/main.rs +++ b/resctl-bench/src/main.rs @@ -255,17 +255,10 @@ impl Program { fn do_upload(&mut self) -> Result<()> { let args = &self.args_file.data; - let path = Path::new(&args.result) - .file_name() - .unwrap() - .to_string_lossy() - .to_string(); + let mut data: Vec = std::fs::read(&args.result) + .context(format!("Error opening or reading {}", &args.result))?; - let mut data = Vec::::new(); - let mut f = std::fs::OpenOptions::new().read(true).open(&path)?; - f.read_to_end(&mut data)?; - - if !path.ends_with(".gz") { + if !args.result.ends_with(".gz") { let deflated = std::mem::take(&mut data); let mut encoder = libflate::gzip::Encoder::new(&mut data)?; encoder.write_all(&deflated).context("Compressing file")?; @@ -285,7 +278,13 @@ impl Program { .with_json(&request)? .send()?; - let response: LambdaResponse = serde_json::from_str(response.as_str()?)?; + let Ok(response) = serde_json::from_str::(response.as_str()?) else { + error!( + "Failed to submit benchmark. Server response: {}", + response.as_str()? + ); + std::process::exit(1); + }; if response.issue.is_none() { if let Some(error_message) = response.error_message { error!("Failed to submit benchmark: {}", error_message);