feat(telemetry): expose compute pipeline stage metrics
This commit is contained in:
@@ -474,11 +474,57 @@ def _agent_raw_document(document: dict[str, Any]) -> dict[str, Any]:
|
||||
}
|
||||
docker_stats: dict[str, dict[str, str]] = raw["docker_stats"]
|
||||
container_states: dict[str, dict[str, object]] = raw["container_states"]
|
||||
perception: dict[str, Any] = raw["perception"]
|
||||
pipeline_stage_metrics: dict[str, dict[str, Any]] = {}
|
||||
pipeline_active_stages: set[str] = set()
|
||||
for sample in samples:
|
||||
measurement = sample.get("measurement")
|
||||
payload, fields, tags = _metric_payload(sample)
|
||||
if sample.get("kind") == "pipeline":
|
||||
raw["perception"] = _mapping(payload.get("payload")) or payload
|
||||
if measurement == "missioncore_pipeline":
|
||||
stage_id = tags.get("stage_id")
|
||||
if isinstance(stage_id, str) and stage_id:
|
||||
stage_state = fields.get("stage_state")
|
||||
if stage_state == "active":
|
||||
pipeline_active_stages.add(stage_id)
|
||||
pipeline_stage_metrics[stage_id] = {
|
||||
"elapsed_seconds": _number(fields.get("elapsed_seconds")),
|
||||
"activations": fields.get("activations"),
|
||||
"share_percent": _number(fields.get("share_percent")),
|
||||
}
|
||||
for name in (
|
||||
"service_state",
|
||||
"current_stage",
|
||||
"active_request_id",
|
||||
):
|
||||
value = fields.get(name)
|
||||
if isinstance(value, str):
|
||||
perception[name if name != "service_state" else "state"] = (
|
||||
value or None
|
||||
)
|
||||
for name in ("active_frame_index", "completed_runs", "failed_runs"):
|
||||
value = fields.get(name)
|
||||
if isinstance(value, int) and not isinstance(value, bool):
|
||||
perception[name] = value if value >= 0 else None
|
||||
model_load_seconds = _number(fields.get("model_load_seconds"))
|
||||
if model_load_seconds is not None:
|
||||
perception["model_load_seconds"] = model_load_seconds
|
||||
perception["collector_state"] = fields.get("collector_state")
|
||||
else:
|
||||
pipeline_payload = _mapping(payload.get("payload")) or payload
|
||||
for name, value in pipeline_payload.items():
|
||||
if name == "stage_metrics":
|
||||
for stage_id, metrics in _mapping(value).items():
|
||||
if isinstance(metrics, dict):
|
||||
pipeline_stage_metrics[stage_id] = metrics
|
||||
elif name == "active_stages":
|
||||
pipeline_active_stages.update(
|
||||
stage_id
|
||||
for stage_id in _items(value)
|
||||
if isinstance(stage_id, str)
|
||||
)
|
||||
else:
|
||||
perception[name] = value
|
||||
continue
|
||||
if sample.get("kind") == "runtime":
|
||||
runtime_payload = _mapping(payload.get("payload")) or payload
|
||||
@@ -610,6 +656,10 @@ def _agent_raw_document(document: dict[str, Any]) -> dict[str, Any]:
|
||||
"version": None,
|
||||
"uptime_seconds": uptime,
|
||||
}
|
||||
if pipeline_stage_metrics:
|
||||
perception["stage_metrics"] = pipeline_stage_metrics
|
||||
if pipeline_active_stages:
|
||||
perception["active_stages"] = sorted(pipeline_active_stages)
|
||||
return raw
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user