Compare commits
No commits in common. "3472e1767a68b9b316889518be762a321d91bcc3" and "6421edfc25047386ddf05fbe79fc97df40bcb3e5" have entirely different histories.
3472e1767a
...
6421edfc25
@ -1,7 +1,5 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
|
||||||
import time
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
@ -9,8 +7,6 @@ from flask import jsonify, request
|
|||||||
|
|
||||||
from . import settings
|
from . import settings
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class AriadneError(Exception):
|
class AriadneError(Exception):
|
||||||
def __init__(self, message: str, status_code: int = 502) -> None:
|
def __init__(self, message: str, status_code: int = 502) -> None:
|
||||||
@ -43,38 +39,17 @@ def request_raw(
|
|||||||
if not enabled():
|
if not enabled():
|
||||||
raise AriadneError("ariadne not configured", 503)
|
raise AriadneError("ariadne not configured", 503)
|
||||||
|
|
||||||
url = _url(path)
|
|
||||||
attempts = max(1, settings.ARIADNE_RETRY_COUNT)
|
|
||||||
for attempt in range(1, attempts + 1):
|
|
||||||
try:
|
try:
|
||||||
with httpx.Client(timeout=settings.ARIADNE_TIMEOUT_SEC) as client:
|
with httpx.Client(timeout=settings.ARIADNE_TIMEOUT_SEC) as client:
|
||||||
resp = client.request(
|
return client.request(
|
||||||
method,
|
method,
|
||||||
url,
|
_url(path),
|
||||||
headers=_auth_headers(),
|
headers=_auth_headers(),
|
||||||
json=payload,
|
json=payload,
|
||||||
params=params,
|
params=params,
|
||||||
)
|
)
|
||||||
if resp.status_code >= 500:
|
|
||||||
logger.warning(
|
|
||||||
"ariadne error response",
|
|
||||||
extra={"method": method, "path": path, "status": resp.status_code},
|
|
||||||
)
|
|
||||||
return resp
|
|
||||||
except httpx.RequestError as exc:
|
except httpx.RequestError as exc:
|
||||||
logger.warning(
|
|
||||||
"ariadne request failed",
|
|
||||||
extra={
|
|
||||||
"method": method,
|
|
||||||
"path": path,
|
|
||||||
"attempt": attempt,
|
|
||||||
"timeout_sec": settings.ARIADNE_TIMEOUT_SEC,
|
|
||||||
"error": str(exc),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
if attempt >= attempts:
|
|
||||||
raise AriadneError("ariadne unavailable", 502) from exc
|
raise AriadneError("ariadne unavailable", 502) from exc
|
||||||
time.sleep(settings.ARIADNE_RETRY_BACKOFF_SEC * attempt)
|
|
||||||
|
|
||||||
|
|
||||||
def proxy(
|
def proxy(
|
||||||
|
|||||||
@ -50,8 +50,6 @@ KEYCLOAK_ADMIN_REALM = os.getenv("KEYCLOAK_ADMIN_REALM", KEYCLOAK_REALM)
|
|||||||
|
|
||||||
ARIADNE_URL = os.getenv("ARIADNE_URL", "").strip()
|
ARIADNE_URL = os.getenv("ARIADNE_URL", "").strip()
|
||||||
ARIADNE_TIMEOUT_SEC = float(os.getenv("ARIADNE_TIMEOUT_SEC", "10"))
|
ARIADNE_TIMEOUT_SEC = float(os.getenv("ARIADNE_TIMEOUT_SEC", "10"))
|
||||||
ARIADNE_RETRY_COUNT = int(os.getenv("ARIADNE_RETRY_COUNT", "2"))
|
|
||||||
ARIADNE_RETRY_BACKOFF_SEC = float(os.getenv("ARIADNE_RETRY_BACKOFF_SEC", "0.2"))
|
|
||||||
|
|
||||||
ACCOUNT_ALLOWED_GROUPS = [
|
ACCOUNT_ALLOWED_GROUPS = [
|
||||||
g.strip()
|
g.strip()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user