Reduce polling and batch observation writes
This commit is contained in:
@@ -156,7 +156,7 @@ def get_auth_me_payload(request: Request) -> Dict[str, Any]:
|
||||
lambda: legacy_routes.SUPABASE_ENTITLEMENT.get_subscription_window(
|
||||
user_id,
|
||||
respect_requirement=False,
|
||||
bypass_cache=True,
|
||||
bypass_cache=False,
|
||||
unknown_on_error=True,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import threading
|
||||
import time
|
||||
@@ -14,6 +15,14 @@ from loguru import logger
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
def _slow_stage_threshold_ms() -> float:
|
||||
raw = str(os.getenv("POLYWEATHER_SLOW_STAGE_LOG_MS") or "1500").strip()
|
||||
try:
|
||||
return max(0.0, float(raw))
|
||||
except (TypeError, ValueError):
|
||||
return 1500.0
|
||||
|
||||
|
||||
class ServerTimingRecorder:
|
||||
def __init__(
|
||||
self,
|
||||
@@ -71,6 +80,20 @@ class ServerTimingRecorder:
|
||||
status_code,
|
||||
dict(self.timings_ms),
|
||||
)
|
||||
threshold = _slow_stage_threshold_ms()
|
||||
slow_stages = {
|
||||
stage: duration
|
||||
for stage, duration in dict(self.timings_ms).items()
|
||||
if duration >= threshold
|
||||
}
|
||||
if slow_stages:
|
||||
logger.warning(
|
||||
"slow_request_timing log_name={} outcome={} status_code={} slow_stages={}",
|
||||
self.log_name,
|
||||
outcome,
|
||||
status_code,
|
||||
slow_stages,
|
||||
)
|
||||
|
||||
def _metric_name(self, stage: str) -> str:
|
||||
raw = f"{self.prefix}_{stage}"
|
||||
|
||||
Reference in New Issue
Block a user