fix(douyu): 修复斗鱼链路 P0/P1 隐患并增强 P2 运维队列可观测性
This commit is contained in:
@@ -155,19 +155,21 @@ def _get_local_exit_ip() -> str | None:
|
||||
"https://4.ipw.cn",
|
||||
"https://api.ipify.org",
|
||||
]
|
||||
for url in targets:
|
||||
try:
|
||||
response = requests.get(
|
||||
url, timeout=8, headers={"User-Agent": "Mozilla/5.0"}
|
||||
)
|
||||
response.raise_for_status()
|
||||
text = response.text.strip()
|
||||
match = re.search(r"(\d{1,3}(?:\.\d{1,3}){3})", text)
|
||||
if match:
|
||||
return match.group(1)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
logger.debug(f"本机出口 IP 查询失败: {url}: {exc}")
|
||||
continue
|
||||
with requests.Session() as sess:
|
||||
sess.trust_env = False
|
||||
for url in targets:
|
||||
try:
|
||||
with sess.get(
|
||||
url, timeout=8, headers={"User-Agent": "Mozilla/5.0"}
|
||||
) as response:
|
||||
response.raise_for_status()
|
||||
text = response.text.strip()
|
||||
match = re.search(r"(\d{1,3}(?:\.\d{1,3}){3})", text)
|
||||
if match:
|
||||
return match.group(1)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
logger.debug(f"本机出口 IP 查询失败: {url}: {exc}")
|
||||
continue
|
||||
return None
|
||||
|
||||
|
||||
@@ -179,26 +181,28 @@ def get_exit_ip_via_proxy(proxy: str) -> str | None:
|
||||
"https://4.ipw.cn",
|
||||
]
|
||||
proxies = {"http": proxy, "https": proxy}
|
||||
for url in targets:
|
||||
try:
|
||||
response = requests.get(
|
||||
url,
|
||||
proxies=proxies,
|
||||
timeout=6,
|
||||
headers={"User-Agent": "Mozilla/5.0"},
|
||||
)
|
||||
response.raise_for_status()
|
||||
content_type = response.headers.get("content-type", "").lower()
|
||||
if "json" in content_type:
|
||||
data = response.json()
|
||||
ip = data.get("ip") or data.get("origin")
|
||||
if ip:
|
||||
return str(ip).split(",")[0].strip()
|
||||
text = response.text.strip()
|
||||
match = re.search(r"(\d{1,3}(?:\.\d{1,3}){3})", text)
|
||||
if match:
|
||||
return match.group(1)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
logger.debug(f"代理出口 IP 查询失败: {url}: {exc}")
|
||||
continue
|
||||
with requests.Session() as sess:
|
||||
sess.trust_env = False
|
||||
for url in targets:
|
||||
try:
|
||||
with sess.get(
|
||||
url,
|
||||
proxies=proxies,
|
||||
timeout=6,
|
||||
headers={"User-Agent": "Mozilla/5.0"},
|
||||
) as response:
|
||||
response.raise_for_status()
|
||||
content_type = response.headers.get("content-type", "").lower()
|
||||
if "json" in content_type:
|
||||
data = response.json()
|
||||
ip = data.get("ip") or data.get("origin")
|
||||
if ip:
|
||||
return str(ip).split(",")[0].strip()
|
||||
text = response.text.strip()
|
||||
match = re.search(r"(\d{1,3}(?:\.\d{1,3}){3})", text)
|
||||
if match:
|
||||
return match.group(1)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
logger.debug(f"代理出口 IP 查询失败: {url}: {exc}")
|
||||
continue
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user