Circuit breaker configuration via Caddyfile

1. The problem I’m having:

I am setting up the circuit breaker module and have a hard time configuring it via Caddyfile.
Unfortunately, adding a circuit_breaker block results in an error. The documentation over this module is absent, so I’m not sure how to configure it using Caddyfile and whether it’s possible (maybe it’s only configurable via JSON?). I would be glad if you could help me fixing the Caddyfile, thanks.

Also I’m not sure what unit does threshold config option use, did I assume percents of requests correctly?

2. Error messages and/or full log output:

Error: adapting config using caddyfile: /etc/caddy/Caddyfile:18: unrecognized directive: circuit_breaker

3. Caddy version:


4. How I installed and ran Caddy:

Caddy is deployed via Helm as a sidecar container to the pod, alongside the application server, and is intended to run as a reverse proxy that implements circuit breaker functionality.

a. System environment:

AWS EKS v1.26, Linux x86_64, containerd v1.6.19

b. Command:

caddy run --config /etc/caddy/Caddyfile --adapter caddyfile

c. Service/unit/compose file:

d. My complete Caddy config:

  admin :2019 # binds admin API on all interfaces, not only localhost. Required to scrape metrics
  auto_https off
  servers {
    trusted_proxies static <redacted>
  order rate_limit before basicauth

:8080 {
  rate_limit {remote.ip} 2r/s # remote.ip corresponds to the first IP in the X-Forwarded-For header

  header -<redacted>
  header -<redacted>

  reverse_proxy :5001 {
    circuit_breaker {
      threshold 50
    header_up -<redacted>

5. Links to relevant resources:

1 Like

You’re the first person I know who is using the circuit breaker.

It does not currently support the Caddyfile. Someone will need to write the UnmarshalCaddyfile() method.

(I would, but I don’t have time right now.)

1 Like

FWIW the config would look like this (because the module’s ID is simple)

	circuit_breaker simple {
		threshold 50

But yeah, PRs welcome for adding a circuit_breaker option which loads a http.reverse_proxy.circuit_breakers.* module

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.