1- // Verifies the cold-start invocations metric has durable_function:true only for a durable function.
1+ // Verifies the invocations metric has durable_function:true only for a durable function, on
2+ // both the cold-start invocation and a subsequent warm invocation.
23import { hasMetricWithTag } from './utils/datadog' ;
34import { forceColdStart , invokeLambda } from './utils/lambda' ;
45import { IDENTIFIER , DEFAULT_DATADOG_INDEXING_WAIT_MS } from '../config' ;
@@ -8,42 +9,51 @@ const stackName = `${IDENTIFIER}-durable-cold-start`;
89const INVOCATIONS_METRIC = 'aws.lambda.enhanced.invocations' ;
910
1011describe ( 'Durable Function Cold-Start Metric Tag Integration Tests' , ( ) => {
11- let invocationStartTime : number ;
12- let metricsEndTime : number ;
12+ let coldStartWindowStart : number ;
13+ let coldStartWindowEnd : number ;
14+ let warmInvokeWindowStart : number ;
15+ let warmInvokeWindowEnd : number ;
1316
1417 const durableFunctionName = `${ stackName } -durable-lambda` ;
1518 const nonDurableFunctionName = `${ stackName } -non-durable-lambda` ;
1619
17- beforeAll ( async ( ) => {
18- const functionNames = [ durableFunctionName , nonDurableFunctionName ] ;
19-
20- await Promise . all ( functionNames . map ( ( fn ) => forceColdStart ( fn ) ) ) ;
21-
22- // Back up 60s so the metric's rollup bucket falls inside the query range.
23- invocationStartTime = Date . now ( ) - 60_000 ;
24-
25- // Durable functions reject unqualified-ARN invokes; `:$LATEST` avoids publishing a version.
26- await Promise . all ( [
20+ // Durable functions reject unqualified-ARN invokes; `:$LATEST` avoids publishing a version.
21+ const invokeBoth = ( ) =>
22+ Promise . all ( [
2723 invokeLambda ( `${ durableFunctionName } :$LATEST` ) ,
2824 invokeLambda ( nonDurableFunctionName ) ,
2925 ] ) ;
3026
31- await new Promise ( ( resolve ) =>
27+ const waitForIndexing = ( ) =>
28+ new Promise ( ( resolve ) =>
3229 setTimeout ( resolve , DEFAULT_DATADOG_INDEXING_WAIT_MS ) ,
3330 ) ;
3431
35- metricsEndTime = Date . now ( ) ;
32+ beforeAll ( async ( ) => {
33+ const functionNames = [ durableFunctionName , nonDurableFunctionName ] ;
34+ await Promise . all ( functionNames . map ( ( fn ) => forceColdStart ( fn ) ) ) ;
35+
36+ // Back up 60s so the metric's rollup bucket falls inside the query range.
37+ coldStartWindowStart = Date . now ( ) - 60_000 ;
38+ await invokeBoth ( ) ; // invocation #1 (cold start)
39+ await waitForIndexing ( ) ;
40+ coldStartWindowEnd = Date . now ( ) ;
3641
37- console . log ( 'Lambdas invoked and indexing wait complete' ) ;
38- } , 1800000 ) ;
42+ warmInvokeWindowStart = Date . now ( ) - 60_000 ;
43+ await invokeBoth ( ) ; // invocation #2 (warm)
44+ await waitForIndexing ( ) ;
45+ warmInvokeWindowEnd = Date . now ( ) ;
46+
47+ console . log ( 'Lambdas invoked twice and indexing waits complete' ) ;
48+ } , 3600000 ) ;
3949
4050 it ( 'durable function cold-start invocation metric should have durable_function:true' , async ( ) => {
4151 const hasTag = await hasMetricWithTag (
4252 INVOCATIONS_METRIC ,
4353 durableFunctionName ,
4454 'durable_function:true' ,
45- invocationStartTime ,
46- metricsEndTime ,
55+ coldStartWindowStart ,
56+ coldStartWindowEnd ,
4757 ) ;
4858 expect ( hasTag ) . toBe ( true ) ;
4959 } ) ;
@@ -53,8 +63,30 @@ describe('Durable Function Cold-Start Metric Tag Integration Tests', () => {
5363 INVOCATIONS_METRIC ,
5464 nonDurableFunctionName ,
5565 'durable_function:true' ,
56- invocationStartTime ,
57- metricsEndTime ,
66+ coldStartWindowStart ,
67+ coldStartWindowEnd ,
68+ ) ;
69+ expect ( hasTag ) . toBe ( false ) ;
70+ } ) ;
71+
72+ it ( 'durable function warm invocation metric should still have durable_function:true' , async ( ) => {
73+ const hasTag = await hasMetricWithTag (
74+ INVOCATIONS_METRIC ,
75+ durableFunctionName ,
76+ 'durable_function:true' ,
77+ warmInvokeWindowStart ,
78+ warmInvokeWindowEnd ,
79+ ) ;
80+ expect ( hasTag ) . toBe ( true ) ;
81+ } ) ;
82+
83+ it ( 'non-durable function warm invocation metric should still NOT have durable_function:true' , async ( ) => {
84+ const hasTag = await hasMetricWithTag (
85+ INVOCATIONS_METRIC ,
86+ nonDurableFunctionName ,
87+ 'durable_function:true' ,
88+ warmInvokeWindowStart ,
89+ warmInvokeWindowEnd ,
5890 ) ;
5991 expect ( hasTag ) . toBe ( false ) ;
6092 } ) ;
0 commit comments