Skip to content

[wip] keep going log classifier changes #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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
10 changes: 7 additions & 3 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,7 @@ 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,7 +90,10 @@ 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)
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
Expand Down
21 changes: 16 additions & 5 deletions aws/lambda/log-classifier/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@ 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 mut bucket = BUCKET_NAME;
if is_temp_log {
key = format!("temp_logs/{}", job_id);
bucket = "gha-artifacts";
}
let resp = client
.get_object()
.bucket(BUCKET_NAME)
.bucket(bucket)
.key(key)
.send()
.await?;
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();
client
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
Loading