feat(telemetry): expose compute pipeline stage metrics

This commit is contained in:
DCCONSTRUCTIONS
2026-07-29 01:53:31 +03:00
parent 783aa444ac
commit 79eb4b46f7
19 changed files with 1000 additions and 24 deletions
+51
View File
@@ -274,6 +274,57 @@ def test_worker_telemetry_prefers_ndc_container_names_during_migration(
assert triton["canonical_name"] == "ndc-mission-core-triton"
def test_agent_pipeline_snapshot_merges_all_stage_series() -> None:
samples = []
for stage_id, stage_state, elapsed, activations, share in (
("detector", "active", 2.5, 42, 62.5),
("semantic-model", "waiting", 1.5, 11, 37.5),
):
samples.append(
{
"node_id": EXPECTED_NODE_ID,
"kind": "pipeline",
"measurement": "missioncore_pipeline",
"observed_at_utc": "2026-07-28T12:00:00Z",
"payload": {
"name": "missioncore_pipeline",
"tags": {"stage_id": stage_id},
"fields": {
"service_state": "busy",
"current_stage": "detector",
"active_request_id": "request-006",
"active_frame_index": 17,
"completed_runs": 3,
"failed_runs": 0,
"model_load_seconds": 10.5,
"collector_state": "live",
"stage_state": stage_state,
"elapsed_seconds": elapsed,
"activations": activations,
"share_percent": share,
},
},
}
)
raw = _agent_raw_document({"samples": samples})
assert raw["perception"]["state"] == "busy"
assert raw["perception"]["active_stages"] == ["detector"]
assert raw["perception"]["stage_metrics"] == {
"detector": {
"elapsed_seconds": 2.5,
"activations": 42,
"share_percent": 62.5,
},
"semantic-model": {
"elapsed_seconds": 1.5,
"activations": 11,
"share_percent": 37.5,
},
}
def test_worker_telemetry_history_keeps_one_row_per_agent_observation(
tmp_path: Path,
) -> None:
@@ -181,6 +181,41 @@ def test_normalizer_preserves_native_pipeline_stage_tags() -> None:
}
def test_normalizer_accepts_telegraf_pipeline_snapshot() -> None:
normalizer = _normalizer()
row = normalizer._normalize(
"mission-core/v1/contours/worker-006/agents/worker-006/pipeline",
json.dumps(
{
"name": "missioncore_pipeline",
"tags": {
"node_id": "DESKTOP-OPJ8J04",
"contour_id": "worker-006",
"agent_id": "worker-006",
"stage_id": "detector",
},
"fields": {
"service_state": "busy",
"stage_state": "active",
"elapsed_seconds": 2.5,
"activations": 42,
},
"timestamp": 1_785_179_600,
}
).encode(),
)
assert row[1:8] == (
"worker-006",
"worker-006",
"DESKTOP-OPJ8J04",
"pipeline",
"missioncore_pipeline",
'{"stage_id":"detector"}',
"telegraf.metric-json/v1",
)
def test_normalizer_rejects_oversized_payload_and_series_identity() -> None:
normalizer = _normalizer()
with pytest.raises(ValueError, match="1 MiB"):