-
Notifications
You must be signed in to change notification settings - Fork 348
feat: Use float instead of int for GCE_METADATA_TIMEOUT #1481
Changes from 1 commit
03c0713
7100b59
1fe93bc
51e12cd
be068a5
f8007f2
b612a28
e2cf0a3
3f9460c
c5a45d9
6329ff2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,10 +53,7 @@ | |
|
|
||
| # Timeout in seconds to wait for the GCE metadata server when detecting the | ||
| # GCE environment. | ||
| try: | ||
| _METADATA_DEFAULT_TIMEOUT = int(os.getenv("GCE_METADATA_TIMEOUT", 3)) | ||
| except ValueError: # pragma: NO COVER | ||
| _METADATA_DEFAULT_TIMEOUT = 3 | ||
| _METADATA_DEFAULT_TIMEOUT = 3 | ||
|
|
||
| # Detect GCE Residency | ||
| _GOOGLE = "Google" | ||
|
|
@@ -119,6 +116,11 @@ def ping(request, timeout=_METADATA_DEFAULT_TIMEOUT, retry_count=3): | |
| # could lead to false negatives in the event that we are on GCE, but | ||
| # the metadata resolution was particularly slow. The latter case is | ||
| # "unlikely". | ||
| try: | ||
| timeout = float(os.getenv("GCE_METADATA_TIMEOUT", timeout)) | ||
| except ValueError: # pragma: NO COVER | ||
| pass | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not capture a ValueError here. Additionally, the timeout variable would not be usable, so the downstream call would have problems. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW the original code caught the ValueError. The value is set by the user.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case, can you remove the pragma, and include test coverage for this change? |
||
|
|
||
| retries = 0 | ||
| headers = _METADATA_HEADERS.copy() | ||
| headers[metrics.API_CLIENT_HEADER] = metrics.mds_ping() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.