Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 10 second timeout to VM Resource Detector #2119

Merged
merged 4 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- `opentelemetry-resource-detector-azure` Added 10s timeout to VM Resource Detector
([#2119](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2119))

## Version 1.22.0/0.43b0 (2023-12-14)

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def get_azure_vm_metadata(self): # pylint: disable=no-self-use
request = Request(_AZURE_VM_METADATA_ENDPOINT)
request.add_header("Metadata", "True")
try:
with urlopen(request).read() as response:
return loads(response)
with urlopen(request, timeout=10) as response:
return loads(response.read())
except URLError:
# Not on Azure VM
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,18 @@
class TestAzureVMResourceDetector(unittest.TestCase):
@patch("opentelemetry.resource.detector.azure.vm.urlopen")
def test_linux(self, mock_urlopen):
mock_open = Mock()
mock_urlopen.return_value = mock_open
mock_open.read.return_value = LINUX_JSON
mock_response = Mock()
mock_urlopen.return_value = mock_response
mock_response.read.return_value = LINUX_JSON
attributes = AzureVMResourceDetector().detect().attributes
for attribute_key, attribute_value in LINUX_ATTRIBUTES.items():
self.assertEqual(attributes[attribute_key], attribute_value)

@patch("opentelemetry.resource.detector.azure.vm.urlopen")
def test_windows(self, mock_urlopen):
mock_open = Mock()
mock_urlopen.return_value = mock_open
mock_open.read.return_value = WINDOWS_JSON
mock_response = Mock()
mock_urlopen.return_value = mock_response
mock_response.read.return_value = WINDOWS_JSON
attributes = AzureVMResourceDetector().detect().attributes
for attribute_key, attribute_value in LINUX_ATTRIBUTES.items():
self.assertEqual(attributes[attribute_key], attribute_value)
Loading