Request icon
Query icon
OutputValues icon
If icon
Fail icon
Loop icon
Log icon
Pause icon
LoopUntil icon
SlackIncomingWebhook icon
Schedule icon

Replay one incident's failed executions on the fixed revision with a canary

Restart one incident's failed Kestra executions on the latest flow revision. A canary runs first, an approval gates the restart and a rerun finishes the rest.

Categories
Infrastructure

After a bad deploy a flow leaves dozens of failed executions behind. You fix the flow and save a new revision while the failed runs still sit at the old one. This flow finds them, groups them by the task that failed and restarts one group on the latest revision. A canary goes first. The rest only starts if the canary succeeded on the new revision.

How it works

  1. flow reads the latest revision. window lists the executions of the flow in the look-back window. scan keeps the end of each restart chain that FAILED on an older revision.
  2. read fetches each candidate once, because the search result has no task runs. incidents groups them by the task that failed and selects the oldest max_replays of the task in failed_task_id.
  3. With the defaults the run logs the plan and stops. With auto_remediate true and dry_run false, hold (Pause) waits for an approval.
  4. same_revision reads the flow again. If it was saved during the wait, nothing is restarted. Every restart reads its execution first and is skipped when the execution is no longer FAILED or already has a restarted twin.
  5. restart_canary calls POST /executions/{id}/actions/restart?revision=N. The twin continues from the failed task on revision N and the original stays FAILED. wait_canary polls until the twins end. gate_canary fails the run unless every canary succeeded.
  6. restart_wave does the same for the rest of the incident, one execution at a time.

What you get

A list of incidents with their counts, a restart of one incident that cannot touch another and a stop at the first sign that the fix does not work. A canary that fails again on the new revision ends the run. The next run refuses to start while that failed twin is the newest execution of its chain.

Who it's for

Teams that run Kestra for pipelines and fix a bug after many runs have failed.

Why orchestrate this with Kestra

The restart, the wait and the verdict all use the Kestra API, so one run holds the plan, the approval and the proof. Pause carries the approval. concurrency with FAIL keeps a second run from restarting the same executions.

Tested end to end

13 cases on Kestra 2.0.6 and 2.0.5 with plugin-kestra 2.1.1 and 2.1.0. Covered: nothing to restart, a list of two incidents, a plan with seven candidates of two incidents, a declined approval, a canary and a wave that restart five executions, a rerun, a canary that fails on the new revision, a rerun after that failure, an execution restarted during the approval, a flow saved during the approval, a second run during the approval, a fix in two steps where only the failed restart is restarted again and a run killed after the canary. Each case checks the twins and the originals through the API.

Prerequisites

A Kestra user that can read and restart executions of the flow.

Secrets

KESTRA_API_USERNAME and KESTRA_API_PASSWORD for the API. SLACK_WEBHOOK_URL only when notify_slack is true.

Inputs

flow_id is required. failed_task_id picks the incident. canary_size defaults to 1 and max_replays to 20. since_hours defaults to 72. The window query shows 1000 executions at most. The run refuses a window that holds that many. auto_remediate defaults to false and dry_run to true.

Quick start

  1. Run with flow_id only and read the incidents in the plan log.
  2. Set failed_task_id. The run shows the executions it would restart and stops.
  3. Set auto_remediate true and dry_run false, then approve the Pause.

How to extend

Add a task after replayed that posts the twin ids to your incident channel. Raise canary_size for a bigger incident. To restart one execution at a given revision without a canary, call the restart endpoint directly.

Links

This blueprint was created by zkasuran.

See How

New to Kestra?

Use blueprints to kickstart your first workflows.