Home charts execution time per node type on a log scale, from a /observability/node-types rollup
This commit is contained in:
@@ -86,6 +86,17 @@ class FlowRollup(BaseModel):
|
||||
last_error_ts: float | None = None
|
||||
|
||||
|
||||
class NodeTypeTiming(BaseModel):
|
||||
"""How long one kind of node takes to run, across every node of it."""
|
||||
|
||||
type: str
|
||||
#: How many published nodes of this type ran inside the window.
|
||||
nodes: int
|
||||
executions: int
|
||||
avg_ms: float
|
||||
max_ms: float
|
||||
|
||||
|
||||
class RunRow(BaseModel):
|
||||
id: str
|
||||
flow: str
|
||||
@@ -428,6 +439,58 @@ def read_flow_rollups(
|
||||
]
|
||||
|
||||
|
||||
@router.get("/node-types", response_model=list[NodeTypeTiming])
|
||||
def read_node_type_timings(
|
||||
session: SessionDep,
|
||||
controller: FlowControllerDep,
|
||||
hours: Annotated[int, Query(ge=0, le=8760)] = 24,
|
||||
) -> Any:
|
||||
"""Execution time per node type, slowest first, to point at the hotspots.
|
||||
|
||||
The rollups are kept per node, so the type is joined on from the published
|
||||
flows. A node deleted since it ran has no type left to count under.
|
||||
"""
|
||||
hours = _window_hours(hours)
|
||||
types = {
|
||||
f"{flow.name}.{node.id}": node.type
|
||||
for flow in controller.store.read_all()
|
||||
for node in flow.nodes
|
||||
}
|
||||
statement = (
|
||||
sa_select(
|
||||
col(MetricBucket.node),
|
||||
func.sum(col(MetricBucket.executions)).label("executions"),
|
||||
func.sum(col(MetricBucket.duration_sum_ms)).label("duration_sum_ms"),
|
||||
func.max(col(MetricBucket.duration_max_ms)).label("max_ms"),
|
||||
)
|
||||
.where(col(MetricBucket.bucket) >= _since(hours))
|
||||
.group_by(col(MetricBucket.node))
|
||||
)
|
||||
totals: dict[str, dict[str, float]] = {}
|
||||
for row in session.execute(statement):
|
||||
kind = types.get(row.node)
|
||||
if kind is None or not row.executions:
|
||||
continue
|
||||
entry = totals.setdefault(
|
||||
kind, {"nodes": 0, "executions": 0, "duration_sum_ms": 0.0, "max_ms": 0.0}
|
||||
)
|
||||
entry["nodes"] += 1
|
||||
entry["executions"] += row.executions
|
||||
entry["duration_sum_ms"] += row.duration_sum_ms
|
||||
entry["max_ms"] = max(entry["max_ms"], row.max_ms)
|
||||
timings = [
|
||||
NodeTypeTiming(
|
||||
type=kind,
|
||||
nodes=int(entry["nodes"]),
|
||||
executions=int(entry["executions"]),
|
||||
avg_ms=round(entry["duration_sum_ms"] / entry["executions"], 3),
|
||||
max_ms=round(entry["max_ms"], 3),
|
||||
)
|
||||
for kind, entry in totals.items()
|
||||
]
|
||||
return sorted(timings, key=lambda timing: timing.avg_ms, reverse=True)
|
||||
|
||||
|
||||
@router.get("/runs", response_model=RunPage)
|
||||
def read_runs(
|
||||
session: SessionDep,
|
||||
|
||||
Reference in New Issue
Block a user