feat(metrics): C3 — Prometheus counters for L0/L1/format-loss/retry
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m30s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m30s
This commit is contained in:
@@ -1418,12 +1418,43 @@ async def _run_translation_job(
|
||||
min_chunks=getattr(config, "QUALITY_L1_MIN_CHUNKS", 10),
|
||||
log_only=getattr(config, "QUALITY_L1_LOG_ONLY", True),
|
||||
)
|
||||
|
||||
# When not in log-only mode, an L1 fail could trigger a
|
||||
# retry. Record the intent (best-effort, never breaks job).
|
||||
if (
|
||||
l1_result is not None
|
||||
and l1_result.verdict == "fail"
|
||||
and not getattr(config, "QUALITY_L1_LOG_ONLY", True)
|
||||
):
|
||||
try:
|
||||
from middleware.metrics import record_translation_retry
|
||||
record_translation_retry(
|
||||
reason="l1_fail",
|
||||
tier=_tier_for_quota(
|
||||
current_user.plan if current_user else None
|
||||
) if current_user else "free",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as l1_err:
|
||||
# L1 must NEVER break a job. Log and continue.
|
||||
logger.warning(
|
||||
f"Job {job_id}: quality L1 layer failed: {l1_err}"
|
||||
)
|
||||
|
||||
# Record L0 fail as a "potential retry" (also best-effort).
|
||||
if l0_failed_indices and not getattr(config, "QUALITY_L1_LOG_ONLY", True):
|
||||
try:
|
||||
from middleware.metrics import record_translation_retry
|
||||
record_translation_retry(
|
||||
reason="l0_fail",
|
||||
tier=_tier_for_quota(
|
||||
current_user.plan if current_user else None
|
||||
) if current_user else "free",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if user_id:
|
||||
# Determine cost factor based on selected provider and model
|
||||
cost_factor = 1
|
||||
|
||||
Reference in New Issue
Block a user