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

Kong Upstream Target Health and Balancer Sentinel

Audits Kong API Gateway upstream targets for unhealthy endpoints, balancer pool failures, and routing degradation with automated alerting.

Categories
CloudInfrastructure

Audits Kong API Gateway Admin API endpoints to monitor upstream load balancer targets, passive circuit breaker states, and target availability ratios across production routes.

How it works

  1. The hourly_kong_target_audit schedule trigger initiates the audit on an hourly recurrence.
  2. The audit_kong_targets task connects to the Kong Admin API /upstreams endpoint and requests /health breakdowns for every registered balancer pool.
  3. The check_upstream_health flowable evaluates if any target has been evicted or if overall pool health percentage drops below the specified tolerance.
  4. If unhealthy targets are detected, notify_slack_gateway_ops sends a targeted diagnostic report to Slack with offending target IPs and weights.
  5. If all upstream pools are fully operational, log_healthy_kong_upstreams logs healthy cluster status.
  6. The export_kong_manifest task generates an execution summary for downstream tracking.

Architecture diagram

flowchart TD
    T[Schedule: hourly_kong_target_audit] --> S[audit_kong_targets]
    S --> C{check_upstream_health}
    C -- Alert Triggered --> A[notify_slack_gateway_ops]
    C -- Healthy --> H[log_healthy_kong_upstreams]
    A --> E[export_kong_manifest]
    H --> E[export_kong_manifest]

Use cases

  • API Gateway Reliability: Automatically detects when microservice backend pods fail health checks before customer requests encounter HTTP 503 errors.
  • Zero Downtime Deployments: Validates that canary or blue-green targets register successfully and transition to HEALTHY state in Kong upstreams.
  • Distributed Gateway Observability: Provides centralized visibility across multi-region Kong Gateway data planes.

Inputs

Name Type Default Description
kong_admin_url STRING http://kong-admin.internal:8001 Base HTTP URL for the Kong Gateway Admin API.
min_pool_health_percentage FLOAT 75.0 Minimum acceptable ratio of healthy targets per upstream pool before triggering an alert.
alert_on_any_unhealthy_target BOOL true Whether to alert immediately if any single upstream target is reported unhealthy.

Expected outputs

  • outputs.audit_kong_targets.vars.total_upstreams: Count of total upstream balancer pools audited.
  • outputs.audit_kong_targets.vars.total_targets_audited: Total number of individual backend targets inspected.
  • outputs.audit_kong_targets.vars.total_unhealthy_targets: Count of targets currently marked UNHEALTHY or DNS_ERROR.
  • outputs.audit_kong_targets.vars.alert_triggered: Boolean flag indicating if alert conditions were met.
  • outputs.export_kong_manifest.value: Formatted execution report text.

Prerequisites

  • Network access from Kestra workers to Kong Admin API (typically port 8001 or 8444).
  • Read access to Kong Admin /upstreams and /upstreams/{name}/health endpoints.
  • Slack incoming webhook endpoint configured.

Secrets

  • SLACK_WEBHOOK_URL: Secret storing the Slack webhook URL for gateway operations alerts.

Quick start

  1. Set SLACK_WEBHOOK_URL in your Kestra namespace secrets.
  2. Configure kong_admin_url with the accessible address of your Kong Admin API.
  3. Run a manual execution to test target health parsing and verify Slack notification delivery.
  4. Enable the hourly_kong_target_audit schedule to automate continuous health monitoring.

Common pitfalls and troubleshooting

  • Kong Admin Network Isolation: In production, the Kong Admin API is typically restricted. Ensure Kestra workers are explicitly allowed via security group or API key headers.
  • DNS Resolution in Dynamic Environments: In Kubernetes, headless service endpoints may flap during rollouts. Use min_pool_health_percentage to prevent alerts during expected rolling updates.
  • Passive vs Active Health Checks: Targets only transition to UNHEALTHY if active or passive health checks are configured in the Kong upstream definition.

How to extend

  • Automate target state remediation by posting to Kong Admin API to mark healthy once container readiness probes pass.
  • Forward target status metrics to Datadog or Prometheus to track upstream availability trends over time.
  • Trigger automated rollback flows in CI/CD pipelines if a newly deployed image results in unhealthy upstream targets.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.