Script icon
Docker icon
If icon
SlackIncomingWebhook icon
Log icon
Return icon
Schedule icon

Kong Ingress Upstream Target Unhealthy and Circuit Breaker Sentinel

Scrapes Kong Prometheus metrics to track unhealthy balancer targets, circuit breaker trips, and gateway timeouts with Slack alerting.

Categories
CloudInfrastructure

Production-grade API gateway reliability watchdog that continuously monitors Kong Gateway and Ingress Controller instances. It tracks upstream target health states in ring-balancer pools, detects circuit breaker activations that isolate downstream microservices, monitors HTTP 504 Gateway Timeout surges, and dispatches structured Slack alerts with runbook diagnostics before customer API traffic experiences complete outage.

How it works

  1. A recurring schedule trigger wakes the flow every 15 minutes to initiate Kong Gateway surveillance.
  2. A containerized Python script polls the Kong Prometheus metrics endpoint exposed on admin or status ports.
  3. The script extracts unhealthy target states (kong_upstream_target_health) across active balancer pools.
  4. The script audits circuit breaker trip events and aggregates HTTP 504 Gateway Timeout error spikes.
  5. A decision gate evaluates whether unhealthy targets or circuit breaker activations breach safety margins.
  6. When routing degradation occurs, high-priority notifications dispatch to Network SRE channels with runbooks.
  7. A structured audit manifest is emitted for enterprise compliance records and API gateway observability archives.

Architecture diagram

flowchart TD
    A[Schedule Trigger: Every 15 Mins] --> B[scan_kong_gateway_metrics]
    B --> C{evaluate_kong_threshold}
    C -- Alert Triggered --> D[notify_slack_networking_team]
    C -- Nominal State --> E[log_nominal_kong_state]
    D --> F[emit_audit_manifest]
    E --> F[emit_audit_manifest]

Architecture components

  • Trigger (periodic_kong_audit): Recurring cron schedule executing every 15 minutes for proactive gateway surveillance.
  • Scraper Task (scan_kong_gateway_metrics): Docker-isolated Python script polling Kong Prometheus metrics with error handling.
  • Decision Gate (evaluate_kong_threshold): Evaluates unhealthy targets and circuit breaker events against user thresholds.
  • Notification Task (notify_slack_networking_team): Sends rich Slack alert with target metrics, timeouts, and gateway runbooks.
  • Compliance Manifest (emit_audit_manifest): Emits structured JSON summary for network audit archives.

Key capabilities

  • Continuous surveillance of upstream ring-balancer target health across all Kong workspaces.
  • Real-time detection of circuit breaker tripouts isolating failing backend microservice pools.
  • Early warning for HTTP 504 Gateway Timeout surges before client SLAs are breached.
  • Standardized Slack alerting with operational runbook instructions for API gateway administrators.

What you get

  • Real-time visibility into Kong Gateway upstream routing health and backend availability.
  • Prevention of silent customer API failures caused by unrecognized backend pod crashes.
  • Automated Slack incident notifications with unhealthy target counts and remediation advice.
  • Clean compliance manifests recording API gateway health for SRE audit trails.

Who it's for

  • API Gateway Administrators managing enterprise Kong Gateway and Ingress Controller clusters.
  • Site Reliability Engineers safeguarding external ingress endpoints and microservice routing.
  • Cloud Platform Engineers operating Kubernetes ingress controllers and service meshes.
  • DevOps Teams operating high-throughput public APIs and partner integration gateways.

Why orchestrate this with Kestra

  • Decoupled Architecture: Scrapes metrics externally without requiring root access to Kong proxy pods.
  • Deterministic Scheduling: Native cron scheduling ensures consistent surveillance without cron daemon drift.
  • Isolated Execution: Runs Python scrapers inside isolated Docker containers with pre-installed libraries.
  • Enterprise Auditability: Generates structured execution histories and JSON manifests for regulatory reporting.

Use cases

  • Backend Pod Eviction Spikes: Detect unhealthy balancer targets when Kubernetes terminates worker pods abruptly.
  • Upstream Canary Failures: Identify circuit breaker trips during canary rollouts of new microservice versions.
  • Slow Database Cascade: Catch 504 timeout surges when database latency backs up upstream service workers.
  • Health Check Misconfiguration: Detect false-unhealthy assertions caused by wrong HTTP health check paths.

Inputs

Name Type Default Description
kong_metrics_url STRING http://kong-gateway-admin.kong.svc.cluster.local:8001 Base HTTP URL exposing Kong Prometheus metrics.
gateway_workspace STRING production-ecommerce Target Kong Gateway workspace identifier under active surveillance.
max_unhealthy_targets_threshold INT 2 Maximum allowable unhealthy balancer targets before alerting.
lookback_minutes INT 15 Lookback evaluation window in minutes for gateway telemetry.
alert_on_kong_failures BOOL true Toggle Slack alert dispatch upon detecting unhealthy targets or tripouts.

Expected outputs

  • {{ outputs.scan_kong_gateway_metrics.vars.unhealthy_targets_count }}: Cumulative count of unhealthy upstream balancer targets.
  • {{ outputs.scan_kong_gateway_metrics.vars.circuit_breaker_trips_count }}: Total number of circuit breaker activation events.
  • {{ outputs.scan_kong_gateway_metrics.vars.gateway_504_timeouts_count }}: Count of HTTP 504 Gateway Timeout responses generated.
  • {{ outputs.scan_kong_gateway_metrics.vars.healthy_upstreams_count }}: Total number of healthy upstream balancer configurations.
  • {{ outputs.scan_kong_gateway_metrics.vars.is_alerting }}: Boolean flag indicating whether failure thresholds were breached.
  • {{ outputs.emit_audit_manifest.value }}: Structured JSON audit manifest emitted for compliance archives.

Prerequisites

  • Kong Gateway deployed with Prometheus plugin enabled globally (kong plugins enable prometheus).
  • Kong metrics endpoint reachable from the Kestra worker execution environment.
  • Docker daemon running on the Kestra host to execute containerized Python tasks.

Secrets

  • SLACK_WEBHOOK_URL: Incoming webhook URL for the target Network SRE Slack alerting channel.

Quick start

  1. Ensure Kong Gateway has Prometheus plugin enabled via Helm values or KongPlugin CRD.
  2. Configure the SLACK_WEBHOOK_URL secret in your Kestra namespace settings.
  3. Specify your workspace identifier in gateway_workspace.
  4. Execute a manual test run via the Kestra UI to verify metric ingestion.
  5. Enable the periodic_kong_audit trigger to establish automated continuous surveillance.

Common pitfalls and troubleshooting

  • Health Check Flapping: Aggressive health check intervals cause targets to toggle rapidly; tune healthy.successes.
  • DNS Resolution Cache: Stale DNS TTLs in Kong upstream configurations prevent discovering replacement pod IPs.
  • Port 8001 Exposure: Never expose Kong admin port publicly; use the dedicated status port (8100) instead.
  • Prometheus Scrape Headers: When RBAC is enabled on Kong Admin, include the Kong-Admin-Token header.

How to extend

  • Automated Target Eviction: Trigger an administrative API call to disable a persistently failing upstream target.
  • Dynamic Balancer Weight Tuning: Chain a task to reduce traffic weighting for degraded upstream services.
  • PagerDuty Escalation: Escalate to on-call gateway engineers if circuit breaker trips exceed 5 within 10 minutes.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.