id: vitess-tablet-health-and-routing-sentinel
namespace: company.data
inputs:
- id: vtgate_host
type: STRING
displayName: VTGate Host
defaults: "vtgate.internal"
description: Hostname or IP address of the Vitess VTGate proxy exposing the
MySQL wire protocol port.
- id: vtgate_port
type: INT
displayName: VTGate Port
defaults: 15306
description: Port number for the MySQL wire protocol interface on VTGate
(default 15306).
- id: target_keyspace
type: STRING
displayName: Target Keyspace
defaults: "@primary"
description: Vitess keyspace and tablet routing target specification (default @primary).
- id: slack_channel
type: STRING
displayName: Slack Channel
defaults: "#data-platform-alerts"
description: Slack channel destination for operational Vitess cluster incident cards.
- id: audit_shard_topology
type: BOOL
displayName: Audit Shard Topology
defaults: true
description: Query SHOW VITESS_SHARDS when degraded tablets are identified to
correlate outages with shard boundaries.
triggers:
- id: every_fifteen_minutes
type: io.kestra.plugin.core.trigger.Schedule
cron: "*/15 * * * *"
tasks:
- id: probe_vitess_tablets
type: io.kestra.plugin.jdbc.mysql.Query
url: "jdbc:mysql://{{ inputs.vtgate_host }}:{{ inputs.vtgate_port }}/{{
inputs.target_keyspace }}"
username: "{{ secret('VITESS_USERNAME') }}"
password: "{{ secret('VITESS_PASSWORD') }}"
fetchType: FETCH
allowFailure: true
sql: "SHOW VITESS_TABLETS;"
- id: route_by_tablet_health
type: io.kestra.plugin.core.flow.Switch
value: >-
{% if outputs.probe_vitess_tablets.rows is null %} PROBE_FAILED {% else %}
{% set primary_not_serving = 0 %}
{% set replica_not_serving = 0 %}
{% for row in outputs.probe_vitess_tablets.rows %}
{% if row.State != 'SERVING' and row.TabletType == 'PRIMARY' %}
{% set primary_not_serving = primary_not_serving + 1 %}
{% elseif row.State != 'SERVING' %}
{% set replica_not_serving = replica_not_serving + 1 %}
{% endif %}
{% endfor %}
{% if primary_not_serving > 0 %}
CRITICAL
{% elseif replica_not_serving > 0 %}
WARNING
{% else %}
HEALTHY
{% endif %}
{% endif %}
cases:
CRITICAL:
- id: alert_critical_slack
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "{{ inputs.slack_channel }}",
"text": "[CRITICAL] Vitess Primary Tablet Not Serving - Shard Write Availability Compromised",
"attachments": [
{
"color": "#D32F2F",
"title": "Vitess Primary Tablet Failure Incident",
"fields": [
{
"title": "Cluster Gateway",
"value": "{{ inputs.vtgate_host }}:{{ inputs.vtgate_port }}",
"short": true
},
{
"title": "Degraded Tablets Count",
"value": "{{ outputs.probe_vitess_tablets.size }}",
"short": true
},
{
"title": "Severity",
"value": "CRITICAL - Primary Tablet Offline",
"short": true
},
{
"title": "Keyspace Target",
"value": "{{ inputs.target_keyspace }}",
"short": true
}
],
"footer": "Kestra Vitess Sentinel | Execution ID: {{ execution.id }}"
}
]
}
- id: check_shard_topology
type: io.kestra.plugin.core.flow.If
condition: "{{ inputs.audit_shard_topology == true }}"
then:
- id: query_vitess_shards
type: io.kestra.plugin.jdbc.mysql.Query
url: "jdbc:mysql://{{ inputs.vtgate_host }}:{{ inputs.vtgate_port }}/{{
inputs.target_keyspace }}"
username: "{{ secret('VITESS_USERNAME') }}"
password: "{{ secret('VITESS_PASSWORD') }}"
fetchType: FETCH
sql: "SHOW VITESS_SHARDS;"
- id: log_shard_topology
type: io.kestra.plugin.core.log.Log
message: "Vitess cluster shard topology and primary assignments: {{
outputs.query_vitess_shards.rows }}"
WARNING:
- id: alert_warning_slack
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "{{ inputs.slack_channel }}",
"text": "[WARNING] Vitess Non-Serving Replica or Read-Only Tablets Detected - Redundancy Degraded",
"attachments": [
{
"color": "#F57C00",
"title": "Vitess Replica Tablet Warning",
"fields": [
{
"title": "Cluster Gateway",
"value": "{{ inputs.vtgate_host }}:{{ inputs.vtgate_port }}",
"short": true
},
{
"title": "Degraded Tablets Count",
"value": "{{ outputs.probe_vitess_tablets.size }}",
"short": true
},
{
"title": "Severity",
"value": "WARNING - Replica Not Serving",
"short": true
},
{
"title": "Keyspace Target",
"value": "{{ inputs.target_keyspace }}",
"short": true
}
],
"footer": "Kestra Vitess Sentinel | Execution ID: {{ execution.id }}"
}
]
}
PROBE_FAILED:
- id: alert_probe_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "{{ inputs.slack_channel }}",
"text": "[CRITICAL] Vitess Sentinel Probe Failed - Unable to execute SHOW VITESS_TABLETS via VTGate. Verify port 15306 routing and credentials."
}
HEALTHY:
- id: log_tablets_healthy
type: io.kestra.plugin.core.log.Log
message: "Vitess cluster tablet routing health is normal. All evaluated tablets
are in SERVING state."
- id: log_audit_summary
type: io.kestra.plugin.core.log.Log
message: "Vitess tablet health audit completed. Status: {{
outputs.route_by_tablet_health.value ?? 'PROCESSED' }}. Evaluated tablets
count: {{ outputs.probe_vitess_tablets.size ?? 0 }}."
errors:
- id: on_flow_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "{{ inputs.slack_channel }}",
"text": "[ERROR] Vitess Tablet Health Sentinel flow execution aborted unexpectedly. Execution ID: {{ execution.id }}."
}