From 99156d97df074bc73ad5f08812edfac33ddc0a2c Mon Sep 17 00:00:00 2001 From: Oddball <81461658+oddballfr@users.noreply.github.com> Date: Fri, 31 Jul 2026 13:26:57 +0000 Subject: [PATCH] Update api_healthcheck.py Fix snuba-api healthcheck bypassing proxy for local requests (urllib NO_PROXY doesn't support CIDR ranges) --- snuba/api_healthcheck.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/snuba/api_healthcheck.py b/snuba/api_healthcheck.py index dc5dd74340f..b832707c1d5 100755 --- a/snuba/api_healthcheck.py +++ b/snuba/api_healthcheck.py @@ -25,10 +25,17 @@ URL = os.environ.get("SNUBA_API_HEALTHCHECK_URL") or "http://127.0.0.1:1218/health" TIMEOUT = float(os.environ.get("SNUBA_API_HEALTHCHECK_TIMEOUT") or 2) +# This is a local, in-container request. urllib's NO_PROXY matching doesn't +# support CIDR ranges (e.g. 127.0.0.0/8), only exact hosts/domain suffixes, +# so a NO_PROXY set up for other tools (curl, wget) can still leave this +# request routed through HTTP(S)_PROXY. Force no proxy explicitly instead +# of relying on NO_PROXY parsing. +_NO_PROXY_OPENER = urllib.request.build_opener(urllib.request.ProxyHandler({})) + def main() -> int: try: - body = urllib.request.urlopen(URL, timeout=TIMEOUT).read().decode() + body = _NO_PROXY_OPENER.open(URL, timeout=TIMEOUT).read().decode() except urllib.error.HTTPError as exc: print(f"snuba api returned HTTP {exc.code} from {URL}", file=sys.stderr) return 1