@@ -38,14 +38,6 @@ def setUp(self):
38
38
self .mock_threadstats_flush_distributions = patcher .start ()
39
39
self .addCleanup (patcher .stop )
40
40
41
- self .metric_lambda_stats_patcher = patch ("datadog_lambda.metric.lambda_stats" )
42
- self .mock_metric_lambda_stats = self .metric_lambda_stats_patcher .start ()
43
- self .addCleanup (self .metric_lambda_stats_patcher .stop )
44
-
45
- self .wrapper_lambda_stats_patcher = patch ("datadog_lambda.wrapper.lambda_stats" )
46
- self .mock_wrapper_lambda_stats = self .wrapper_lambda_stats_patcher .start ()
47
- self .addCleanup (self .wrapper_lambda_stats_patcher .stop )
48
-
49
41
patcher = patch ("datadog_lambda.wrapper.extract_dd_trace_context" )
50
42
self .mock_extract_dd_trace_context = patcher .start ()
51
43
self .mock_extract_dd_trace_context .return_value = ({}, None )
@@ -101,10 +93,23 @@ def lambda_handler(event, context):
101
93
102
94
lambda_handler (lambda_event , lambda_context )
103
95
104
- self .mock_metric_lambda_stats .distribution .assert_has_calls (
105
- [call ("test.metric" , 100 , timestamp = None , tags = ANY )]
96
+ self .mock_threadstats_flush_distributions .assert_has_calls (
97
+ [
98
+ call (
99
+ [
100
+ {
101
+ "metric" : "test.metric" ,
102
+ "points" : [[ANY , [100 ]]],
103
+ "type" : "distribution" ,
104
+ "host" : None ,
105
+ "device" : None ,
106
+ "tags" : ANY ,
107
+ "interval" : 10 ,
108
+ }
109
+ ]
110
+ )
111
+ ]
106
112
)
107
- self .mock_wrapper_lambda_stats .flush .assert_called ()
108
113
self .mock_extract_dd_trace_context .assert_called_with (
109
114
lambda_event , lambda_context , extractor = None
110
115
)
@@ -122,16 +127,11 @@ def lambda_handler(event, context):
122
127
lambda_event = {}
123
128
lambda_handler (lambda_event , get_mock_context ())
124
129
125
- self .mock_metric_lambda_stats .distribution .assert_not_called ()
126
- self .mock_wrapper_lambda_stats .flush .assert_not_called ()
130
+ self .mock_threadstats_flush_distributions .assert_not_called ()
127
131
128
132
del os .environ ["DD_FLUSH_TO_LOG" ]
129
133
130
134
def test_datadog_lambda_wrapper_flush_in_thread (self ):
131
- # stop patchers so mock_threadstats_flush_distributions gets called
132
- self .metric_lambda_stats_patcher .stop ()
133
- self .wrapper_lambda_stats_patcher .stop ()
134
-
135
135
# force ThreadStats to flush in thread
136
136
import datadog_lambda .metric as metric_module
137
137
@@ -158,15 +158,7 @@ def lambda_handler(event, context):
158
158
metric_module .lambda_stats .stop ()
159
159
metric_module .lambda_stats .start (flush_in_thread = False )
160
160
161
- # resume patchers
162
- self .metric_lambda_stats_patcher .start ()
163
- self .wrapper_lambda_stats_patcher .start ()
164
-
165
161
def test_datadog_lambda_wrapper_not_flush_in_thread (self ):
166
- # stop patchers so mock_threadstats_flush_distributions gets called
167
- self .metric_lambda_stats_patcher .stop ()
168
- self .wrapper_lambda_stats_patcher .stop ()
169
-
170
162
# force ThreadStats to not flush in thread
171
163
import datadog_lambda .metric as metric_module
172
164
@@ -193,10 +185,6 @@ def lambda_handler(event, context):
193
185
metric_module .lambda_stats .stop ()
194
186
metric_module .lambda_stats .start (flush_in_thread = False )
195
187
196
- # resume patchers
197
- self .metric_lambda_stats_patcher .start ()
198
- self .wrapper_lambda_stats_patcher .start ()
199
-
200
188
def test_datadog_lambda_wrapper_inject_correlation_ids (self ):
201
189
os .environ ["DD_LOGS_INJECTION" ] = "True"
202
190
@@ -445,5 +433,4 @@ def lambda_handler(event, context):
445
433
lambda_handler_double_wrapped (lambda_event , get_mock_context ())
446
434
447
435
self .mock_patch_all .assert_called_once ()
448
- self .mock_wrapper_lambda_stats .flush .assert_called_once ()
449
436
self .mock_submit_invocations_metric .assert_called_once ()
0 commit comments