feat(telemetry): add bounded native pipeline lifecycle
This commit is contained in:
@@ -13,6 +13,7 @@ from k1link.compute.pipeline_telemetry import (
|
||||
PipelineTelemetryEmitter,
|
||||
PipelineTelemetryError,
|
||||
PipelineTelemetryIdentity,
|
||||
build_pipeline_run_telemetry_document,
|
||||
build_pipeline_telemetry_document,
|
||||
)
|
||||
|
||||
@@ -59,6 +60,7 @@ def test_pipeline_document_is_accepted_without_losing_stage_identity() -> None:
|
||||
stage_id="predict",
|
||||
state="completed",
|
||||
duration_ms=125.5,
|
||||
activation_count=7,
|
||||
input_count=89,
|
||||
output_count=89,
|
||||
queue_wait_ms=2.25,
|
||||
@@ -89,9 +91,51 @@ def test_pipeline_document_is_accepted_without_losing_stage_identity() -> None:
|
||||
}
|
||||
stored = json.loads(row[13])
|
||||
assert stored["payload"]["event"]["duration_ms"] == 125.5
|
||||
assert stored["payload"]["event"]["activation_count"] == 7
|
||||
assert stored["payload"]["stage_metrics"]["predict"]["activations"] == 7
|
||||
assert stored["authority"]["commands_enabled"] is False
|
||||
|
||||
|
||||
def test_telegraf_tail_wrapper_restores_the_native_pipeline_document() -> None:
|
||||
identity = _identity()
|
||||
native = build_pipeline_telemetry_document(
|
||||
identity=identity,
|
||||
stage_id="tracking",
|
||||
state="completed",
|
||||
duration_ms=4.25,
|
||||
observed_at_utc="2026-07-28T12:00:00Z",
|
||||
)
|
||||
record = {
|
||||
"schema_version": "missioncore.pipeline-telemetry-record/v1",
|
||||
"topic": identity.topic,
|
||||
"payload": native,
|
||||
}
|
||||
telegraf = {
|
||||
"name": "missioncore_pipeline_event",
|
||||
"timestamp": 1785240000,
|
||||
"tags": {
|
||||
"agent_id": identity.agent_id,
|
||||
"contour_id": identity.contour_id,
|
||||
"node_id": identity.node_id,
|
||||
},
|
||||
"fields": {
|
||||
"value": json.dumps(record, separators=(",", ":")),
|
||||
},
|
||||
}
|
||||
|
||||
row = _normalizer()._normalize(identity.topic, json.dumps(telegraf).encode())
|
||||
|
||||
assert row[5] == "pipeline"
|
||||
assert row[7] == "missioncore.agent-pipeline-telemetry/v1"
|
||||
assert row[9:13] == ("E41", "run-001", "request-001", 17)
|
||||
assert json.loads(row[13]) == native
|
||||
|
||||
record["topic"] = "mission-core/v1/contours/other/agents/other/pipeline"
|
||||
telegraf["fields"]["value"] = json.dumps(record)
|
||||
with pytest.raises(ValueError, match="pipeline event record"):
|
||||
_normalizer()._normalize(identity.topic, json.dumps(telegraf).encode())
|
||||
|
||||
|
||||
def test_stage_context_emits_terminal_event_and_preserves_failure() -> None:
|
||||
published: list[tuple[str, dict[str, object]]] = []
|
||||
|
||||
@@ -131,6 +175,42 @@ def test_stage_context_emits_terminal_event_and_preserves_failure() -> None:
|
||||
assert "source failure" not in json.dumps(published[-1][1])
|
||||
|
||||
|
||||
def test_run_events_record_explicit_terminal_outcome() -> None:
|
||||
identity = _identity()
|
||||
started = build_pipeline_run_telemetry_document(
|
||||
identity=identity,
|
||||
state="started",
|
||||
observed_at_utc="2026-07-28T12:00:00Z",
|
||||
)
|
||||
completed = build_pipeline_run_telemetry_document(
|
||||
identity=identity,
|
||||
state="completed",
|
||||
duration_ms=12_345.5,
|
||||
exit_code=2,
|
||||
observed_at_utc="2026-07-28T12:00:12Z",
|
||||
)
|
||||
|
||||
assert started["payload"]["state"] == "busy"
|
||||
assert started["payload"]["active_request_id"] == "request-001"
|
||||
assert completed["event_type"] == "run"
|
||||
assert completed["run_state"] == "completed"
|
||||
assert completed["payload"]["active_request_id"] is None
|
||||
assert completed["payload"]["event"] == {
|
||||
"event_type": "run",
|
||||
"state": "completed",
|
||||
"duration_ms": 12_345.5,
|
||||
"exit_code": 2,
|
||||
"error_type": None,
|
||||
}
|
||||
|
||||
with pytest.raises(PipelineTelemetryError, match="completed run"):
|
||||
build_pipeline_run_telemetry_document(
|
||||
identity=identity,
|
||||
state="completed",
|
||||
duration_ms=1.0,
|
||||
)
|
||||
|
||||
|
||||
def test_jsonl_sink_records_topic_bound_documents(tmp_path: Path) -> None:
|
||||
path = tmp_path / "telemetry" / "e41.jsonl"
|
||||
identity = _identity()
|
||||
|
||||
Reference in New Issue
Block a user