id: questdb-wal-suspended-table-sentinel
namespace: company.team
description: |
Query QuestDB's wal_tables() function for tables where suspended = true, alert Slack with
the real suspended table names when the count exceeds a threshold, and optionally issue
ALTER TABLE RESUME WAL over the REST API for each one, guarded by a safe-character check on
the table name.
triggers:
- id: every_15_minutes
type: io.kestra.plugin.core.trigger.Schedule
description: Check WAL suspension state every 15 minutes.
cron: "*/15 * * * *"
disabled: true
inputs:
questdb_host: "questdb"
questdb_pgwire_port: 8812
questdb_http_port: 9000
suspended_count_threshold: 0
auto_resume_wal: "false"
- id: on_demand_webhook
type: io.kestra.plugin.core.trigger.Webhook
description: Trigger an immediate WAL health check from an incident runbook or CI gate.
key: "{{ secret('WEBHOOK_KEY') }}"
inputs:
- id: questdb_host
type: STRING
displayName: QuestDB Hostname
description: Hostname or IP of the QuestDB instance reachable from the Kestra worker.
defaults: "questdb"
- id: questdb_pgwire_port
type: INT
displayName: QuestDB PGWire Port
description: PostgreSQL wire protocol port used by QuestDB for the wal_tables() probe.
defaults: 8812
- id: questdb_http_port
type: INT
displayName: QuestDB HTTP Port
description: REST API port used to send ALTER TABLE RESUME WAL when
auto_resume_wal is true.
defaults: 9000
- id: suspended_count_threshold
type: INT
displayName: Suspended Table Alert Threshold
description: Fire a Slack alert when the real suspended table count is strictly
greater than this value. 0 means any suspension triggers an alert.
defaults: 0
- id: auto_resume_wal
type: SELECT
displayName: Auto-Resume Suspended WAL Tables
description: When true, send ALTER TABLE RESUME WAL for every suspended table
that passes the safe-character name check, via the QuestDB REST API, after
alerting.
values:
- "true"
- "false"
defaults: "false"
tasks:
- id: probe_suspended_tables
type: io.kestra.plugin.jdbc.postgresql.Query
description: |
Queries wal_tables() via QuestDB's PostgreSQL wire protocol (PGWire) for the name,
writerTxn, and sequencerTxn of every table where suspended = true. No dedicated
QuestDB plugin or JDBC subplugin exists in the Kestra plugin catalog, so this uses the generic plugin-jdbc-postgres Query task against QuestDB's
PGWire-compatible port. This task is not wrapped in allowFailure, a connection or auth
failure here is caught by the flow-level errors block below instead of a separate
PROBE_FAILED branch.
url: "jdbc:postgresql://{{ inputs.questdb_host }}:{{ inputs.questdb_pgwire_port
}}/qdb"
username: "{{ secret('QUESTDB_USERNAME') }}"
password: "{{ secret('QUESTDB_PASSWORD') }}"
fetchType: FETCH
sql: "SELECT name, writerTxn, sequencerTxn FROM wal_tables() WHERE suspended =
true"
- id: gate_on_suspension
type: io.kestra.plugin.core.flow.If
description: Branches on the real suspended-table count against
suspended_count_threshold. No sum or count aggregate is computed in SQL,
outputs.probe_suspended_tables.size is the row count the JDBC task itself
reports, so there is no NULL-aggregate case to guard against.
condition: "{{ outputs.probe_suspended_tables.size >
inputs.suspended_count_threshold }}"
then:
- id: alert_wal_suspension
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Alerts with the real suspended count and the real table names,
joined from outputs.probe_suspended_tables.rows, never an invented
name or count.
url: "{{ secret('SLACK_WEBHOOK') }}"
payload: |
{{ {"text": "QuestDB WAL suspension detected on " ~ inputs.questdb_host ~ ":" ~ inputs.questdb_pgwire_port ~ ". Suspended table count: " ~ outputs.probe_suspended_tables.size ~ ". Tables: " ~ (outputs.probe_suspended_tables.rows | jq("[.[].name] | join(\", \")") | first) ~ ". Auto-resume: " ~ inputs.auto_resume_wal ~ ". Execution: " ~ execution.id ~ "."} | toJson }}
- id: check_auto_resume
type: io.kestra.plugin.core.flow.If
description: Gates automatic remediation behind the auto_resume_wal toggle.
condition: "{{ inputs.auto_resume_wal == 'true' }}"
then:
- id: resume_loop
type: io.kestra.plugin.core.flow.Loop
description: |
Iterates over a list of plain table-name strings extracted via jq from
outputs.probe_suspended_tables.rows, not over the raw row maps. Kestra's own
Loop task documentation states that when values is a list of objects,
individual objects are coalesced to strings, so looping over the row maps
directly would not reliably expose item.value.name. Extracting a jq-built list
of strings first avoids relying on that coalescing behavior. concurrencyLimit 1
serializes the RESUME WAL calls so they do not compete against each other.
concurrencyLimit: 1
values: "{{ outputs.probe_suspended_tables.rows | jq('[.[].name]') | first }}"
tasks:
- id: guard_safe_table_name
type: io.kestra.plugin.core.flow.If
description: |
Only a conservative, self-defined safety guard before interpolating the name
into SQL and a URL, not a verified QuestDB identifier grammar, that was not
found in the fetched QuestDB documentation. Uses the same
value | toJson | jq('test("...")') | first pattern already merged elsewhere
in this repository for validating a name before using it unescaped.
condition: "{{ (item.value | toJson | jq('test(\"^[A-Za-z0-9_.-]{1,255}$\")') |
first) }}"
then:
- id: resume_wal_via_rest
type: io.kestra.plugin.core.http.Request
description: |
Sends ALTER TABLE <name> RESUME WAL to QuestDB's REST /exec endpoint as a
URL-encoded GET query parameter. QuestDB's own docs mark /exec as the
older, still-supported name for /execute, stating it takes the same
parameters and returns the same response, this flow uses /exec. options.allowFailed
lets a non-2xx response populate outputs instead of throwing, and the
separate allowFailure lets one table's failed call skip rather than abort
the remaining iterations.
uri: "http://{{ inputs.questdb_host }}:{{ inputs.questdb_http_port
}}/exec?query={{ ('ALTER TABLE ' ~ item.value ~ ' RESUME
WAL') | urlencode }}"
method: GET
options:
allowFailed: true
allowFailure: true
else:
- id: log_unsafe_table_name_skipped
type: io.kestra.plugin.core.log.Log
description: Logs and skips any table name that failed the safe-character check,
rather than sending it to SQL or a URL.
message: "Skipping RESUME WAL, table name failed the safe-character check: {{
item.value }}"
else:
- id: log_auto_resume_disabled
type: io.kestra.plugin.core.log.Log
description: Records that auto-resume is disabled and names the tables that
still need a manual RESUME WAL.
message: "Auto-resume off. Resume manually, tables: {{
(outputs.probe_suspended_tables.rows | jq('[.[].name] | join(\",
\")') | first) }}"
else:
- id: log_wal_healthy
type: io.kestra.plugin.core.log.Log
description: Logs the real suspended count, which may be a non-zero value at or
below suspended_count_threshold, never a hardcoded zero.
message: "QuestDB WAL healthy on {{ inputs.questdb_host }}:{{
inputs.questdb_pgwire_port }}. Suspended count: {{
outputs.probe_suspended_tables.size }}. Threshold: {{
inputs.suspended_count_threshold }}."
- id: log_audit_summary
type: io.kestra.plugin.core.log.Log
description: Final audit log confirming the gate ran, regardless of the branch
taken above.
message: "AUDIT flow={{ flow.id }} execution={{ execution.id }} host={{
inputs.questdb_host }}:{{ inputs.questdb_pgwire_port }} suspended_count={{
outputs.probe_suspended_tables.size }} threshold={{
inputs.suspended_count_threshold }} auto_resume={{ inputs.auto_resume_wal
}}"
errors:
- id: alert_flow_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Alerts on-call when the flow itself fails, for example on a probe
connection or auth failure.
url: "{{ secret('SLACK_WEBHOOK') }}"
payload: |
{{ {"text": "QuestDB WAL suspended table sentinel flow failed (execution " ~ execution.id ~ "). Host: " ~ inputs.questdb_host ~ ":" ~ inputs.questdb_pgwire_port ~ ". Check the execution logs, QuestDB PGWire connectivity, and the QUESTDB_USERNAME and QUESTDB_PASSWORD secrets."} | toJson }}