Skip to content

Commit

Permalink
feat: Show the transport exception that happened for GCE Metadata (#474)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hilts-vaughan authored Jul 21, 2020
1 parent 18d5ae6 commit 23919bb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions google/auth/compute_engine/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ def ping(request, timeout=_METADATA_DEFAULT_TIMEOUT, retry_count=3):
and metadata_flavor == _METADATA_FLAVOR_VALUE
)

except exceptions.TransportError:
_LOGGER.info(
"Compute Engine Metadata server unavailable on" "attempt %s of %s",
except exceptions.TransportError as e:
_LOGGER.warning(
"Compute Engine Metadata server unavailable on"
"attempt %s of %s. Reason: %s",
retries + 1,
retry_count,
e,
)
retries += 1

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

except exceptions.TransportError:
_LOGGER.info(
"Compute Engine Metadata server unavailable on" "attempt %s of %s",
except exceptions.TransportError as e:
_LOGGER.warning(
"Compute Engine Metadata server unavailable on"
"attempt %s of %s. Reason: %s",
retries + 1,
retry_count,
e,
)
retries += 1
else:
Expand Down

0 comments on commit 23919bb

Please # to comment.