@@ -111,9 +111,9 @@ pub struct Processor {
111111 /// on `platform.report`. This flag ensures whichever event arrives first wins and the other is skipped,
112112 /// preventing double counting.
113113 init_duration_metric_emitted : bool ,
114- /// Timestamp of the On-Demand cold-start invocation metric, held back until
114+ /// Timestamp of the cold-start invocation metric in On-Demand mode , held back until
115115 /// `platform.initStart` sets the durable tag so it's not missed on invocation #1.
116- pending_first_invocation_metric : Option < i64 > ,
116+ pending_first_invocation_metric_timestamp : Option < i64 > ,
117117}
118118
119119impl Processor {
@@ -157,17 +157,14 @@ impl Processor {
157157 durable_context_tx,
158158 restore_time : None ,
159159 init_duration_metric_emitted : false ,
160- pending_first_invocation_metric : None ,
160+ pending_first_invocation_metric_timestamp : None ,
161161 }
162162 }
163163
164164 /// Given a `request_id`, creates the context and adds the enhanced metric offsets to the context buffer.
165165 ///
166166 pub fn on_invoke_event ( & mut self , request_id : String ) {
167- // Fallback flush in case `platform.initStart` never arrived before this invocation.
168- self . flush_pending_first_invocation_metric ( ) ;
169-
170- // See `pending_first_invocation_metric`.
167+ // See `pending_first_invocation_metric_timestamp`.
171168 let is_on_demand_cold_start =
172169 !self . aws_config . is_managed_instance_mode ( ) && self . context_buffer . is_empty ( ) ;
173170
@@ -235,9 +232,9 @@ impl Processor {
235232 . add_enhanced_metric_data ( & request_id, enhanced_metric_offsets) ;
236233 }
237234
238- // Hold back the metric for an On-Demand cold start ; see `pending_first_invocation_metric `.
235+ // Hold back the metric for a cold start in On-Demand mode ; see `pending_first_invocation_metric_timestamp `.
239236 if is_on_demand_cold_start {
240- self . pending_first_invocation_metric = Some ( timestamp) ;
237+ self . pending_first_invocation_metric_timestamp = Some ( timestamp) ;
241238 } else {
242239 self . enhanced_metrics . increment_invocation_metric ( timestamp) ;
243240 }
@@ -274,7 +271,7 @@ impl Processor {
274271
275272 /// Flushes the metric held back by `on_invoke_event`, if any.
276273 fn flush_pending_first_invocation_metric ( & mut self ) {
277- if let Some ( timestamp) = self . pending_first_invocation_metric . take ( ) {
274+ if let Some ( timestamp) = self . pending_first_invocation_metric_timestamp . take ( ) {
278275 self . enhanced_metrics . increment_invocation_metric ( timestamp) ;
279276 }
280277 }
@@ -2131,7 +2128,9 @@ mod tests {
21312128 // `platform.initStart`. The invocation metric must not be emitted yet.
21322129 processor. on_invoke_event ( "req-1" . to_string ( ) ) ;
21332130 assert ! (
2134- processor. pending_first_invocation_metric. is_some( ) ,
2131+ processor
2132+ . pending_first_invocation_metric_timestamp
2133+ . is_some( ) ,
21352134 "Expected the cold start invocation metric to be held back"
21362135 ) ;
21372136
@@ -2149,7 +2148,9 @@ mod tests {
21492148 ) ;
21502149
21512150 assert ! (
2152- processor. pending_first_invocation_metric. is_none( ) ,
2151+ processor
2152+ . pending_first_invocation_metric_timestamp
2153+ . is_none( ) ,
21532154 "Expected the held-back invocation metric to be flushed by on_platform_init_start"
21542155 ) ;
21552156
@@ -2178,23 +2179,6 @@ mod tests {
21782179 ) ;
21792180 }
21802181
2181- #[ tokio:: test]
2182- async fn test_on_invoke_event_flushes_pending_metric_if_init_start_never_arrives ( ) {
2183- let mut processor = setup ( ) ;
2184-
2185- // First invocation of a cold sandbox: metric held back.
2186- processor. on_invoke_event ( "req-1" . to_string ( ) ) ;
2187- assert ! ( processor. pending_first_invocation_metric. is_some( ) ) ;
2188-
2189- // A second invocation arrives without platform.initStart ever showing up. The held-back
2190- // metric from req-1 must still be flushed (as a fallback), not lost.
2191- processor. on_invoke_event ( "req-2" . to_string ( ) ) ;
2192- assert ! (
2193- processor. pending_first_invocation_metric. is_none( ) ,
2194- "Expected the pending metric to be flushed as a fallback on the next invocation"
2195- ) ;
2196- }
2197-
21982182 #[ tokio:: test]
21992183 async fn test_init_duration_emitted_from_init_report ( ) {
22002184 let mut processor = setup ( ) ;
0 commit comments