Skip to content

Commit b7aaf22

Browse files
feat: Show the transport exception that happened for GCE Metadata (#474)
Two primary motivators here: 1. Why obscure the exception? Sometimes it has some really useful information, such as the case when its being rate limited or throwing some internal error. Some of those responses have valuable information; and it's a public API so the contents of it are not a secret. 2. The metadata server should not be spewing failures that often; I think it would be good to know with `WARNING` when it happens since `WARNING` is the default and what a lot of people run with. When Metadata servers have issues overnight, we have no logs for those who left it as default. A good example of this is when the Metadata server is being rate limited; it would be good to know that's happening. Logs will help make that faster, though ideally of course maybe the library would have a result or something indicating the status of all checks (or something else so faults can be diagnosed faster?) but logs are cheap, easy and make diagnosing it a lot faster. It should be rare enough (correct me if I'm wrong?) that it should not be failing often enough except in the "resolution lag" case.
1 parent c8a7e30 commit b7aaf22

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

‎packages/google-auth/google/auth/compute_engine/_metadata.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ def ping(request, timeout=_METADATA_DEFAULT_TIMEOUT, retry_count=3):
9595
and metadata_flavor == _METADATA_FLAVOR_VALUE
9696
)
9797

98-
except exceptions.TransportError:
99-
_LOGGER.info(
100-
"Compute Engine Metadata server unavailable on" "attempt %s of %s",
98+
except exceptions.TransportError as e:
99+
_LOGGER.warning(
100+
"Compute Engine Metadata server unavailable on"
101+
"attempt %s of %s. Reason: %s",
101102
retries + 1,
102103
retry_count,
104+
e,
103105
)
104106
retries += 1
105107

@@ -144,11 +146,13 @@ def get(request, path, root=_METADATA_ROOT, recursive=False, retry_count=5):
144146
response = request(url=url, method="GET", headers=_METADATA_HEADERS)
145147
break
146148

147-
except exceptions.TransportError:
148-
_LOGGER.info(
149-
"Compute Engine Metadata server unavailable on" "attempt %s of %s",
149+
except exceptions.TransportError as e:
150+
_LOGGER.warning(
151+
"Compute Engine Metadata server unavailable on"
152+
"attempt %s of %s. Reason: %s",
150153
retries + 1,
151154
retry_count,
155+
e,
152156
)
153157
retries += 1
154158
else:

0 commit comments

Comments
 (0)