id: grafana-deployment-annotation-marker
namespace: company.sre
inputs:
- id: service_name
type: STRING
displayName: Service Name
description: Name of the microservice or application being deployed (e.g.
checkout-api, auth-service).
defaults: checkout-api
- id: environment
type: STRING
displayName: Deployment Environment
description: Target deployment tier (e.g. production, staging, canary).
defaults: production
- id: version
type: STRING
displayName: Release Version
description: Application version or release tag (e.g. v2.4.0).
defaults: v2.4.0
- id: commit_sha
type: STRING
displayName: Git Commit SHA
description: Short or full Git commit hash corresponding to the deployed release.
defaults: 7f9b1c2
- id: deployed_by
type: STRING
displayName: Deployed By
description: User, pipeline, or bot initiating the deployment (e.g.
github-actions, argo-cd, john.doe).
defaults: github-actions
- id: dashboard_uid
type: STRING
displayName: Dashboard UID (Optional)
description: UID of a specific Grafana dashboard to scope the annotation to.
Leave empty to annotate globally across all dashboards.
defaults: ""
- id: release_notes
type: STRING
displayName: Release Summary
description: Brief description or changelog summary for this deployment.
defaults: Scaled database pool and optimized checkout query performance.
- id: notify_slack
type: BOOL
displayName: Notify Slack
description: Send a deployment confirmation message with direct Grafana
dashboard link to Slack. Requires SLACK_WEBHOOK_URL secret.
defaults: true
concurrency:
limit: 5
triggers:
- id: deployment_webhook
type: io.kestra.plugin.core.trigger.Webhook
description: Webhook endpoint called by CI/CD pipelines (GitHub Actions, GitLab
CI, ArgoCD post-sync) immediately after a rollout succeeds.
key: deploy-marker
tasks:
- id: build_annotation_payload
type: io.kestra.plugin.scripts.python.Script
description: Format release metadata, compute millisecond epoch timestamp, and
construct the Grafana annotations API request payload.
containerImage: python:3.11-slim
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
beforeCommands:
- pip install --no-cache-dir kestra
script: |
import json
import time
from kestra import Kestra
# Current epoch time in milliseconds for Grafana annotation
epoch_ms = int(time.time() * 1000)
service = "{{ inputs.service_name }}"
env = "{{ inputs.environment }}"
version = "{{ inputs.version }}"
sha = "{{ inputs.commit_sha }}"
author = "{{ inputs.deployed_by }}"
notes = """{{ inputs.release_notes }}""".strip()
dashboard_uid = "{{ inputs.dashboard_uid }}".strip()
tags = ["deployment", env, service, version]
# Text rendered inside the Grafana annotation popup
annotation_text = (
f"<b>Deployment: {service} ({version})</b><br/>"
f"• Environment: <code>{env}</code><br/>"
f"• Commit: <code>{sha}</code><br/>"
f"• Deployer: {author}<br/>"
f"• Notes: {notes}"
)
payload = {
"text": annotation_text,
"tags": tags,
"time": epoch_ms,
"timeEnd": epoch_ms
}
if dashboard_uid:
payload["dashboardUID"] = dashboard_uid
payload_str = json.dumps(payload)
print("Generated Grafana annotation payload:")
print(payload_str)
Kestra.outputs({
"epoch_ms": epoch_ms,
"payload_json": payload_str,
"annotation_text": annotation_text
})
- id: post_grafana_annotation
type: io.kestra.plugin.core.http.Request
description: Send HTTP POST request to Grafana Annotations API to write the
deployment event marker onto metric panels.
uri: "{{ secret('GRAFANA_URL') }}/api/annotations"
method: POST
contentType: application/json
headers:
Authorization: "Bearer {{ secret('GRAFANA_API_TOKEN') }}"
body: "{{ outputs.build_annotation_payload.vars.payload_json }}"
- id: evaluate_post_response
type: io.kestra.plugin.core.flow.If
description: Check Grafana API response code and trigger Slack confirmation or
incident escalation accordingly.
condition: "{{ outputs.post_grafana_annotation.status >= 200 and
outputs.post_grafana_annotation.status < 300 }}"
then:
- id: log_annotation_success
type: io.kestra.plugin.core.log.Log
description: Log successful creation of Grafana deployment annotation.
message: >-
Grafana deployment annotation created successfully for '{{
inputs.service_name }}' ({{ inputs.version }}) in {{
inputs.environment }}. Response Status: {{
outputs.post_grafana_annotation.status }}, Body: {{
outputs.post_grafana_annotation.body }}.
- id: notify_slack_success
type: io.kestra.plugin.core.flow.If
description: Post deployment marker card to Slack channel if notification is
enabled.
condition: "{{ inputs.notify_slack }}"
then:
- id: slack_success_alert
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Send rich Slack notification card with direct dashboard navigation
context.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "Deployment Marked in Grafana: `{{ inputs.service_name }}` (`{{ inputs.version }}`)\n• Environment: `{{ inputs.environment }}`\n• Commit SHA: `{{ inputs.commit_sha }}`\n• Deployed By: {{ inputs.deployed_by }}\n• Notes: {{ inputs.release_notes }}\n• Grafana URL: {{ secret('GRAFANA_URL') }}\nExecution: {{ execution.id }}"
}
else:
- id: notify_slack_failure
type: io.kestra.plugin.core.flow.If
description: Alert Slack if Grafana rejected the annotation payload.
condition: "{{ inputs.notify_slack }}"
then:
- id: slack_failure_alert
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Post Grafana API failure alert to Slack.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "Failed to create Grafana deployment annotation for `{{ inputs.service_name }}`! HTTP Status: {{ outputs.post_grafana_annotation.status }}. Body: {{ outputs.post_grafana_annotation.body }}. Execution {{ execution.id }}."
}
- id: fail_execution
type: io.kestra.plugin.core.execution.Fail
description: Terminate workflow as failed when Grafana API returns a non-2xx
status code.
errorMessage: "Grafana Annotations API returned status {{
outputs.post_grafana_annotation.status }}: {{
outputs.post_grafana_annotation.body }}."
errors:
- id: on_pipeline_error
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Catch unhandled network timeouts, bad secrets, or connectivity failures.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "Unexpected error in Grafana deployment marker flow `{{ flow.id }}` for service `{{ inputs.service_name }}` (Execution `{{ execution.id }}`). Check worker network logs."
}
outputs:
- id: annotation_response
type: JSON
description: Raw response payload from the Grafana Annotations REST API.
value: "{{ outputs.post_grafana_annotation.body }}"
- id: http_status
type: INT
description: HTTP response status code returned by Grafana.
value: "{{ outputs.post_grafana_annotation.status }}"
- id: timestamp_millis
type: INT
description: Millisecond Unix epoch timestamp assigned to the annotation.
value: "{{ outputs.build_annotation_payload.vars.epoch_ms }}"