Skip to content

Commit

Permalink
Add 10 second timeout to VM Resource Detector (#2119)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydvoss authored Jan 9, 2024
1 parent 14d7779 commit 588d5d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
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
12 changes: 6 additions & 6 deletions resource/opentelemetry-resource-detector-azure/tests/test_vm.py
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)

0 comments on commit 588d5d7

Please sign in to comment.