id: temporal-worker-canary-verification-and-traffic-gate
namespace: company.platform
description: |
Runs a synthetic canary workflow on a dedicated task queue served by a new Temporal worker build, and only
signals your traffic router workflow to promote that build when the canary completes. A failed or timed out
canary stops the release and alerts Slack.
concurrency:
limit: 1
behavior: QUEUE
inputs:
- id: worker_version
type: STRING
required: false
displayName: Target Worker Version
description: "Version or commit tag of the new worker build, such as v2.4.1 or a
short SHA. Webhook runs can send it as worker_version in the JSON body."
- id: task_queue
type: STRING
required: false
displayName: Production Task Queue
description: "Production task queue name. The canary queue is
<task_queue>-canary-<worker_version>, so the candidate worker must poll
that queue."
- id: canary_workflow_type
type: STRING
required: false
displayName: Canary Workflow Type
description: "Workflow type, registered in the candidate worker, that is run as
the canary."
- id: traffic_router_workflow_id
type: STRING
required: false
displayName: Traffic Router Workflow ID
description: "ID of your running router workflow. It must handle the
promoteWorkerVersion signal, which carries one JSON argument with
promotedVersion, taskQueue and approvedBy."
- id: health_query_type
type: STRING
required: false
displayName: Health Query Type
description: "Name of a query handler that the canary workflow registers. The
query must succeed, and its answer is logged."
- id: canary_timeout_minutes
type: INT
defaults: 5
min: 1
displayName: Canary Timeout (Minutes)
description: "Maximum time for the canary workflow to start and reach COMPLETED."
- id: temporal_namespace
type: STRING
defaults: default
displayName: Temporal Namespace
description: "Temporal namespace that holds the workflows and task queues."
triggers:
- id: ci_worker_build_webhook
type: io.kestra.plugin.core.trigger.Webhook
description: "Called by CI after it publishes a worker build, with a JSON body
such as {\"worker_version\": \"v2.4.1\"}."
key: "{{ secret('TEMPORAL_CANARY_WEBHOOK_KEY') }}"
variables:
target_worker_version: "{{ trigger.body.worker_version is defined ?
trigger.body.worker_version : (inputs.worker_version is defined ?
inputs.worker_version : '') }}"
canary_task_queue: "{{ inputs.task_queue is defined ? inputs.task_queue : ''
}}-canary-{{ vars.target_worker_version }}"
canary_workflow_id: "canary-{{ vars.target_worker_version }}-{{ execution.id }}"
tasks:
- id: validate_parameters
type: io.kestra.plugin.core.execution.Assert
description: "Stops before any workflow is started when a value is missing or
has an unsafe format. The worker version may come from a webhook body, and
it ends up in a task queue name and in the promotion signal."
errorMessage: "Missing or invalid parameters. worker_version must be a plain
version or SHA, and task_queue, canary_workflow_type,
traffic_router_workflow_id and health_query_type must be set."
conditions:
- "{{ vars.target_worker_version |
regexMatch(regex='^[A-Za-z0-9._-]{1,64}$') }}"
- "{{ vars.target_worker_version == (vars.target_worker_version | trim) }}"
- "{{ (inputs.task_queue is defined ? inputs.task_queue : '') |
regexMatch(regex='^[A-Za-z0-9._-]{1,128}$') }}"
- "{{ (inputs.canary_workflow_type is defined ?
inputs.canary_workflow_type : '') |
regexMatch(regex='^[A-Za-z0-9._-]{1,128}$') }}"
- "{{ (inputs.traffic_router_workflow_id is defined ?
inputs.traffic_router_workflow_id : '') |
regexMatch(regex='^[A-Za-z0-9._:-]{1,128}$') }}"
- "{{ (inputs.health_query_type is defined ? inputs.health_query_type :
'') | regexMatch(regex='^[A-Za-z0-9._-]{1,128}$') }}"
- id: start_canary_workflow
type: io.kestra.plugin.temporal.workflow.Trigger
description: "Starts the canary workflow on the canary task queue, which only
the candidate worker serves."
endpoint: "{{ secret('TEMPORAL_ENDPOINT') }}"
namespace: "{{ inputs.temporal_namespace }}"
workflowType: "{{ inputs.canary_workflow_type }}"
taskQueue: "{{ vars.canary_task_queue }}"
workflowId: "{{ vars.canary_workflow_id }}"
input:
- "{{ {'canaryRunId': execution.id, 'targetVersion':
vars.target_worker_version} | toJson }}"
executionTimeout: "PT{{ inputs.canary_timeout_minutes }}M"
- id: probe_canary_health
type: io.kestra.plugin.temporal.workflow.Query
description: "Calls the canary's query handler. It only succeeds when a worker
of the candidate build is polling the canary queue and has registered the
workflow and the handler."
endpoint: "{{ secret('TEMPORAL_ENDPOINT') }}"
namespace: "{{ inputs.temporal_namespace }}"
workflowId: "{{ outputs.start_canary_workflow.workflowId }}"
runId: "{{ outputs.start_canary_workflow.runId }}"
queryType: "{{ inputs.health_query_type }}"
- id: wait_for_canary_completion
type: io.kestra.plugin.temporal.workflow.Wait
description: "Waits for the canary to reach a terminal state. A canary that ends
in any state other than COMPLETED is handled by the next step, and a
canary that does not finish in time fails the execution."
endpoint: "{{ secret('TEMPORAL_ENDPOINT') }}"
namespace: "{{ inputs.temporal_namespace }}"
workflowId: "{{ outputs.start_canary_workflow.workflowId }}"
runId: "{{ outputs.start_canary_workflow.runId }}"
pollInterval: PT5S
waitTimeout: "PT{{ inputs.canary_timeout_minutes }}M"
failOnNonCompleted: false
- id: evaluate_canary_success
type: io.kestra.plugin.core.flow.If
description: "Promotes the worker version only when the canary COMPLETED.
Otherwise alerts Slack and fails the execution, so nothing is promoted."
condition: "{{ outputs.wait_for_canary_completion.status == 'COMPLETED' }}"
then:
- id: log_canary_verified
type: io.kestra.plugin.core.log.Log
message: "Canary workflow {{ vars.canary_workflow_id }} completed on queue {{
vars.canary_task_queue }}. Health query answer: {{
outputs.probe_canary_health.result }}."
- id: signal_traffic_promotion
type: io.kestra.plugin.temporal.workflow.Signal
description: "Sends the promoteWorkerVersion signal to the traffic router
workflow. The signal is fire-and-forget, so check your router to see
that it applied it."
endpoint: "{{ secret('TEMPORAL_ENDPOINT') }}"
namespace: "{{ inputs.temporal_namespace }}"
workflowId: "{{ inputs.traffic_router_workflow_id }}"
signalName: promoteWorkerVersion
args:
- "{{ {'promotedVersion': vars.target_worker_version, 'taskQueue':
inputs.task_queue, 'approvedBy': 'kestra-canary-gate'} | toJson }}"
- id: notify_promotion_success
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Tells the channel that the promotion signal was sent."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": ":rocket: *Temporal worker version promotion signalled*",
"attachments": [
{
"color": "#36A64F",
"fields": [
{"title": "Worker Version", "value": {{ vars.target_worker_version | toJson }}, "short": true},
{"title": "Task Queue", "value": {{ inputs.task_queue | toJson }}, "short": true},
{"title": "Canary Workflow", "value": {{ vars.canary_workflow_id | toJson }}, "short": false},
{"title": "Execution", "value": {{ execution.id | toJson }}, "short": false}
]
}
]
}
else:
- id: alert_canary_failed
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Tells the channel that the canary failed and nothing was promoted."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": ":rotating_light: *Temporal canary failed, promotion aborted*",
"attachments": [
{
"color": "#E24A4A",
"fields": [
{"title": "Candidate Version", "value": {{ vars.target_worker_version | toJson }}, "short": true},
{"title": "Canary Status", "value": {{ (outputs.wait_for_canary_completion.status is defined ? outputs.wait_for_canary_completion.status : 'UNKNOWN') | toJson }}, "short": true},
{"title": "Canary Workflow", "value": {{ vars.canary_workflow_id | toJson }}, "short": false},
{"title": "Execution", "value": {{ execution.id | toJson }}, "short": false}
]
}
]
}
- id: abort_execution
type: io.kestra.plugin.core.execution.Fail
description: "Fails the execution so that CI sees the rejected build."
errorMessage: "Canary workflow {{ vars.canary_workflow_id }} ended with status
{{ outputs.wait_for_canary_completion.status is defined ?
outputs.wait_for_canary_completion.status : 'UNKNOWN' }}. Worker
version {{ vars.target_worker_version }} was not promoted."
errors:
- id: alert_pipeline_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: "Tells the channel when the flow stops with an error, for example
an unreachable Temporal frontend, a failed query, or a canary that timed
out. Nothing is promoted in that case."
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": {{ (":boom: Temporal canary gate stopped with an error in execution " ~ execution.id ~ ". The worker version was not promoted.") | toJson }}
}