Search icon
If icon
DiscordIncomingWebhook icon
Fail icon
Log icon
Schedule icon

Hourly OpenSearch Error Spike Gate with Discord Alerting

Gate on OpenSearch error counts with Kestra. Count 5xx logs hourly, alert Discord and fail the run above a threshold, log an all-clear below it.

Categories
DataInfrastructure

A digest tells you what happened yesterday; a gate stops the line now. This blueprint runs an hourly io.kestra.plugin.opensearch.Search with size: 0 counting documents with a 5xx status over the last hour, then branches with io.kestra.plugin.core.flow.If. Above the threshold, the flow posts the exact numbers to Discord and fails itself with io.kestra.plugin.core.execution.Fail, so the spike shows up as a red execution that downstream automation can react to. Below the threshold, it logs an all-clear and exits green.

How it works

  1. count_recent_errors (io.kestra.plugin.opensearch.Search) filters the app-logs index to status between 500 and 599 with @timestamp newer than now-1h. With size: 0, only {{ outputs.count_recent_errors.total }} travels back.
  2. gate (io.kestra.plugin.core.flow.If) compares the total against the error_threshold input, which defaults to 50.
  3. On breach, alert_spike posts the count and threshold to Discord, then fail_execution (io.kestra.plugin.core.execution.Fail) turns the execution red on purpose.
  4. Below the threshold, all_clear (io.kestra.plugin.core.log.Log) records the healthy count.
  5. The errors block posts a Discord alert on any failure, covering both deliberate breaches and a broken search.
  6. A disabled-by-default Schedule trigger runs the gate at the top of every hour.

What you get

  • An hourly health verdict computed inside OpenSearch, with zero documents transferred.
  • A deliberate red execution on breach, so flow-state triggers and dashboards see the incident.
  • The exact count and threshold in the Discord message, no login required to triage.
  • An auditable all-clear line for every quiet hour.

Who it's for

  • SRE and platform teams who ship access or application logs to OpenSearch and want a cheap tripwire.
  • Teams whose incident automation keys off execution state rather than log dashboards.
  • Anyone tired of discovering error spikes from customer tickets instead of alerts.

Why orchestrate this with Kestra

Alerting rules inside a monitoring stack are opaque to the pipelines they protect. Declaring the gate as a flow makes the threshold an input you can override per run, the verdict an execution state other flows can subscribe to, and every check a logged, replayable execution. When the gate fires, the red run and the Discord message point at the same execution id.

Prerequisites

  • An OpenSearch index of logs with a numeric status field and @timestamp, app-logs by default.
  • Credentials allowed to search that index.
  • A Discord incoming webhook for alerts.

Secrets

  • OPENSEARCH_HOST: OpenSearch endpoint, for example https://opensearch.example.com:9200.
  • OPENSEARCH_USERNAME: OpenSearch username.
  • OPENSEARCH_PASSWORD: OpenSearch password.
  • DISCORD_WEBHOOK_URL: Discord incoming webhook URL.

Quick start

  1. Add the four secrets to your Kestra namespace.
  2. Adjust the index name and the status field to your log schema, and pick a realistic error_threshold default.
  3. Execute the flow once manually with a low threshold to see the alert path, then once with a high one to see the all-clear.
  4. Set disabled: false on the hourly trigger.

How to extend

  • Split the threshold into warn and page levels with a second If branch.
  • Scope the count to one service with an extra term filter and run one gate per critical service.
  • Trigger a remediation flow from this flow's FAILED state with a flow trigger.
  • Feed the count into the daily digest pattern from the OpenSearch log error digest blueprint.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.