Schedule icon
Query icon
If icon
SlackIncomingWebhook icon
Log icon

Apache Druid Ingestion Task Failure and Duration Gate

Audit Apache Druid sys.tasks for ingestion failures and stalled task durations. Evaluate operational SLA gates and trigger Slack alerts.

Categories
DataInfrastructure

Apache Druid relies on distributed ingestion tasks running on MiddleManager workers or indexing peons to consume high-throughput streaming events from Kafka or Kinesis, as well as to execute scheduled compaction and batch loads. When data schema drift occurs, network partitions disrupt stream ingestion, or worker slots experience memory pressure, ingestion tasks can fail repeatedly or stall in a running state indefinitely, exhausting MiddleManager execution slots and stalling downstream analytical dashboards.

This blueprint provides an automated Day 2 operations sentinel for Apache Druid. It inspects Druid's native sys.tasks and sys.servers system catalog views over Avatica JDBC, evaluates aggregate failure counts and stalled task execution durations against operational SLA thresholds, and dispatches structured Slack notifications when ingestion health degrades.

How it works

  1. periodic_sentinel_schedule triggers the sentinel workflow on a 30-minute cron schedule (disabled by default so connection endpoints and thresholds can be configured).
  2. probe_ingestion_tasks executes an aggregating SQL query against sys.tasks via io.kestra.plugin.jdbc.druid.Query with fetchType: FETCH_ONE. It quantifies total tasks, failed tasks within the rolling lookback window, and active tasks exceeding max_task_duration_ms.
  3. probe_failed_task_offenders queries sys.tasks with fetchType: FETCH to extract detailed context (task ID, datasource, task type, duration, and error preview) for up to 5 offending tasks.
  4. probe_worker_cluster_capacity queries sys.servers to verify the count of healthy MiddleManager and Historical worker nodes currently registered in the cluster.
  5. evaluate_ingestion_health uses io.kestra.plugin.core.flow.If to check if failed_task_count meets or exceeds max_allowed_failed_tasks, or if stalled_task_count meets or exceeds max_allowed_stalled_tasks.
  6. When a breach occurs, evaluate_alert_mode checks alert_mode: ALERT posts a formatted Slack notification via io.kestra.plugin.slack.notifications.SlackIncomingWebhook, while AUDIT_ONLY logs the violation without paging on-call staff.
  7. When performance is nominal, log_healthy_status records a healthy audit entry.
  8. log_sentinel_audit_complete runs at the conclusion of every execution to maintain an unbroken audit trail of sentinel passes.
  9. A flow-level errors handler catches connection errors or unreachable endpoints and alerts operators that the monitoring sentinel is offline.

What you get

  • Automated, continuous monitoring of Apache Druid streaming and batch ingestion tasks without deploying external Prometheus agents.
  • Dual-risk evaluation: detects both hard task termination (status = 'FAILED') and runaway resource starvation (status = 'RUNNING' past time ceiling).
  • Top offender context: captures offending task IDs, datasources, and root-cause error messages directly in execution outputs.
  • Dry-run capability via AUDIT_ONLY mode to benchmark baseline task turnover before enabling live paging channels.
  • Out-of-band error handling that catches network partitions or cluster downtime and prevents silent monitoring failures.

Who it's for

  • Data Platform Engineers and SREs operating Apache Druid clusters for real-time analytics and user-facing dashboards.
  • Streaming data pipeline owners maintaining Kafka and Kinesis ingestion supervisors.
  • Analytics Engineers requiring SLA guarantees on streaming ingestion freshness and compaction progress.

Why orchestrate this with Kestra

Druid's built-in coordinator and overlord web consoles display task states interactively but do not provide autonomous alerting or conditional incident triage workflows. Kestra delivers declarative, version-controlled workflow orchestration with built-in secret masking, conditional branching, native Slack integrations, and full execution history tracking. Managing the sentinel as a Kestra blueprint replaces brittle custom cron scripts with a resilient, observable automation pipeline.

Prerequisites

  • An Apache Druid cluster (version 0.23.0 or later, including 30.0.0+) reachable via HTTP/HTTPS over its Avatica JDBC SQL endpoint.
  • A Druid user account with permission to query system catalog tables (sys.tasks, sys.servers).
  • A Slack incoming webhook URL for dispatching alerts.

Secrets

  • DRUID_USERNAME: Database user for authenticating against Druid Avatica SQL endpoint.
  • DRUID_PASSWORD: Database password for authenticating against Druid Avatica SQL endpoint.
  • SLACK_WEBHOOK: Incoming webhook URL for the target Slack channel (required for live alerting).

Note for Kestra Open-Source (OSS): Secrets are configured as base64-encoded environment variables formatted as SECRET_<NAME> (e.g. SECRET_DRUID_USERNAME, SECRET_SLACK_WEBHOOK).

Inputs

Name Type Default Allowed Values Description
druid_url STRING "jdbc:avatica:remote:url=http://localhost:8888/druid/v2/sql/avatica/;transparent_reconnection=true" Valid Avatica JDBC URL Druid Avatica JDBC SQL connection URL
lookback_hours INT 2 Positive integer Lookback window in hours to scan sys.tasks
max_allowed_failed_tasks INT 1 Positive integer Maximum failed ingestion tasks allowed before alert
max_task_duration_ms INT 7200000 Positive integer Maximum allowable running duration in milliseconds
max_allowed_stalled_tasks INT 1 Positive integer Maximum stalled tasks allowed before alert
alert_mode SELECT "ALERT" "ALERT", "AUDIT_ONLY" Operational alerting mode on threshold breach

Outputs

  • {{ outputs.probe_ingestion_tasks.row.failed_task_count }}: Aggregate count of failed tasks within the lookback window.
  • {{ outputs.probe_ingestion_tasks.row.stalled_task_count }}: Count of active tasks exceeding the duration ceiling.
  • {{ outputs.probe_ingestion_tasks.row.max_running_duration_ms }}: Maximum execution duration observed among active running tasks.
  • {{ outputs.probe_failed_task_offenders.rows }}: Structured list of top offending failed or stalled tasks with task ID, datasource, and error messages.
  • {{ outputs.probe_worker_cluster_capacity.row.middle_manager_count }}: Active MiddleManager nodes registered in the cluster.

Quick start

  1. Start a local Apache Druid single-container instance on port 8888 (avoiding host port 8080):

    docker run -d
    --name druid-sentinel
    -p 8888:8888
    apache/druid:30.0.0

  2. Connect the Druid container to the Kestra Docker network:

    docker network connect YOUR_KESTRA_NETWORK druid-sentinel

    Identify your network name using docker network ls.

  3. Configure the DRUID_USERNAME, DRUID_PASSWORD, and SLACK_WEBHOOK secrets in your Kestra environment.

  4. Import this blueprint into your Kestra instance.

  5. Run the flow manually with alert_mode: AUDIT_ONLY to establish baseline task metrics and verify Avatica JDBC connectivity.

  6. Enable periodic_sentinel_schedule to begin automated 30-minute operational sweeps.

How to extend

  • Add automated task remediation by issuing an HTTP POST request to Druid Overlord endpoint /druid/indexer/v1/task/{taskId}/shutdown to kill stalled runaway tasks.
  • Add partition and segment availability validation by joining with sys.segments to confirm published segments match queryable historical states.
  • Route critical streaming ingestion alerts to PagerDuty or Opsgenie while routing batch compaction delays to informational Slack channels.
  • Export execution audit metrics to BigQuery, Snowflake, or DuckDB for long-term ingestion SLA compliance trend analysis.

Links

Pitfalls

  • Avatica URL format: Apache Druid requires the Avatica JDBC prefix with transparent reconnection enabled: jdbc:avatica:remote:url=http://<host>:8888/druid/v2/sql/avatica/;transparent_reconnection=true. Omitting the path suffix will cause connection timeouts.
  • Port conflict: Apache Druid Router listens on HTTP port 8888 by default. Never map container ports to host port 8080 to prevent collision with Kestra web UI.
  • Network isolation: When running Kestra and Druid in separate Docker containers, localhost:8888 will resolve to the Kestra container itself. Use the container hostname (e.g. http://druid-sentinel:8888) on a shared Docker bridge network.
  • SQL compatibility: Druid system tables use Calcite SQL semantics. String timestamps and intervals require standard ANSI formatting (e.g. CURRENT_TIMESTAMP - INTERVAL '2' HOUR).
  • Task retention: Tasks remain in sys.tasks for the duration configured by Druid task retention settings (druid.indexer.storage.recentlyFinishedThreshold). Ensure lookback_hours does not exceed this retention window.
See How

New to Kestra?

Use blueprints to kickstart your first workflows.