id: graphql-mutation-error-rate-sentinel
namespace: company.devops
inputs:
- id: graphql_endpoint
type: URI
displayName: GraphQL Gateway Endpoint
defaults: "https://api.spacex.land/graphql"
description: URL of the GraphQL gateway or backend service to probe.
- id: mutation_query
type: STRING
displayName: Canary Mutation Query
defaults: |
mutation InsertUserCanary($name: String!, $rocket: String!) {
insert_users(objects: [{name: $name, rocket: $rocket}]) {
affected_rows
returning {
id
name
}
}
}
description: GraphQL mutation document executed to verify resolver execution health.
- id: mutation_variables
type: JSON
displayName: Mutation Variables
defaults: |
{
"name": "Kestra-Health-Probe",
"rocket": "Falcon-Heavy"
}
description: JSON variables supplied to the canary mutation query.
- id: max_tolerable_errors
type: INT
displayName: Maximum Tolerable Mutation Errors
defaults: 0
description: Threshold of acceptable errors in the GraphQL response body before
dispatching an incident alert.
triggers:
- id: mutation_health_schedule
type: io.kestra.plugin.core.trigger.Schedule
description: Probes GraphQL mutation resolver health every 15 minutes. Shipped
disabled by default.
cron: "*/15 * * * *"
disabled: true
tasks:
- id: execute_canary_mutation
type: io.kestra.plugin.graphql.Request
description: Execute mutation against target GraphQL endpoint capturing response
data and partial errors.
uri: "{{ inputs.graphql_endpoint }}"
headers:
Authorization: "Bearer {{ secret('GRAPHQL_API_TOKEN') }}"
Content-Type: "application/json"
User-Agent: "Kestra-GraphQL-Mutation-Sentinel/1.0"
failOnGraphQLErrors: false
query: "{{ inputs.mutation_query }}"
variables: "{{ inputs.mutation_variables }}"
- id: evaluate_mutation_errors
type: io.kestra.plugin.scripts.python.Script
description: Inspect GraphQL response payload for partial execution errors,
unhandled exceptions, and schema rejections.
containerImage: python:3.11-slim
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
env:
RESPONSE_BODY: "{{ outputs.execute_canary_mutation.body }}"
STATUS_CODE: "{{ outputs.execute_canary_mutation.status }}"
ENDPOINT: "{{ inputs.graphql_endpoint }}"
script: |
import os
import json
from kestra import Kestra
raw_body = os.environ.get("RESPONSE_BODY", "{}")
status_code = int(os.environ.get("STATUS_CODE", 200))
endpoint = os.environ.get("ENDPOINT", "")
try:
payload = json.loads(raw_body)
except Exception as exc:
payload = {"errors": [{"message": f"Malformed JSON response: {str(exc)}"}]}
errors = payload.get("errors", [])
data = payload.get("data")
error_count = len(errors)
is_partial_failure = (error_count > 0 and data is not None)
is_complete_failure = (error_count > 0 and data is None) or status_code >= 400
top_messages = [e.get("message", "Unknown error") for e in errors[:5]]
error_codes = [e.get("extensions", {}).get("code", "INTERNAL_SERVER_ERROR") for e in errors if "extensions" in e]
Kestra.outputs({
"error_count": error_count,
"has_errors": error_count > 0,
"is_partial_failure": is_partial_failure,
"is_complete_failure": is_complete_failure,
"status_code": status_code,
"top_error_messages": top_messages,
"error_codes": list(set(error_codes)),
"summary": f"GraphQL mutation probe to {endpoint} returned {error_count} error(s) with HTTP status {status_code}."
})
- id: check_error_threshold
type: io.kestra.plugin.core.flow.If
description: Evaluate if mutation error count breaches configured allowable tolerance.
condition: "{{ outputs.evaluate_mutation_errors.vars.error_count >
inputs.max_tolerable_errors }}"
then:
- id: notify_slack_mutation_alert
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatch high-priority alert to engineering on-call channel in Slack.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "#graphql-api-alerts",
"username": "Kestra GraphQL Sentinel",
"icon_emoji": ":warning:",
"attachments": [
{
"color": "#dc3545",
"title": "GraphQL Mutation Resolver Failure Detected",
"title_link": "{{ inputs.graphql_endpoint }}",
"text": "{{ outputs.evaluate_mutation_errors.vars.summary }}",
"fields": [
{
"title": "Endpoint",
"value": "`{{ inputs.graphql_endpoint }}`",
"short": true
},
{
"title": "HTTP Status",
"value": "{{ outputs.evaluate_mutation_errors.vars.status_code }}",
"short": true
},
{
"title": "Total Mutation Errors",
"value": "{{ outputs.evaluate_mutation_errors.vars.error_count }}",
"short": true
},
{
"title": "Failure Category",
"value": "{% if outputs.evaluate_mutation_errors.vars.is_partial_failure %}Partial Resolver Failure (HTTP 200 with errors){% else %}Complete Mutation Failure{% endif %}",
"short": true
},
{
"title": "Error Messages",
"value": "```{{ outputs.evaluate_mutation_errors.vars.top_error_messages | join('\n') }}```",
"short": false
}
],
"footer": "Kestra Mutation Health Sentinel",
"ts": "{{ now() | date('X') }}"
}
]
}
errors:
- id: send_failure_alert
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatch notification if GraphQL probe workflow execution
encounters unhandled system exceptions.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "#devops-alerts",
"username": "Kestra Sentinel Watchdog",
"icon_emoji": ":boom:",
"attachments": [
{
"color": "#ff0000",
"title": "GraphQL Mutation Sentinel Flow Execution Failed",
"text": "Execution *{{ execution.id }}* failed during GraphQL mutation health evaluation for endpoint *{{ inputs.graphql_endpoint }}*.",
"fields": [
{
"title": "Flow ID",
"value": "{{ flow.id }}",
"short": true
},
{
"title": "Namespace",
"value": "{{ flow.namespace }}",
"short": true
}
],
"footer": "Kestra Sentinel Watchdog",
"ts": "{{ now() | date('X') }}"
}
]
}