1919
2020class TestLambdaMetric (unittest .TestCase ):
2121 def setUp (self ):
22- patcher = patch ("datadog_lambda.metric.lambda_stats" )
23- self .mock_metric_lambda_stats = patcher .start ()
24- self .addCleanup (patcher .stop )
22+ lambda_stats_patcher = patch ("datadog_lambda.metric.lambda_stats" )
23+ self .mock_metric_lambda_stats = lambda_stats_patcher .start ()
24+ self .addCleanup (lambda_stats_patcher .stop )
25+
26+ stdout_metric_patcher = patch (
27+ "datadog_lambda.metric.write_metric_point_to_stdout"
28+ )
29+ self .mock_write_metric_point_to_stdout = stdout_metric_patcher .start ()
30+ self .addCleanup (stdout_metric_patcher .stop )
2531
2632 def test_lambda_metric_tagged_with_dd_lambda_layer (self ):
2733 lambda_metric ("test" , 1 )
@@ -56,13 +62,26 @@ def test_select_metrics_handler_dd_api_fallback(self):
5662 self .assertEqual (MetricsHandler .DATADOG_API , _select_metrics_handler ())
5763 del os .environ ["DD_FLUSH_TO_LOG" ]
5864
65+ @patch ("datadog_lambda.metric.enable_fips_mode" , True )
66+ @patch ("datadog_lambda.metric.should_use_extension" , False )
67+ def test_select_metrics_handler_has_no_fallback_in_fips_mode (self ):
68+ os .environ ["DD_FLUSH_TO_LOG" ] = "False"
69+ self .assertEqual (MetricsHandler .NO_METRICS , _select_metrics_handler ())
70+ del os .environ ["DD_FLUSH_TO_LOG" ]
71+
5972 @patch ("datadog_lambda.metric.metrics_handler" , MetricsHandler .EXTENSION )
60- def test_lambda_metric_flush_to_log_with_extension (self ):
73+ def test_lambda_metric_goes_to_extension_with_extension_handler (self ):
6174 lambda_metric ("test" , 1 )
6275 self .mock_metric_lambda_stats .distribution .assert_has_calls (
6376 [call ("test" , 1 , timestamp = None , tags = [dd_lambda_layer_tag ])]
6477 )
6578
79+ @patch ("datadog_lambda.metric.metrics_handler" , MetricsHandler .NO_METRICS )
80+ def test_lambda_metric_has_nowhere_to_go_with_no_metrics_handler (self ):
81+ lambda_metric ("test" , 1 )
82+ self .mock_metric_lambda_stats .distribution .assert_not_called ()
83+ self .mock_write_metric_point_to_stdout .assert_not_called ()
84+
6685 @patch ("datadog_lambda.metric.metrics_handler" , MetricsHandler .EXTENSION )
6786 def test_lambda_metric_timestamp_with_extension (self ):
6887 delta = timedelta (minutes = 1 )
@@ -72,6 +91,7 @@ def test_lambda_metric_timestamp_with_extension(self):
7291 self .mock_metric_lambda_stats .distribution .assert_has_calls (
7392 [call ("test_timestamp" , 1 , timestamp = timestamp , tags = [dd_lambda_layer_tag ])]
7493 )
94+ self .mock_write_metric_point_to_stdout .assert_not_called ()
7595
7696 @patch ("datadog_lambda.metric.metrics_handler" , MetricsHandler .EXTENSION )
7797 def test_lambda_metric_datetime_with_extension (self ):
@@ -89,6 +109,7 @@ def test_lambda_metric_datetime_with_extension(self):
89109 )
90110 ]
91111 )
112+ self .mock_write_metric_point_to_stdout .assert_not_called ()
92113
93114 @patch ("datadog_lambda.metric.metrics_handler" , MetricsHandler .EXTENSION )
94115 def test_lambda_metric_invalid_timestamp_with_extension (self ):
@@ -97,16 +118,21 @@ def test_lambda_metric_invalid_timestamp_with_extension(self):
97118
98119 lambda_metric ("test_timestamp" , 1 , timestamp )
99120 self .mock_metric_lambda_stats .distribution .assert_not_called ()
121+ self .mock_write_metric_point_to_stdout .assert_not_called ()
100122
101123 @patch ("datadog_lambda.metric.metrics_handler" , MetricsHandler .FORWARDER )
102124 def test_lambda_metric_flush_to_log (self ):
103125 lambda_metric ("test" , 1 )
104126 self .mock_metric_lambda_stats .distribution .assert_not_called ()
127+ self .mock_write_metric_point_to_stdout .assert_has_calls (
128+ [call ("test" , 1 , timestamp = None , tags = [dd_lambda_layer_tag ])]
129+ )
105130
106131 @patch ("datadog_lambda.metric.logger.warning" )
107132 def test_lambda_metric_invalid_metric_name_none (self , mock_logger_warning ):
108133 lambda_metric (None , 1 )
109134 self .mock_metric_lambda_stats .distribution .assert_not_called ()
135+ self .mock_write_metric_point_to_stdout .assert_not_called ()
110136 mock_logger_warning .assert_called_once_with (
111137 "Ignoring metric submission. Invalid metric name: %s" , None
112138 )
@@ -115,6 +141,7 @@ def test_lambda_metric_invalid_metric_name_none(self, mock_logger_warning):
115141 def test_lambda_metric_invalid_metric_name_not_string (self , mock_logger_warning ):
116142 lambda_metric (123 , 1 )
117143 self .mock_metric_lambda_stats .distribution .assert_not_called ()
144+ self .mock_write_metric_point_to_stdout .assert_not_called ()
118145 mock_logger_warning .assert_called_once_with (
119146 "Ignoring metric submission. Invalid metric name: %s" , 123
120147 )
@@ -123,6 +150,7 @@ def test_lambda_metric_invalid_metric_name_not_string(self, mock_logger_warning)
123150 def test_lambda_metric_non_numeric_value (self , mock_logger_warning ):
124151 lambda_metric ("test.non_numeric" , "oops" )
125152 self .mock_metric_lambda_stats .distribution .assert_not_called ()
153+ self .mock_write_metric_point_to_stdout .assert_not_called ()
126154 mock_logger_warning .assert_called_once_with (
127155 "Ignoring metric submission for metric '%s' because the value is not numeric: %r" ,
128156 "test.non_numeric" ,
0 commit comments