Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit 754d89a

Browse files
authored
Fix a few bugs for Stats (#1077)
1 parent 4cb6f5a commit 754d89a

File tree

5 files changed

+14
-31
lines changed

5 files changed

+14
-31
lines changed

contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/statsbeat_metrics/statsbeat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
_AIMS_API_VERSION = "api-version=2017-12-01"
3737
_AIMS_FORMAT = "format=json"
3838

39-
_DEFAULT_STATS_CONNECTION_STRING = "InstrumentationKey=c4a29126-a7cb-47e5-b348-11414998b11e;IngestionEndpoint=https://dc.services.visualstudio.com/" # noqa: E501
39+
_DEFAULT_STATS_CONNECTION_STRING = "InstrumentationKey=c4a29126-a7cb-47e5-b348-11414998b11e;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com/" # noqa: E501
4040
_DEFAULT_STATS_SHORT_EXPORT_INTERVAL = 900 # 15 minutes
4141
_DEFAULT_STATS_LONG_EXPORT_INTERVAL = 86400 # 24 hours
4242

@@ -111,7 +111,7 @@ def _get_common_properties():
111111

112112
def _get_attach_properties():
113113
properties = _get_common_properties()
114-
properties.insert(1, LabelKey("rpid", 'unique id of rp'))
114+
properties.insert(1, LabelKey("rpId", 'unique id of rp'))
115115
return properties
116116

117117

@@ -345,7 +345,7 @@ def _get_attach_metric(self):
345345
elif self._vm_retry and self._get_azure_compute_metadata():
346346
# VM
347347
rp = _RP_NAMES[2]
348-
rpId = '{}//{}'.format(
348+
rpId = '{}/{}'.format(
349349
self._vm_data.get("vmId", ''),
350350
self._vm_data.get("subscriptionId", ''))
351351
self._os_type = self._vm_data.get("osType", '')

contrib/opencensus-ext-azure/tests/test_azure_log_exporter.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def export(self, batch):
5454
class TestBaseLogHandler(unittest.TestCase):
5555

5656
def setUp(self):
57-
os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"] = "True"
57+
os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"] = "true"
5858
return super(TestBaseLogHandler, self).setUp()
5959

6060
def tearDown(self):
@@ -84,19 +84,15 @@ def test_export_exception(self):
8484
class TestAzureLogHandler(unittest.TestCase):
8585

8686
def setUp(self):
87-
os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"] = "True"
87+
os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"] = "true"
8888
return super(TestAzureLogHandler, self).setUp()
8989

9090
def tearDown(self):
9191
del os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"]
9292
return super(TestAzureLogHandler, self).tearDown()
9393

9494
def test_ctor(self):
95-
from opencensus.ext.azure.common import Options
96-
instrumentation_key = Options._default.instrumentation_key
97-
Options._default.instrumentation_key = None
98-
self.assertRaises(ValueError, lambda: log_exporter.AzureLogHandler())
99-
Options._default.instrumentation_key = instrumentation_key
95+
self.assertRaises(ValueError, lambda: log_exporter.AzureLogHandler(connection_string="", instrumentation_key="")) # noqa: E501
10096

10197
def test_invalid_sampling_rate(self):
10298
with self.assertRaises(ValueError):
@@ -300,20 +296,15 @@ def test_log_record_not_sampled(self, requests_mock):
300296

301297
class TestAzureEventHandler(unittest.TestCase):
302298
def setUp(self):
303-
os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"] = "True"
299+
os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"] = "true"
304300
return super(TestAzureEventHandler, self).setUp()
305301

306302
def tearDown(self):
307303
del os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"]
308304
return super(TestAzureEventHandler, self).setUp()
309305

310306
def test_ctor(self):
311-
from opencensus.ext.azure.common import Options
312-
instrumentation_key = Options._default.instrumentation_key
313-
Options._default.instrumentation_key = None
314-
self.assertRaises(ValueError, lambda: log_exporter.AzureEventHandler(
315-
))
316-
Options._default.instrumentation_key = instrumentation_key
307+
self.assertRaises(ValueError, lambda: log_exporter.AzureEventHandler(connection_string="", instrumentation_key="")) # noqa: E501
317308

318309
def test_invalid_sampling_rate(self):
319310
with self.assertRaises(ValueError):

contrib/opencensus-ext-azure/tests/test_azure_metrics_exporter.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import mock
2020

2121
from opencensus.common import utils
22-
from opencensus.ext.azure.common import Options
2322
from opencensus.ext.azure.common.protocol import DataPoint
2423
from opencensus.ext.azure.metrics_exporter import (
2524
MetricsExporter,
@@ -63,18 +62,15 @@ def create_metric():
6362
class TestAzureMetricsExporter(unittest.TestCase):
6463

6564
def setUp(self):
66-
os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"] = "True"
65+
os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"] = "true"
6766
return super(TestAzureMetricsExporter, self).setUp()
6867

6968
def tearDown(self):
7069
del os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"]
7170
return super(TestAzureMetricsExporter, self).tearDown()
7271

7372
def test_constructor_missing_key(self):
74-
instrumentation_key = Options._default.instrumentation_key
75-
Options._default.instrumentation_key = None
76-
self.assertRaises(ValueError, lambda: MetricsExporter())
77-
Options._default.instrumentation_key = instrumentation_key
73+
self.assertRaises(ValueError, lambda: MetricsExporter(connection_string="", instrumentation_key="")) # noqa: E501
7874

7975
def test_constructor_invalid_batch_size(self):
8076
self.assertRaises(

contrib/opencensus-ext-azure/tests/test_azure_statsbeat_metrics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def test_statsbeat_metric_init(self, attach_mock, network_mock, feature_mock):
206206
def test_get_attach_properties(self):
207207
properties = _get_attach_properties()
208208
self.assertEqual(properties[0].key, "rp")
209-
self.assertEqual(properties[1].key, "rpid")
209+
self.assertEqual(properties[1].key, "rpId")
210210
self.assertEqual(properties[2].key, "attach")
211211
self.assertEqual(properties[3].key, "cikey")
212212
self.assertEqual(properties[4].key, "runtimeVersion")
@@ -462,7 +462,7 @@ def test_get_attach_metric_vm(self):
462462
properties = metric._time_series[0]._label_values
463463
self.assertEqual(len(properties), 8)
464464
self.assertEqual(properties[0].value, _RP_NAMES[2])
465-
self.assertEqual(properties[1].value, "123//sub123")
465+
self.assertEqual(properties[1].value, "123/sub123")
466466
self.assertEqual(properties[2].value, "sdk")
467467
self.assertEqual(properties[3].value, "ikey")
468468
self.assertEqual(properties[4].value, platform.python_version())

contrib/opencensus-ext-azure/tests/test_azure_trace_exporter.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,15 @@ def func(*_args, **_kwargs):
4242
class TestAzureExporter(unittest.TestCase):
4343

4444
def setUp(self):
45-
os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"] = "True"
45+
os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"] = "true"
4646
return super(TestAzureExporter, self).setUp()
4747

4848
def tearDown(self):
4949
del os.environ["APPLICATIONINSIGHTS_STATSBEAT_DISABLED_ALL"]
5050
return super(TestAzureExporter, self).tearDown()
5151

5252
def test_ctor(self):
53-
from opencensus.ext.azure.common import Options
54-
instrumentation_key = Options._default.instrumentation_key
55-
Options._default.instrumentation_key = None
56-
self.assertRaises(ValueError, lambda: trace_exporter.AzureExporter())
57-
Options._default.instrumentation_key = instrumentation_key
53+
self.assertRaises(ValueError, lambda: trace_exporter.AzureExporter(connection_string="", instrumentation_key="")) # noqa: E501
5854

5955
def test_init_exporter_with_proxies(self):
6056
exporter = trace_exporter.AzureExporter(

0 commit comments

Comments
 (0)