feat(system): instrument worker pipeline stages

This commit is contained in:
DCCONSTRUCTIONS
2026-07-27 21:41:40 +03:00
parent 67e12a47a4
commit 667db00b52
10 changed files with 446 additions and 152 deletions
+33 -8
View File
@@ -499,6 +499,12 @@ def _pipeline_document(raw: dict[str, Any]) -> dict[str, Any]:
current_stage = perception.get("current_stage")
if not isinstance(current_stage, str):
current_stage = None
active_stages = {
value
for value in _items(perception.get("active_stages"))
if isinstance(value, str)
}
stage_metrics = _mapping(perception.get("stage_metrics"))
busy = perception.get("state") == "busy"
stages = (
("source-ingress", "Приём сенсорного потока"),
@@ -517,6 +523,8 @@ def _pipeline_document(raw: dict[str, Any]) -> dict[str, Any]:
return "unavailable"
if not busy:
return "ready"
if active_stages:
return "active" if stage_id in active_stages else "waiting"
if stage_id == current_stage or stage_id in {
"source-ingress",
"camera-decode",
@@ -525,6 +533,30 @@ def _pipeline_document(raw: dict[str, Any]) -> dict[str, Any]:
return "active"
return "waiting"
def stage_document(stage_id: str, label: str) -> dict[str, Any]:
raw_metric = _mapping(stage_metrics.get(stage_id))
elapsed_seconds = _number(raw_metric.get("elapsed_seconds"))
share_percent = _number(raw_metric.get("share_percent"))
activations = raw_metric.get("activations")
return {
"id": stage_id,
"label": label,
"state": stage_state(stage_id),
"elapsed_seconds": (
max(0.0, elapsed_seconds) if elapsed_seconds is not None else None
),
"share_percent": (
min(100.0, max(0.0, share_percent))
if share_percent is not None
else None
),
"activations": (
max(0, int(activations))
if isinstance(activations, int) and not isinstance(activations, bool)
else None
),
}
return {
"service_state": (
perception.get("state") if isinstance(perception.get("state"), str) else "unavailable"
@@ -551,14 +583,7 @@ def _pipeline_document(raw: dict[str, Any]) -> dict[str, Any]:
else None
),
"model_load_seconds": _number(perception.get("model_load_seconds")),
"stages": [
{
"id": stage_id,
"label": label,
"state": stage_state(stage_id),
}
for stage_id, label in stages
],
"stages": [stage_document(stage_id, label) for stage_id, label in stages],
}