This repository was archived by the owner on Sep 17, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
contrib/opencensus-ext-azure
opencensus/ext/azure/metrics_exporter/heartbeat_metrics Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -100,8 +100,9 @@ def get_azure_compute_metadata(self):
100100 try :
101101 request_url = "{0}?{1}&{2}" .format (
102102 _AIMS_URI , _AIMS_API_VERSION , _AIMS_FORMAT )
103- response = requests .get (request_url , headers = {"MetaData" : "True" })
104- except requests .exceptions .ConnectionError :
103+ response = requests .get (
104+ request_url , headers = {"MetaData" : "True" }, timeout = 5.0 )
105+ except (requests .exceptions .ConnectionError , requests .Timeout ):
105106 # Not in VM
106107 self .is_vm = False
107108 return False
Original file line number Diff line number Diff line change @@ -218,6 +218,17 @@ def test_heartbeat_metric_not_vm(self):
218218 keys = list (metric .properties .keys ())
219219 self .assertEqual (len (keys ), 2 )
220220
221+ def test_heartbeat_metric_not_vm_timeout (self ):
222+ with mock .patch (
223+ 'requests.get' ,
224+ throw (requests .Timeout )
225+ ):
226+ metric = heartbeat_metrics .HeartbeatMetric ()
227+ self .assertFalse (metric .is_vm )
228+ self .assertEqual (metric .NAME , 'Heartbeat' )
229+ keys = list (metric .properties .keys ())
230+ self .assertEqual (len (keys ), 2 )
231+
221232 def test_heartbeat_metric_vm_error_response (self ):
222233 with mock .patch ('requests.get' ) as get :
223234 get .return_value = MockResponse (
You can’t perform that action at this time.
0 commit comments