Skip to content

Commit 391eb32

Browse files
committed
RP Id for statsbeat needs work
1 parent d924138 commit 391eb32

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/_statsbeat_metrics.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from azure.monitor.opentelemetry.exporter._constants import (
1919
_ATTACH_METRIC_NAME,
2020
_FEATURE_METRIC_NAME,
21+
_KUBERNETES_SERVICE_HOST,
2122
_REQ_DURATION_NAME,
2223
_REQ_EXCEPTION_NAME,
2324
_REQ_FAILURE_NAME,
@@ -187,7 +188,9 @@ def _get_attach_metric(self, options: CallbackOptions) -> Iterable[Observation]:
187188
elif _utils._is_on_aks():
188189
# AKS
189190
rp = _RP_Names.AKS.value
190-
rpId = os.environ.get(_AKS_ARM_NAMESPACE_ID, "")
191+
# TODO: AKS_ARM_NAMESPACE_ID is only for attach
192+
# rpId = os.environ.get(_AKS_ARM_NAMESPACE_ID, "")
193+
rpId = os.environ.get(_KUBERNETES_SERVICE_HOST , "")
191194
elif self._vm_retry and self._get_azure_compute_metadata():
192195
# VM
193196
rp = _RP_Names.VM.value

sdk/monitor/azure-monitor-opentelemetry-exporter/tests/statsbeat/test_statsbeat.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,16 @@ def test_get_attach_metric_functions(self, metadata_mock):
446446
@mock.patch.dict(
447447
os.environ,
448448
{
449-
"AKS_ARM_NAMESPACE_ID": "namespace_id",
449+
"KUBERNETES_SERVICE_HOST": "TEST_KUBERNETES_SERVICE_HOST",
450450
},
451451
)
452452
def test_get_attach_metric_aks(self):
453453
attributes = dict(_StatsbeatMetrics._COMMON_ATTRIBUTES)
454454
self.assertEqual(attributes["rp"], _RP_Names.UNKNOWN.value)
455455
attributes["rp"] = _RP_Names.AKS.value
456-
attributes["rpId"] = "namespace_id"
456+
# TODO: What should rpId be for aks?
457+
# attributes["rpId"] = ""
458+
attributes["rpId"] = "TEST_KUBERNETES_SERVICE_HOST"
457459
observations = self._metric._get_attach_metric(options=None)
458460
for obs in observations:
459461
self.assertEqual(obs.value, 1)

0 commit comments

Comments
 (0)