13
13
def get_mock_context (
14
14
aws_request_id = "request-id-1" ,
15
15
memory_limit_in_mb = "256" ,
16
- invoked_function_arn = "arn:aws:lambda:us-west-1:123457598159:function:python-layer-test:foobar " ,
16
+ invoked_function_arn = "arn:aws:lambda:us-west-1:123457598159:function:python-layer-test:1 " ,
17
17
function_version = "1" ,
18
18
):
19
19
lambda_context = MagicMock ()
@@ -146,10 +146,9 @@ def lambda_handler(event, context):
146
146
"region:us-west-1" ,
147
147
"account_id:123457598159" ,
148
148
"functionname:python-layer-test" ,
149
- "resource:python-layer-test:foobar " ,
149
+ "resource:python-layer-test:1 " ,
150
150
"cold_start:true" ,
151
151
"memorysize:256" ,
152
- "executedversion:1" ,
153
152
"runtime:python2.7" ,
154
153
"dd_lambda_layer:datadog-python27_0.1.0" ,
155
154
],
@@ -176,10 +175,9 @@ def lambda_handler(event, context):
176
175
"region:us-west-1" ,
177
176
"account_id:123457598159" ,
178
177
"functionname:python-layer-test" ,
179
- "resource:python-layer-test:foobar " ,
178
+ "resource:python-layer-test:1 " ,
180
179
"cold_start:true" ,
181
180
"memorysize:256" ,
182
- "executedversion:1" ,
183
181
"runtime:python2.7" ,
184
182
"dd_lambda_layer:datadog-python27_0.1.0" ,
185
183
],
@@ -191,10 +189,9 @@ def lambda_handler(event, context):
191
189
"region:us-west-1" ,
192
190
"account_id:123457598159" ,
193
191
"functionname:python-layer-test" ,
194
- "resource:python-layer-test:foobar " ,
192
+ "resource:python-layer-test:1 " ,
195
193
"cold_start:true" ,
196
194
"memorysize:256" ,
197
- "executedversion:1" ,
198
195
"runtime:python2.7" ,
199
196
"dd_lambda_layer:datadog-python27_0.1.0" ,
200
197
],
@@ -226,10 +223,9 @@ def lambda_handler(event, context):
226
223
"region:us-west-1" ,
227
224
"account_id:123457598159" ,
228
225
"functionname:python-layer-test" ,
229
- "resource:python-layer-test:foobar " ,
226
+ "resource:python-layer-test:1 " ,
230
227
"cold_start:true" ,
231
228
"memorysize:256" ,
232
- "executedversion:1" ,
233
229
"runtime:python2.7" ,
234
230
"dd_lambda_layer:datadog-python27_0.1.0" ,
235
231
],
@@ -241,17 +237,80 @@ def lambda_handler(event, context):
241
237
"region:us-west-1" ,
242
238
"account_id:123457598159" ,
243
239
"functionname:python-layer-test" ,
244
- "resource:python-layer-test:foobar " ,
240
+ "resource:python-layer-test:1 " ,
245
241
"cold_start:false" ,
246
242
"memorysize:256" ,
247
- "executedversion:1" ,
248
243
"runtime:python2.7" ,
249
244
"dd_lambda_layer:datadog-python27_0.1.0" ,
250
245
],
251
246
),
252
247
]
253
248
)
254
249
250
+ def test_enhanced_metrics_latest (self ):
251
+ @datadog_lambda_wrapper
252
+ def lambda_handler (event , context ):
253
+ lambda_metric ("test.metric" , 100 )
254
+
255
+ lambda_event = {}
256
+ lambda_context = get_mock_context ()
257
+
258
+ lambda_context .invoked_function_arn = (
259
+ "arn:aws:lambda:us-west-1:123457598159:function:python-layer-test:$Latest"
260
+ )
261
+ lambda_handler (lambda_event , lambda_context )
262
+
263
+ self .mock_write_metric_point_to_stdout .assert_has_calls (
264
+ [
265
+ call (
266
+ "aws.lambda.enhanced.invocations" ,
267
+ 1 ,
268
+ tags = [
269
+ "region:us-west-1" ,
270
+ "account_id:123457598159" ,
271
+ "functionname:python-layer-test" ,
272
+ "resource:python-layer-test:Latest" ,
273
+ "cold_start:true" ,
274
+ "memorysize:256" ,
275
+ "runtime:python2.7" ,
276
+ "dd_lambda_layer:datadog-python27_0.1.0" ,
277
+ ],
278
+ )
279
+ ]
280
+ )
281
+
282
+ def test_enhanced_metrics_alias (self ):
283
+ @datadog_lambda_wrapper
284
+ def lambda_handler (event , context ):
285
+ lambda_metric ("test.metric" , 100 )
286
+
287
+ lambda_event = {}
288
+ lambda_context = get_mock_context ()
289
+ # tests wouldn't run because line was too long
290
+ alias_arn = "arn:aws:lambda:us-west-1:123457598159:function:python-layer-test:My_alias-1"
291
+ lambda_context .invoked_function_arn = alias_arn
292
+ lambda_handler (lambda_event , lambda_context )
293
+
294
+ self .mock_write_metric_point_to_stdout .assert_has_calls (
295
+ [
296
+ call (
297
+ "aws.lambda.enhanced.invocations" ,
298
+ 1 ,
299
+ tags = [
300
+ "region:us-west-1" ,
301
+ "account_id:123457598159" ,
302
+ "functionname:python-layer-test" ,
303
+ "executedversion:1" ,
304
+ "resource:python-layer-test:My_alias-1" ,
305
+ "cold_start:true" ,
306
+ "memorysize:256" ,
307
+ "runtime:python2.7" ,
308
+ "dd_lambda_layer:datadog-python27_0.1.0" ,
309
+ ],
310
+ )
311
+ ]
312
+ )
313
+
255
314
def test_no_enhanced_metrics_without_env_var (self ):
256
315
os .environ ["DD_ENHANCED_METRICS" ] = "false"
257
316
0 commit comments