2020import requests
2121
2222from opencensus .ext .azure .metrics_exporter import standard_metrics
23- from opencensus .trace import execution_context
2423
2524if sys .version_info < (3 ,):
2625 from BaseHTTPServer import HTTPServer
3332
3433class TestStandardMetrics (unittest .TestCase ):
3534 def setUp (self ):
36- standard_metrics .http_dependency .dependency_map .clear ()
3735 standard_metrics .http_requests .requests_map .clear ()
3836 requests .Session .request = ORIGINAL_FUNCTION
39- standard_metrics .http_dependency .ORIGINAL_REQUEST = ORIGINAL_FUNCTION
4037 standard_metrics .http_requests .ORIGINAL_CONSTRUCTOR = ORIGINAL_CONS
4138
4239 @mock .patch ('opencensus.ext.azure.metrics_exporter'
@@ -50,12 +47,12 @@ def test_producer_get_metrics(self):
5047 producer = standard_metrics .AzureStandardMetricsProducer ()
5148 metrics = producer .get_metrics ()
5249
53- self .assertEqual (len (metrics ), 7 )
50+ self .assertEqual (len (metrics ), 6 )
5451
5552 def test_register_metrics (self ):
5653 registry = standard_metrics .register_metrics ()
5754
58- self .assertEqual (len (registry .get_metrics ()), 7 )
55+ self .assertEqual (len (registry .get_metrics ()), 6 )
5956
6057 def test_get_available_memory_metric (self ):
6158 metric = standard_metrics .AvailableMemoryMetric ()
@@ -144,58 +141,6 @@ def test_get_process_cpu_usage_exception(self, logger_mock):
144141
145142 logger_mock .exception .assert_called ()
146143
147- def test_dependency_patch (self ):
148- map = standard_metrics .http_dependency .dependency_map
149- standard_metrics .http_dependency .ORIGINAL_REQUEST = lambda x : None
150- session = requests .Session ()
151- execution_context .set_is_exporter (False )
152- result = standard_metrics .http_dependency .dependency_patch (session )
153-
154- self .assertEqual (map ['count' ], 1 )
155- self .assertIsNone (result )
156-
157- def test_dependency_patch_exporter_thread (self ):
158- map = standard_metrics .http_dependency .dependency_map
159- standard_metrics .http_dependency .ORIGINAL_REQUEST = lambda x : None
160- session = mock .Mock ()
161- execution_context .set_is_exporter (True )
162- result = standard_metrics .http_dependency .dependency_patch (session )
163-
164- self .assertIsNone (map .get ('count' ))
165- self .assertIsNone (result )
166-
167- def test_get_dependency_rate_metric (self ):
168- metric = standard_metrics .DependencyRateMetric ()
169- gauge = metric ()
170-
171- self .assertEqual (gauge .descriptor .name ,
172- '\\ ApplicationInsights\\ Dependency Calls/Sec' )
173-
174- def test_get_dependency_rate_first_time (self ):
175- rate = standard_metrics .DependencyRateMetric .get_value ()
176-
177- self .assertEqual (rate , 0 )
178-
179- @mock .patch ('opencensus.ext.azure.metrics_exporter'
180- '.standard_metrics.http_dependency.time' )
181- def test_get_dependency_rate (self , time_mock ):
182- time_mock .time .return_value = 100
183- standard_metrics .http_dependency .dependency_map ['last_time' ] = 98
184- standard_metrics .http_dependency .dependency_map ['count' ] = 4
185- rate = standard_metrics .DependencyRateMetric .get_value ()
186-
187- self .assertEqual (rate , 2 )
188-
189- @mock .patch ('opencensus.ext.azure.metrics_exporter'
190- '.standard_metrics.http_dependency.time' )
191- def test_get_dependency_rate_error (self , time_mock ):
192- time_mock .time .return_value = 100
193- standard_metrics .http_dependency .dependency_map ['last_result' ] = 5
194- standard_metrics .http_dependency .dependency_map ['last_time' ] = 100
195- result = standard_metrics .DependencyRateMetric .get_value ()
196-
197- self .assertEqual (result , 5 )
198-
199144 def test_request_patch (self ):
200145 map = standard_metrics .http_requests .requests_map
201146 func = mock .Mock ()
0 commit comments