Skip to content

Commit 83baa63

Browse files
authored
aj/add timeout log (#590)
* test: timeout log * feat: Add task time out log to end log * fix: duration format tests * fix: fmt * feat: specs
1 parent 54e5d19 commit 83baa63

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

bottlecap/src/logs/lambda/processor.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::lifecycle::invocation::context::Context as InvocationContext;
1010
use crate::logs::aggregator::Aggregator;
1111
use crate::logs::processor::{Processor, Rule};
1212
use crate::tags::provider;
13-
use crate::telemetry::events::{TelemetryEvent, TelemetryRecord};
13+
use crate::telemetry::events::{Status, TelemetryEvent, TelemetryRecord};
1414
use crate::LAMBDA_RUNTIME_SLUG;
1515

1616
use crate::logs::lambda::{IntakeLog, Message};
@@ -155,20 +155,23 @@ impl LambdaProcessor {
155155
event.time.timestamp_millis(),
156156
))
157157
},
158-
TelemetryRecord::PlatformRuntimeDone { request_id , metrics, .. } => { // TODO: check what to do with rest of the fields
158+
TelemetryRecord::PlatformRuntimeDone { request_id, status, metrics, .. } => { // TODO: check what to do with rest of the fields
159159
if let Err(e) = self.event_bus.send(Event::Telemetry(copy)).await {
160160
error!("Failed to send PlatformRuntimeDone to the main event bus: {}", e);
161161
}
162162

163+
let mut message = format!("END RequestId: {request_id}");
163164
if let Some(metrics) = metrics {
164165
self.invocation_context.runtime_duration_ms = metrics.duration_ms;
166+
if status == Status::Timeout {
167+
message.push_str(format!(" Task timed out after {:.2} seconds", metrics.duration_ms / 1000.0).as_str());
168+
}
165169
}
166-
167170
// Remove the `request_id` since no more orphan logs will be processed with this one
168171
self.invocation_context.request_id = String::new();
169172

170173
Ok(Message::new(
171-
format!("END RequestId: {request_id}"),
174+
message,
172175
Some(request_id),
173176
self.function_arn.clone(),
174177
event.time.timestamp_millis(),
@@ -186,7 +189,7 @@ impl LambdaProcessor {
186189
}
187190

188191
let mut message = format!(
189-
"REPORT RequestId: {} Duration: {} ms Runtime Duration: {} ms Post Runtime Duration: {} ms Billed Duration: {} ms Memory Size: {} MB Max Memory Used: {} MB",
192+
"REPORT RequestId: {} Duration: {:.2} ms Runtime Duration: {:.2} ms Post Runtime Duration: {:.2} ms Billed Duration: {:.2} ms Memory Size: {} MB Max Memory Used: {} MB",
190193
request_id,
191194
metrics.duration_ms,
192195
self.invocation_context.runtime_duration_ms,
@@ -198,7 +201,7 @@ impl LambdaProcessor {
198201

199202
let init_duration_ms = metrics.init_duration_ms;
200203
if let Some(init_duration_ms) = init_duration_ms {
201-
message = format!("{message} Init Duration: {init_duration_ms} ms");
204+
message = format!("{message} Init Duration: {init_duration_ms:.2} ms");
202205
}
203206

204207
Ok(Message::new(
@@ -440,6 +443,31 @@ mod tests {
440443
},
441444
),
442445

446+
// platform runtime done
447+
platform_runtime_done_timeout: (
448+
&TelemetryEvent {
449+
time: Utc.with_ymd_and_hms(2023, 1, 7, 3, 23, 47).unwrap(),
450+
record: TelemetryRecord::PlatformRuntimeDone {
451+
request_id: "test-request-id".to_string(),
452+
status: Status::Timeout,
453+
error_type: None,
454+
metrics: Some(RuntimeDoneMetrics {
455+
duration_ms: 5000.0,
456+
produced_bytes: Some(42)
457+
})
458+
}
459+
},
460+
Message {
461+
message: "END RequestId: test-request-id Task timed out after 5.00 seconds".to_string(),
462+
lambda: Lambda {
463+
arn: "test-arn".to_string(),
464+
request_id: Some("test-request-id".to_string()),
465+
},
466+
timestamp: 1_673_061_827_000,
467+
status: "info".to_string(),
468+
},
469+
),
470+
443471
// platform report
444472
platform_report: (
445473
&TelemetryEvent {
@@ -459,7 +487,7 @@ mod tests {
459487
}
460488
},
461489
Message {
462-
message: "REPORT RequestId: test-request-id Duration: 100 ms Runtime Duration: 0 ms Post Runtime Duration: 0 ms Billed Duration: 128 ms Memory Size: 256 MB Max Memory Used: 64 MB Init Duration: 50 ms".to_string(),
490+
message: "REPORT RequestId: test-request-id Duration: 100.00 ms Runtime Duration: 0.00 ms Post Runtime Duration: 0.00 ms Billed Duration: 128 ms Memory Size: 256 MB Max Memory Used: 64 MB Init Duration: 50.00 ms".to_string(),
463491
lambda: Lambda {
464492
arn: "test-arn".to_string(),
465493
request_id: Some("test-request-id".to_string()),

0 commit comments

Comments
 (0)