Skip to content

Commit

Permalink
try catch RequestException
Browse files Browse the repository at this point in the history
  • Loading branch information
stanley-cheung committed Feb 8, 2024
1 parent b9caa33 commit 3ab0f31
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tests/gamma/csm_observability_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from google.api_core import retry as gapi_retries
from google.cloud import monitoring_v3
import requests
from requests.exceptions import RequestException
import yaml

from framework import xds_gamma_testcase
Expand Down Expand Up @@ -488,10 +489,16 @@ def ping_gmp_endpoint(
A helper function to ping the GMP endpoint to get what GMP sees
from the OTel exporter before passing metrics to Cloud Monitoring.
"""
gmp_log = requests.get(
f"http://{monitoring_host}:{monitoring_port}/metrics"
)
return "\n".join(gmp_log.text.splitlines())
try:
gmp_log = requests.get(
f"http://{monitoring_host}:{monitoring_port}/metrics"
)
return "\n".join(gmp_log.text.splitlines())
except RequestException as e:
logger.error("Http request to GMP endpoint failed: %r", e)
# It's OK the caller will receive nothing in case of an exception.
# Caller can continue.
return ""


if __name__ == "__main__":
Expand Down

0 comments on commit 3ab0f31

Please sign in to comment.