feat: 接入渲染灰度观测指标到compose_video和stream_copy
- compose_video 入口接入 render_task_metrics 上下文 自动记录:引擎选择、任务耗时、成功/失败、错误类型、活跃任务数 - unified_render_service 接入 stream_copy 埋点 三种状态:hit(命中直通)/ miss(条件不满足跳过)/ fallback(失败回退) miss 原因归一化为8类:编码/分辨率/帧率/字幕/像素格式/裁剪/多片段/其他
This commit is contained in:
@@ -728,6 +728,10 @@ class UnifiedRenderService:
|
||||
self.plan.id,
|
||||
reason,
|
||||
)
|
||||
# 灰度观测:stream_copy 未命中
|
||||
from video_processing.render_metrics import classify_stream_copy_miss_reason, record_stream_copy
|
||||
miss_reason = classify_stream_copy_miss_reason(reason)
|
||||
record_stream_copy("miss", miss_reason)
|
||||
return False
|
||||
|
||||
# 构建 copy 命令
|
||||
@@ -784,9 +788,15 @@ class UnifiedRenderService:
|
||||
self.plan.id,
|
||||
output_path.stat().st_size,
|
||||
)
|
||||
# 灰度观测:stream_copy 命中成功
|
||||
from video_processing.render_metrics import record_stream_copy
|
||||
record_stream_copy("hit", "成功")
|
||||
return True
|
||||
else:
|
||||
logger.warning("[unified-render] stream_copy 输出为空: plan_id=%s", self.plan.id)
|
||||
# 灰度观测:stream_copy 失败回退(输出为空)
|
||||
from video_processing.render_metrics import record_stream_copy
|
||||
record_stream_copy("fallback", "输出为空")
|
||||
return False
|
||||
except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e:
|
||||
logger.warning(
|
||||
@@ -794,6 +804,9 @@ class UnifiedRenderService:
|
||||
self.plan.id,
|
||||
str(e)[:200],
|
||||
)
|
||||
# 灰度观测:stream_copy 失败回退(ffmpeg错误)
|
||||
from video_processing.render_metrics import record_stream_copy
|
||||
record_stream_copy("fallback", "ffmpeg失败")
|
||||
# 清理可能的损坏输出文件
|
||||
if output_path.exists():
|
||||
try:
|
||||
|
||||
@@ -63,15 +63,30 @@ def compose_video(self, job_id: str, **kwargs):
|
||||
# 判断使用哪个渲染引擎
|
||||
# 优先级:Redis Feature Flag(白名单 > 百分比) > 环境变量默认
|
||||
from video_processing.render_engine_resolver import get_render_engine_resolver
|
||||
from video_processing.render_metrics import render_task_metrics
|
||||
|
||||
resolver = get_render_engine_resolver()
|
||||
user_id = job.created_by_user_id or None
|
||||
engine = resolver.get_engine(user_id=user_id)
|
||||
# 灰度期间打印详细 flag 配置,便于排查
|
||||
config = resolver.get_config_snapshot()
|
||||
logger.info(
|
||||
"compose_video 引擎选择: job_id=%s engine=%s user_id=%s enabled=%s percentage=%s whitelist=%d default=%s",
|
||||
job_id,
|
||||
engine,
|
||||
user_id,
|
||||
config.get("enabled"),
|
||||
config.get("percentage"),
|
||||
len(config.get("whitelist", [])),
|
||||
config.get("default_engine"),
|
||||
)
|
||||
|
||||
if engine == "unified":
|
||||
return _compose_with_unified_engine(self, job_service, job, plan_id, db)
|
||||
else:
|
||||
return _compose_with_legacy_engine(self, job_service, job, plan_id, db)
|
||||
# 灰度观测指标埋点
|
||||
with render_task_metrics(engine=engine, task_type="compose_video"):
|
||||
if engine == "unified":
|
||||
return _compose_with_unified_engine(self, job_service, job, plan_id, db)
|
||||
else:
|
||||
return _compose_with_legacy_engine(self, job_service, job, plan_id, db)
|
||||
|
||||
except self.retry_exc as exc:
|
||||
logger.warning("视频合成重试中: job_id=%s, exc=%s", job_id, exc)
|
||||
|
||||
Reference in New Issue
Block a user