What's Changed
Runner Heartbeats for Flow Run Monitoring
Flow runs can now emit heartbeat events to detect infrastructure failures (crashed machines, evicted containers, etc). When enabled, an automation can automatically mark flows as crashed when heartbeats stop, preventing stuck "zombie" flows in the running state.
Enable with:
- Set
PREFECT_RUNNER_HEARTBEAT_FREQUENCY
(requires Prefect 3.1.8+) - Deploy the provided automation script to update flow states when heartbeats stop
from prefect.automations import Automation
from prefect.client.schemas.objects import StateType
from prefect.events.actions import ChangeFlowRunState
from prefect.events.schemas.automations import EventTrigger, Posture
my_automation = Automation(
name="Crash zombie flows",
trigger=EventTrigger(
after={"prefect.flow-run.heartbeat"},
expect={
"prefect.flow-run.heartbeat",
"prefect.flow-run.Completed",
"prefect.flow-run.Failed",
"prefect.flow-run.Cancelled",
"prefect.flow-run.Crashed",
},
match={"prefect.resource.id": ["prefect.flow-run.*"]},
for_each={"prefect.resource.id"},
posture=Posture.Proactive,
threshold=1,
within=90,
),
actions=[
ChangeFlowRunState(
state=StateType.CRASHED,
message="Flow run marked as crashed due to missing heartbeats.",
)
],
)
my_automation.create()
Basic Authentication
We have also added a long requested feature: basic authentication support for the Prefect API. Enable by setting an auth string:
Start a protected server:
PREFECT_SERVER_API_AUTH_STRING="admin:admin" prefect server start
Authenticate client operations:
PREFECT_API_AUTH_STRING="admin:admin" python flow_script.py
Enhancements ➕➕
- Add working implementation of basic auth to server and client by @cicdw in #16408
- Add basic auth UI by @aaazzam in #16411
- Enhance
Runner
to send heartbeat events for flow runs by @desertaxle in #16410
Integrations & Dependencies 🤝
- add async redis client utils to
prefect-redis
by @zzstoatzz in #16417
Documentation 📓
Full Changelog: 3.1.7...3.1.8