History is kept by flow id: runs, cascades, rollups and events file the id in their flow column and nodes as <flow id>.<node>, the API answers flow plus flow_name and shows and takes nodes as <key>.<node>; events carry flow_id from the moment they are published; run queue items, the stage cache and cached curves keep ids and keys apart; endpoints, the brain graph, device bindings and search name the id to open

This commit is contained in:
2026-11-02 19:01:19 +01:00
parent e6027af8fe
commit d4a1b1db47
34 changed files with 1374 additions and 329 deletions
+28 -20
View File
@@ -16,7 +16,7 @@ def _seed(db: Session) -> None:
now = datetime.now(UTC).replace(second=0, microsecond=0)
db.add(
MetricBucket(
flow=FLOW,
flow_id=FLOW,
node=f"{FLOW}.calc",
bucket=now - timedelta(minutes=1),
executions=4,
@@ -33,20 +33,24 @@ def _seed(db: Session) -> None:
EngineEvent(
ts=now,
type="node_error",
flow=FLOW,
flow_id=FLOW,
node=f"{FLOW}.calc",
detail="ValueError: bad input\nTraceback",
)
)
db.add(
EngineEvent(
ts=now, type="audit", flow=FLOW, detail="published", actor="a@example.com"
ts=now,
type="audit",
flow_id=FLOW,
detail="published",
actor="a@example.com",
)
)
db.add(
FlowRun(
id="9-0",
flow=FLOW,
flow_id=FLOW,
source="external",
started_at=now,
finished_at=now,
@@ -208,7 +212,7 @@ def test_the_timeseries_folds_into_the_requested_bucket(
for offset, executions in ((0, 1), (2, 2), (5, 4), (15, 8)):
db.add(
MetricBucket(
flow=flow,
flow_id=flow,
node=f"{flow}.calc",
bucket=first + timedelta(minutes=offset),
executions=executions,
@@ -242,7 +246,7 @@ def test_the_bucket_still_filling_is_held_back(
for offset, executions in ((-60, 3), (0, 1)):
db.add(
MetricBucket(
flow=flow,
flow_id=flow,
node=f"{flow}.calc",
bucket=datetime.fromtimestamp(minute + offset, UTC),
executions=executions,
@@ -289,7 +293,7 @@ def test_the_runs_page_carries_its_total(
db.add(
FlowRun(
id=f"paged-{index}",
flow=FLOW,
flow_id=FLOW,
started_at=minute + timedelta(seconds=index),
status="ok",
)
@@ -315,11 +319,11 @@ def test_runs_narrow_to_one_minute(
) -> None:
"""A minute picked off a chart reaches past what the recent list holds."""
minute = datetime.now(UTC).replace(second=0, microsecond=0) - timedelta(hours=3)
db.add(FlowRun(id="minute-in", flow=FLOW, started_at=minute, status="ok"))
db.add(FlowRun(id="minute-in", flow_id=FLOW, started_at=minute, status="ok"))
db.add(
FlowRun(
id="minute-after",
flow=FLOW,
flow_id=FLOW,
started_at=minute + timedelta(minutes=1),
status="ok",
)
@@ -345,7 +349,7 @@ def test_a_running_cascade_reports_how_long_it_has_been_going(
) -> None:
"""The collector writes a duration at the end; until then, time since."""
started = datetime.now(UTC) - timedelta(seconds=30)
db.add(FlowRun(id="in-flight", flow=FLOW, started_at=started, status="running"))
db.add(FlowRun(id="in-flight", flow_id=FLOW, started_at=started, status="running"))
db.commit()
runs = client.get(
@@ -363,12 +367,12 @@ def test_events_narrow_to_one_minute(
) -> None:
"""The failures list reaches as far back as the charts beside it."""
minute = datetime.now(UTC).replace(second=0, microsecond=0) - timedelta(hours=4)
db.add(EngineEvent(ts=minute, type="node_error", flow=FLOW, detail="minute-in"))
db.add(EngineEvent(ts=minute, type="node_error", flow_id=FLOW, detail="minute-in"))
db.add(
EngineEvent(
ts=minute + timedelta(minutes=1),
type="node_error",
flow=FLOW,
flow_id=FLOW,
detail="minute-after",
)
)
@@ -394,16 +398,18 @@ def test_events_narrow_to_one_run(
"""Reading one run's failures without filtering the engine-wide list."""
ts = datetime.now(UTC) - timedelta(hours=6)
db.add(
EngineEvent(ts=ts, type="node_error", flow=FLOW, detail="mine", run="run-mine")
EngineEvent(
ts=ts, type="node_error", flow_id=FLOW, detail="mine", run="run-mine"
)
)
db.add(
EngineEvent(
ts=ts, type="node_error", flow=FLOW, detail="theirs", run="run-theirs"
ts=ts, type="node_error", flow_id=FLOW, detail="theirs", run="run-theirs"
)
)
# What a live cascade unrelated to any run leaves, and what every row
# written before the column existed looks like.
db.add(EngineEvent(ts=ts, type="node_error", flow=FLOW, detail="neither"))
db.add(EngineEvent(ts=ts, type="node_error", flow_id=FLOW, detail="neither"))
db.commit()
events = client.get(
@@ -423,7 +429,7 @@ def test_a_timeseries_window_can_be_named(
for minute in range(4):
db.add(
MetricBucket(
flow="windowed",
flow_id="windowed",
node="windowed.n",
bucket=base + timedelta(minutes=minute),
executions=1,
@@ -553,7 +559,7 @@ def test_a_superuser_can_flush_the_collector_now(
written = db.exec(
select(EngineEvent).where(
EngineEvent.flow == FLOW, EngineEvent.detail == "flushed"
EngineEvent.flow_id == FLOW, EngineEvent.detail == "flushed"
)
).all()
assert len(written) == 1
@@ -564,12 +570,14 @@ def test_execution_time_is_summed_per_node_type(
) -> None:
from fluksio.flow.schemas import FlowDef, NodeDef
flow = "node_type_test"
# Rows name a node by its flow's id, which here is not its key.
flow, key = "x_node_type_test", "node_type_test"
controller = client.app.state.flow_controller
before = controller.store.read_all
controller.store.read_all = lambda: [
FlowDef(
name=flow,
id=flow,
name=key,
nodes=[
NodeDef(id="a", type="python"),
NodeDef(id="b", type="python"),
@@ -587,7 +595,7 @@ def test_execution_time_is_summed_per_node_type(
):
db.add(
MetricBucket(
flow=flow,
flow_id=flow,
node=f"{flow}.{node}",
bucket=now - timedelta(minutes=2),
executions=executions,