-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27f5b9d
commit 958bd25
Showing
2 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
sdk/monitor/azure-monitor-opentelemetry-exporter/tests/resource/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. |
114 changes: 114 additions & 0 deletions
114
...azure-monitor-opentelemetry-exporter/tests/resource/test_app_service_resource_detector.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
from azure.monitor.opentelemetry.exporter.resource.app_service_resource_detector import ( | ||
AzureAppServiceResourceDetector, | ||
) | ||
|
||
TEST_WEBSITE_SITE_NAME = "TEST_WEBSITE_SITE_NAME" | ||
TEST_REGION_NAME = "TEST_REGION_NAME" | ||
TEST_WEBSITE_SLOT_NAME = "TEST_WEBSITE_SLOT_NAME" | ||
TEST_WEBSITE_HOSTNAME = "TEST_WEBSITE_HOSTNAME" | ||
TEST_WEBSITE_INSTANCE_ID = "TEST_WEBSITE_INSTANCE_ID" | ||
TEST_WEBSITE_HOME_STAMPNAME = "TEST_WEBSITE_HOME_STAMPNAME" | ||
|
||
TEST_WEBSITE_RESOURCE_GROUP = "TEST_WEBSITE_RESOURCE_GROUP" | ||
TEST_WEBSITE_OWNER_NAME = "TEST_WEBSITE_OWNER_NAME" | ||
|
||
class TestAzureAppServiceResourceDetector(unittest.TestCase): | ||
@patch.dict("os.environ", { | ||
"WEBSITE_SITE_NAME": TEST_WEBSITE_SITE_NAME, | ||
"REGION_NAME": TEST_REGION_NAME, | ||
"WEBSITE_SLOT_NAME": TEST_WEBSITE_SLOT_NAME, | ||
"WEBSITE_HOSTNAME": TEST_WEBSITE_HOSTNAME, | ||
"WEBSITE_INSTANCE_ID": TEST_WEBSITE_INSTANCE_ID, | ||
"WEBSITE_HOME_STAMPNAME": TEST_WEBSITE_HOME_STAMPNAME, | ||
"WEBSITE_RESOURCE_GROUP": TEST_WEBSITE_RESOURCE_GROUP, | ||
"WEBSITE_OWNER_NAME": TEST_WEBSITE_OWNER_NAME, | ||
}, clear=True) | ||
def test_on_app_service(self): | ||
resource = AzureAppServiceResourceDetector().detect() | ||
attributes = resource.attributes | ||
# self.assertEqual(attributes { | ||
# "service.name": TEST_WEBSITE_SITE_NAME, | ||
# "cloud.provider": , | ||
# "cloud.platform": , | ||
# "cloud.resource_id": , | ||
# "cloud.region": , | ||
# "deployment.environment": , | ||
# "deployment.environment": , | ||
# }) | ||
self.assertEqual(attributes["service.name"], TEST_WEBSITE_SITE_NAME) | ||
self.assertEqual(attributes["cloud.provider"], "azure") | ||
self.assertEqual(attributes["cloud.platform"], "azure_app_service") | ||
|
||
self.assertEqual(attributes["cloud.resource_id"], \ | ||
f"/subscriptions/{TEST_WEBSITE_OWNER_NAME}/resourceGroups/{TEST_WEBSITE_RESOURCE_GROUP}/providers/Microsoft.Web/sites/{TEST_WEBSITE_SITE_NAME}") | ||
|
||
self.assertEqual(attributes["cloud.region"], TEST_REGION_NAME) | ||
self.assertEqual(attributes["deployment.environment"], TEST_WEBSITE_SLOT_NAME) | ||
self.assertEqual(attributes["host.id"], TEST_WEBSITE_HOSTNAME) | ||
self.assertEqual(attributes["service.instance.id"], TEST_WEBSITE_INSTANCE_ID) | ||
self.assertEqual(attributes["azure.app.service.stamp"], TEST_WEBSITE_HOME_STAMPNAME) | ||
|
||
@patch.dict("os.environ", { | ||
"WEBSITE_SITE_NAME": TEST_WEBSITE_SITE_NAME, | ||
"REGION_NAME": TEST_REGION_NAME, | ||
"WEBSITE_SLOT_NAME": TEST_WEBSITE_SLOT_NAME, | ||
"WEBSITE_HOSTNAME": TEST_WEBSITE_HOSTNAME, | ||
"WEBSITE_INSTANCE_ID": TEST_WEBSITE_INSTANCE_ID, | ||
"WEBSITE_HOME_STAMPNAME": TEST_WEBSITE_HOME_STAMPNAME, | ||
"WEBSITE_OWNER_NAME": TEST_WEBSITE_OWNER_NAME, | ||
}, clear=True) | ||
def test_on_app_service_no_resource_group(self): | ||
resource = AzureAppServiceResourceDetector().detect() | ||
attributes = resource.attributes | ||
self.assertEqual(attributes["service.name"], TEST_WEBSITE_SITE_NAME) | ||
self.assertEqual(attributes["cloud.provider"], "azure") | ||
self.assertEqual(attributes["cloud.platform"], "azure_app_service") | ||
|
||
self.assertTrue("cloud.resource_id" not in attributes) | ||
|
||
self.assertEqual(attributes["cloud.region"], TEST_REGION_NAME) | ||
self.assertEqual(attributes["deployment.environment"], TEST_WEBSITE_SLOT_NAME) | ||
self.assertEqual(attributes["host.id"], TEST_WEBSITE_HOSTNAME) | ||
self.assertEqual(attributes["service.instance.id"], TEST_WEBSITE_INSTANCE_ID) | ||
self.assertEqual(attributes["azure.app.service.stamp"], TEST_WEBSITE_HOME_STAMPNAME) | ||
|
||
@patch.dict("os.environ", { | ||
"WEBSITE_SITE_NAME": TEST_WEBSITE_SITE_NAME, | ||
"REGION_NAME": TEST_REGION_NAME, | ||
"WEBSITE_SLOT_NAME": TEST_WEBSITE_SLOT_NAME, | ||
"WEBSITE_HOSTNAME": TEST_WEBSITE_HOSTNAME, | ||
"WEBSITE_INSTANCE_ID": TEST_WEBSITE_INSTANCE_ID, | ||
"WEBSITE_HOME_STAMPNAME": TEST_WEBSITE_HOME_STAMPNAME, | ||
"WEBSITE_OWNER_NAME": TEST_WEBSITE_OWNER_NAME, | ||
}, clear=True) | ||
def test_on_app_service_no_owner(self): | ||
resource = AzureAppServiceResourceDetector().detect() | ||
attributes = resource.attributes | ||
self.assertEqual(attributes["service.name"], TEST_WEBSITE_SITE_NAME) | ||
self.assertEqual(attributes["cloud.provider"], "azure") | ||
self.assertEqual(attributes["cloud.platform"], "azure_app_service") | ||
|
||
self.assertTrue("cloud.resource_id" not in attributes) | ||
|
||
self.assertEqual(attributes["cloud.region"], TEST_REGION_NAME) | ||
self.assertEqual(attributes["deployment.environment"], TEST_WEBSITE_SLOT_NAME) | ||
self.assertEqual(attributes["host.id"], TEST_WEBSITE_HOSTNAME) | ||
self.assertEqual(attributes["service.instance.id"], TEST_WEBSITE_INSTANCE_ID) | ||
self.assertEqual(attributes["azure.app.service.stamp"], TEST_WEBSITE_HOME_STAMPNAME) | ||
|
||
@patch.dict("os.environ", { | ||
"REGION_NAME": TEST_REGION_NAME, | ||
"WEBSITE_SLOT_NAME": TEST_WEBSITE_SLOT_NAME, | ||
"WEBSITE_HOSTNAME": TEST_WEBSITE_HOSTNAME, | ||
"WEBSITE_INSTANCE_ID": TEST_WEBSITE_INSTANCE_ID, | ||
"WEBSITE_HOME_STAMPNAME": TEST_WEBSITE_HOME_STAMPNAME, | ||
"WEBSITE_OWNER_NAME": TEST_WEBSITE_OWNER_NAME, | ||
}, clear=True) | ||
def test_off_app_service(self): | ||
resource = AzureAppServiceResourceDetector().detect() | ||
self.assertEqual(resource.attributes, {}) |