39
39
_get_retry_count_value ,
40
40
_get_success_count_value ,
41
41
_get_throttle_count_value ,
42
+ _shorten_host ,
42
43
_StatsbeatMetrics ,
43
44
)
44
45
from opencensus .metrics .export .gauge import (
51
52
_OPTIONS = Options (
52
53
instrumentation_key = "ikey" ,
53
54
enable_local_storage = True ,
54
- endpoint = "test-endpoint " ,
55
+ endpoint = "https://eastus-1.in.applicationinsights.azure.com/ " ,
55
56
credential = None ,
56
57
)
57
58
@@ -348,6 +349,17 @@ def test_get_feature_metric_wtih_aad(self):
348
349
self .assertEqual (
349
350
properties [8 ].value , ext_version ) # noqa: E501
350
351
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
+
351
363
def test_get_instrumentation_metric (self ):
352
364
original_integrations = integrations ._INTEGRATIONS_BIT_MASK
353
365
integrations ._INTEGRATIONS_BIT_MASK = 1024
@@ -367,6 +379,15 @@ def test_get_instrumentation_metric(self):
367
379
properties [8 ].value , ext_version ) # noqa: E501
368
380
integrations ._INTEGRATIONS_BIT_MASK = original_integrations
369
381
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
+
370
391
@mock .patch (
371
392
'opencensus.ext.azure.metrics_exporter.statsbeat_metrics.statsbeat._get_exception_count_value' ) # noqa: E501
372
393
@mock .patch (
@@ -407,7 +428,8 @@ def test_get_network_metrics(self, mock1, mock2, mock3, mock4, mock5, mock6): #
407
428
self .assertEqual (properties [5 ].value , "python" )
408
429
self .assertEqual (properties [6 ].value , ext_version )
409
430
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 )
411
433
412
434
@mock .patch (
413
435
'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):
417
439
suc_mock .return_value = 0
418
440
metrics = stats ._get_network_metrics ()
419
441
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 )
431
442
432
443
@mock .patch .dict (
433
444
os .environ ,
@@ -583,3 +594,21 @@ def test_get_azure_compute_metadata__vm_retry(self):
583
594
self .assertFalse (vm_result )
584
595
self .assertEqual (len (stats ._vm_data ), 0 )
585
596
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