3939 _get_retry_count_value ,
4040 _get_success_count_value ,
4141 _get_throttle_count_value ,
42+ _shorten_host ,
4243 _StatsbeatMetrics ,
4344)
4445from opencensus .metrics .export .gauge import (
5152_OPTIONS = Options (
5253 instrumentation_key = "ikey" ,
5354 enable_local_storage = True ,
54- endpoint = "test-endpoint " ,
55+ endpoint = "https://eastus-1.in.applicationinsights.azure.com/ " ,
5556 credential = None ,
5657)
5758
@@ -348,6 +349,17 @@ def test_get_feature_metric_wtih_aad(self):
348349 self .assertEqual (
349350 properties [8 ].value , ext_version ) # noqa: E501
350351
352+ def test_get_feature_metric_zero (self ):
353+ # pylint: disable=protected-access
354+ options = Options (
355+ instrumentation_key = "ikey" ,
356+ enable_local_storage = False ,
357+ credential = None ,
358+ )
359+ stats = _StatsbeatMetrics (options )
360+ metric = stats ._get_feature_metric ()
361+ self .assertIsNone (metric )
362+
351363 def test_get_instrumentation_metric (self ):
352364 original_integrations = integrations ._INTEGRATIONS_BIT_MASK
353365 integrations ._INTEGRATIONS_BIT_MASK = 1024
@@ -367,6 +379,15 @@ def test_get_instrumentation_metric(self):
367379 properties [8 ].value , ext_version ) # noqa: E501
368380 integrations ._INTEGRATIONS_BIT_MASK = original_integrations
369381
382+ def test_get_instrumentation_metrics_zero (self ):
383+ # pylint: disable=protected-access
384+ original_integrations = integrations ._INTEGRATIONS_BIT_MASK
385+ integrations ._INTEGRATIONS_BIT_MASK = 0
386+ stats = _StatsbeatMetrics (_OPTIONS )
387+ metric = stats ._get_instrumentation_metric ()
388+ self .assertIsNone (metric )
389+ integrations ._INTEGRATIONS_BIT_MASK = original_integrations
390+
370391 @mock .patch (
371392 'opencensus.ext.azure.metrics_exporter.statsbeat_metrics.statsbeat._get_exception_count_value' ) # noqa: E501
372393 @mock .patch (
@@ -407,7 +428,8 @@ def test_get_network_metrics(self, mock1, mock2, mock3, mock4, mock5, mock6): #
407428 self .assertEqual (properties [5 ].value , "python" )
408429 self .assertEqual (properties [6 ].value , ext_version )
409430 self .assertEqual (properties [7 ].value , _ENDPOINT_TYPES [0 ])
410- self .assertEqual (properties [8 ].value , _OPTIONS .endpoint )
431+ short_host = _shorten_host (_OPTIONS .endpoint )
432+ self .assertEqual (properties [8 ].value , short_host )
411433
412434 @mock .patch (
413435 'opencensus.ext.azure.metrics_exporter.statsbeat_metrics.statsbeat._get_success_count_value' ) # noqa: E501
@@ -417,17 +439,6 @@ def test_get_network_metrics_zero(self, suc_mock):
417439 suc_mock .return_value = 0
418440 metrics = stats ._get_network_metrics ()
419441 self .assertEqual (len (metrics ), 0 )
420- for metric in metrics :
421- properties = metric ._time_series [0 ]._label_values
422- self .assertEqual (len (properties ), 7 )
423- self .assertEqual (properties [0 ].value , _RP_NAMES [3 ])
424- self .assertEqual (properties [1 ].value , "sdk" )
425- self .assertEqual (properties [2 ].value , "ikey" )
426- self .assertEqual (properties [3 ].value , platform .python_version ())
427- self .assertEqual (properties [4 ].value , platform .system ())
428- self .assertEqual (properties [5 ].value , "python" )
429- self .assertEqual (
430- properties [6 ].value , ext_version )
431442
432443 @mock .patch .dict (
433444 os .environ ,
@@ -583,3 +594,21 @@ def test_get_azure_compute_metadata__vm_retry(self):
583594 self .assertFalse (vm_result )
584595 self .assertEqual (len (stats ._vm_data ), 0 )
585596 self .assertTrue (stats ._vm_retry )
597+
598+ def test_shorten_host (self ):
599+ url = "https://fakehost-1.example.com/"
600+ self .assertEqual (_shorten_host (url ), "fakehost-1" )
601+ url = "https://fakehost-2.example.com/"
602+ self .assertEqual (_shorten_host (url ), "fakehost-2" )
603+ url = "http://www.fakehost-3.example.com/"
604+ self .assertEqual (_shorten_host (url ), "fakehost-3" )
605+ url = "http://www.fakehost.com/v2/track"
606+ self .assertEqual (_shorten_host (url ), "fakehost" )
607+ url = "https://www.fakehost0-4.com/"
608+ self .assertEqual (_shorten_host (url ), "fakehost0-4" )
609+ url = "https://www.fakehost-5.com"
610+ self .assertEqual (_shorten_host (url ), "fakehost-5" )
611+ url = "https://fakehost.com"
612+ self .assertEqual (_shorten_host (url ), "fakehost" )
613+ url = "http://fakehost-5/"
614+ self .assertEqual (_shorten_host (url ), "fakehost-5" )
0 commit comments