Search

Traffic Router Health VCL

The traffic_router_health.vcl file is a VCL include that enables the Traffic Router to probe the health of a Varnish instance through Varnish itself. It serves the agent’s health check data (traffic_router_health.json) in response to router health probe requests.

Background

The Traffic Router needs to know whether each Varnish endpoint is healthy, in maintenance, or down before making routing decisions. Rather than querying a sidecar service, the router sends a specially crafted HTTP request directly to the Varnish instance. The traffic_router_health.vcl include intercepts this request and serves the health check JSON file from disk using the Varnish Enterprise file VMOD.

How It Works

The router identifies its health probe requests with:

  • Method: GET
  • Accept: application/vnd.router.healthcheck+json
  • User-Agent: Matches Varnish Request Router

When all three conditions match, the request is handled internally and never reaches the origin backend. The health check handler returns early when it matches a probe request, so it does not interfere with normal request processing.

Shared Deployments (Automatic)

For shared deployments (the default deployment type), the agent automatically generates a root VCL that already includes traffic_router_health.vcl. No action is required from the user.

Root Deployments (Manual Include Required)

When using a root deployment, the Varnish Controller does not generate a root VCL, you provide your own. In this case, add the following line to your VCL:

vcl 4.1;

import ...;

include "traffic_router_health.vcl";

# Your VCL logic here

The include statement should be placed near the top of the file, before any subroutine definitions. Since VCL subroutines are concatenated when multiple definitions exist, the health check logic will be prepended to your own vcl_recv and vcl_backend_response subroutines. The health check handler returns early when it matches a probe request, so it does not interfere with normal request processing.

Ordering Considerations

The include should appear before your vcl_recv definition. VCL processes subroutines in definition order, and the health check handler uses return (pass) to exit early when it detects a probe request. If your vcl_recv appears first and returns before the health check logic runs, the router probes will not be handled correctly.

What the Include Does Not Do

  • It does not affect normal client requests. Only requests with the exact Accept header and User-Agent match are intercepted.
  • It does not cache health check responses. The TTL is set to 0.1 seconds and marked as uncacheable.

®Varnish Software, Wallingatan 12, 111 60 Stockholm, Organization nr. 556805-6203