Schedule icon
Request icon
If icon
Fail icon
Script icon
Docker icon
Set icon
SlackIncomingWebhook icon
Loop icon
Log icon

Elasticsearch & OpenSearch ILM Phase Stuck Remediation Guard

Remediate stuck Elasticsearch and OpenSearch ILM phases. Classify failures, clear invalid settings, trigger automated retries, and dispatch Slack alerts.

Categories
DataInfrastructure

Elasticsearch and OpenSearch indices routinely get stuck in Index Lifecycle Management (ILM) or Index State Management (ISM) error steps. When an ILM step encounters an error, such as an illegal argument exception due to an invalid rollover alias, unallocated shards preventing an index shrink, or network timeouts during frozen tier searchable snapshot mounting, the index halts all lifecycle progression. Write traffic continues, data retention ceases to execute, and disk utilization climbs toward watermark limits while overall cluster health remains deceptive green.

This blueprint implements an automated ILM/ISM phase guard that queries the explain lifecycle API, classifies root-cause failures into actionable remediation categories, clears conflicting index settings, triggers safe automated retries, stores operational history in Kestra KV, and dispatches detailed triage alerts to Slack.

How it works

  1. The fetch_ilm_explain task queries Elasticsearch or OpenSearch through io.kestra.plugin.core.http.Request via GET /{index_pattern}/_ilm/explain using basic authentication headers.
  2. The check_explain_status task evaluates HTTP response codes. If the cluster endpoint returns non-200 responses, the flow aborts immediately via fail_unreachable_cluster to prevent downstream actions on incomplete state.
  3. The triage_ilm_failures task (io.kestra.plugin.scripts.python.Script) parses the cluster explain payload. It filters managed indices in ERROR state, extracts step details, and classifies failure modes:
    • ROLLOVER_ALIAS_MISSING: Rollover failed because index.lifecycle.rollover_alias is unset, invalid, or pointing to a different index.
    • SHRINK_SHARD_ROUTING_MISMATCH: Shrink failed because primary shards were not routed to a single node.
    • FROZEN_TIER_TIMEOUT: Searchable snapshot mount or cold/frozen tier storage operation timed out.
    • GENERIC_PHASE_ERROR: Any other lifecycle exception or conflicting read-only block.
  4. The persist_telemetry_kv task (io.kestra.plugin.core.kv.Set) stores the audit manifest and error history into Kestra KV under key elastic_ilm_stuck_remediation_history.
  5. The gate_stuck_indices task (io.kestra.plugin.core.flow.If) checks if stuck indices exist:
    • When detected, dispatch_slack_triage (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) sends an operational triage notification containing index names, policies, failed steps, retry counts, and root-cause reasons.
    • If auto_remediate is enabled and dry_run is disabled, remediate_indices (io.kestra.plugin.core.flow.Loop) iterates through each stuck index:
      • Clears conflicting index settings via PUT /{index}/_settings when applicable.
      • Triggers automated lifecycle retry via POST /{index}/_ilm/retry.
      • Logs HTTP outcomes.
    • When in simulation mode (dry_run: true), remediation steps are bypassed and logged.
  6. The hourly_ilm_guard schedule trigger runs periodic health scans. An errors handler posts to Slack on unexpected execution failures.

What you get

  • Automated detection of Elasticsearch and OpenSearch indices trapped in ILM/ISM error steps.
  • Failure categorization distinguishing missing rollover aliases, shrink shard allocation mismatches, and frozen tier timeouts.
  • Safe automated remediation clearing conflicting write blocks and issuing lifecycle retries.
  • Persistent audit history stored in Kestra namespace Key-Value store for compliance and trend tracking.
  • Context-rich Slack triage alerts containing exact step names, retry counts, and underlying cluster exceptions.
  • Non-destructive dry-run mode for pre-production verification.

Who it's for

  • Platform and Site Reliability Engineers managing Elasticsearch or OpenSearch logging clusters.
  • Data Engineers maintaining append-only time-series indices, rollover aliases, and data streams.
  • Infrastructure teams troubleshooting disk exhaustion caused by blocked rollover and delete lifecycle phases.

Why orchestrate this with Kestra

Lifecycle failures in Elasticsearch often remain silent because shards stay allocated and the cluster health remains green, even while retention and rollover stop completely. Writing ad-hoc shell scripts or cron jobs leaves no audit trail, risks uncontrolled retry loops, and fails to handle node routing prerequisites. Kestra provides native HTTP orchestration, containerized classification logic, atomic KV state persistence, dry-run safety gates, and immediate incident alerting in a single declarative workflow.

Prerequisites

  • Reachable Elasticsearch cluster (version 7.x or 8.x) or OpenSearch cluster (version 1.x or 2.x).
  • HTTP user credentials with cluster permissions manage_ilm, manage_index_templates, and view_index_metadata.
  • Slack Incoming Webhook URL configured for incident triage notifications.

Secrets

  • ELASTICSEARCH_USERNAME: Username for HTTP basic authentication.
  • ELASTICSEARCH_PASSWORD: Password for HTTP basic authentication.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL for operational notifications and alerts.

Quick start

  1. Configure ELASTICSEARCH_USERNAME, ELASTICSEARCH_PASSWORD, and SLACK_WEBHOOK_URL in your Kestra namespace secrets.
  2. Run an initial manual execution with default parameters (dry_run: true) to audit current ILM explain states without modifying indices.
  3. Review the execution logs, Slack alert summary, and Kestra KV store entry under elastic_ilm_stuck_remediation_history.
  4. Run with auto_remediate: true and dry_run: false to clear conflicting blocks and trigger automated retries.
  5. Enable the hourly_ilm_guard schedule trigger to maintain automated continuous remediation.

How to extend

  • Configure index_pattern to isolate specific index families such as logs-* or metrics-*.
  • Add an automated index template remediation step to patch bad rollover aliases at the template source.
  • Integrate Jira or PagerDuty incident tasks when an index exceeds max_retry_threshold.
  • Extend the Python triage task to handle OpenSearch multi-node ISM transition actions.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.