Skip to content

Keep going display on HUD: log classifer to handle temp logs #6723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions aws/lambda/log-classifier/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ async fn handle(
repo: &str,
should_write_dynamo: ShouldWriteDynamo,
context_depth: usize,
is_temp_log: bool,
) -> Result<String> {
// delete this in a future pr
let client = get_s3_client().await;
// Download the log from S3.
let start = Instant::now();
let raw_log = download_log(&client, repo, job_id).await?;
let raw_log = download_log(&client, repo, job_id, is_temp_log).await?;
info!("download: {:?}", start.elapsed());

// Do some preprocessing.
Expand Down Expand Up @@ -65,7 +66,8 @@ async fn handle(
info!("match: {}", body);
if should_write_dynamo.0 {
let client = get_dynamo_client().await;
upload_classification_dynamo(&client, repo, job_id, &match_json).await?;
upload_classification_dynamo(&client, repo, job_id, &match_json, is_temp_log)
.await?;
}
Ok(body)
}
Expand All @@ -89,10 +91,19 @@ async fn function_handler(event: Request) -> Result<Response<Body>, Error> {
.first("context_depth")
.unwrap_or_else(|| CONTEXT_DEPTH)
.parse::<usize>()?;
handle(job_id, repo, ShouldWriteDynamo(true), context_depth)
.await?
.into_response()
.await
let is_temp_log = query_string_parameters
.first("temp_log")
.map_or(false, |v| v == "true");
handle(
job_id,
repo,
ShouldWriteDynamo(true),
context_depth,
is_temp_log,
)
.await?
.into_response()
.await
}

_ => Response::builder()
Expand Down
29 changes: 20 additions & 9 deletions aws/lambda/log-classifier/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,22 @@ pub async fn get_dynamo_client() -> dynamodb::Client {
}

/// Download a log for `job_id` from S3.
pub async fn download_log(client: &s3::Client, repo: &str, job_id: usize) -> Result<String> {
let key = match repo {
pub async fn download_log(
client: &s3::Client,
repo: &str,
job_id: usize,
is_temp_log: bool,
) -> Result<String> {
let mut key = match repo {
"pytorch/pytorch" => format!("log/{}", job_id),
_ => format!("log/{}/{}", repo, job_id),
};
let resp = client
.get_object()
.bucket(BUCKET_NAME)
.key(key)
.send()
.await?;
let mut bucket = BUCKET_NAME;
if is_temp_log {
key = format!("temp_logs/{}", job_id);
bucket = "gha-artifacts";
}
let resp = client.get_object().bucket(bucket).key(key).send().await?;

let data = resp.body.collect().await?;
let mut decoder = GzDecoder::new(data.reader());
Expand Down Expand Up @@ -77,19 +82,25 @@ pub async fn upload_classification_dynamo(
repo: &str,
job_id: usize,
best_match: &SerializedMatch,
is_temp_log: bool,
) -> Result<()> {
let update = AttributeValueUpdate::builder()
.action(AttributeAction::Put)
.value(to_attribute_value(best_match)?)
.build();
let attribute_name = if is_temp_log {
"torchci_classification_temp"
} else {
"torchci_classification"
};
client
.update_item()
.table_name("torchci-workflow-job")
.key(
"dynamoKey",
to_attribute_value(format!("{}/{}", repo, job_id))?,
)
.attribute_updates("torchci_classification", update)
.attribute_updates(attribute_name, update)
.send()
.await?;
info!("SUCCESS upload classification to dynamo for job {}", job_id);
Expand Down