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

Varnish Backend VCL Fail and Panic Sentinel

Audits Varnish Cache metrics for backend connection failures, thread exhaustion, and VCL panics, alerting SREs on Slack before edge caching outages.

Categories
CloudInfrastructure

In high-performance content delivery architectures, Varnish HTTP Cache accelerates web applications and APIs by serving cached responses with microsecond latencies directly from host memory. Varnish monitors upstream application origins using active VCL backend probes (.probe) and health check directors.

When backend web applications undergo deployments, experience connection timeouts, or exhaust thread pools, Varnish marks directors as unhealthy. If connection failures surge (MAIN.backend_fail) or faulty VCL C-code extensions trigger child process panics (MAIN.panic), Varnish falls back to synthetic HTTP 503 Gateway Timeout pages, bypassing cached assets and dropping user traffic.

This blueprint provides an automated edge caching availability sentinel. Running on a recurrent ten-minute schedule, it interrogates Prometheus exporter metrics exposing live varnishstat counters, quantifies backend failures, unhealthy director states, and child panics, and delivers actionable Slack alerts with exact varnishadm diagnostic commands to on-call infrastructure engineers.

How it works

  1. Recurrent Pulse Trigger: The poll_varnish_health trigger (io.kestra.plugin.core.trigger.Schedule) initiates the metric scan every ten minutes.
  2. Prometheus Metrics Scrape: The scan_varnish_backend_metrics task (io.kestra.plugin.scripts.python.Script) queries the Varnish Prometheus exporter, extracting backend_fail, backend_unhealthy, and panic counters.
  3. Threshold Gate: The evaluate_varnish_panics flowable task (io.kestra.plugin.core.flow.If) evaluates whether backend connection drops or thread creation failures exceed safe limits.
  4. Slack Incident Alert: When anomalies occur, alert_slack_varnish_panic (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) dispatches an actionable incident card detailing exact diagnostic commands (varnishadm backend.list, varnishadm panic.show).
  5. Healthy Confirmation: When metrics indicate nominal operations, log_healthy_varnish_cache logs healthy cache status.
  6. Manifest Export: The export_varnish_manifest task emits structured telemetry JSON for SRE observability dashboards.

Architecture diagram

flowchart TD
    A[Schedule: Every 10 Minutes] --> B[scan_varnish_backend_metrics: Varnish Exporter API]
    B --> C{Backend Fails or Panics Detected?}
    C -- Yes --> D[alert_slack_varnish_panic: Slack Webhook]
    C -- No --> E[log_healthy_varnish_cache: Log]
    D --> F[export_varnish_manifest: Return JSON]
    E --> F

Use cases

  • Edge Reverse Proxy Health Auditing: Detect origin API server dropouts before stale-while-revalidate cache grace periods expire.
  • VCL Dynamic Reconfiguration Safety: Verify that newly loaded VCL configurations do not trigger child worker segfaults or thread allocation panics.
  • Prevent Cache Stampedes on Origin: Identify failing backend connections before unmitigated retries overwhelm recovering application databases.

Inputs

Name Type Default Description
varnish_stats_url STRING "http://localhost:9131/metrics" Prometheus metrics endpoint exposing varnishstat.
max_backend_fail_threshold INT 5 Maximum allowable backend connection failures before alert.
target_instance_id STRING "varnish-edge-node-01" Logical identifier of the Varnish caching node.
slack_channel STRING "#edge-caching-alerts" Slack channel destination for edge caching alerts.

Expected outputs

  • {{ outputs.scan_varnish_backend_metrics.vars.has_issue }}: Boolean flag indicating if anomalies were detected.
  • {{ outputs.scan_varnish_backend_metrics.vars.backend_fail }}: Count of backend connection failures.
  • {{ outputs.scan_varnish_backend_metrics.vars.backend_unhealthy }}: Count of unhealthy backend directors.
  • {{ outputs.scan_varnish_backend_metrics.vars.main_panics }}: Number of child worker panics recorded.
  • {{ outputs.scan_varnish_backend_metrics.outputFiles['varnish_health_report.json'] }}: Structured JSON diagnostic report.

Prerequisites

  • Varnish Cache instance with prometheus-varnish-exporter running on port 9131.
  • Incoming Webhook URL configured for your edge caching Slack channel.

Secrets

  • SLACK_WEBHOOK_URL: Slack Incoming Webhook endpoint URL with permissions to post messages.

Quick start

  1. Configure SLACK_WEBHOOK_URL in your Kestra namespace secrets.
  2. Import this flow YAML into your Kestra workspace.
  3. Update varnish_stats_url to point to your Prometheus Varnish exporter endpoint.
  4. Click Execute in the UI to perform an initial edge cache stability probe.

Common pitfalls and troubleshooting

  • Shared Memory Log File Permissions: Ensure prometheus-varnish-exporter has read access to /var/lib/varnish/<hostname> shared memory log files (vsm) to extract metrics.
  • Transient Network Glitches: Individual backend probe failures do not immediately flip directors to sick status; monitor backend_unhealthy to avoid false alarms.

How to extend

  • Add automated panic log archival using varnishadm panic.clear after copying panic backtraces to S3.
  • Loop across all edge caching nodes dynamically using list inputs for multi-region CDN auditability.
  • Automatically trigger VCL rollback via varnishadm vcl.use <previous_vcl> when panics occur after a reload.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.