caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
55.45k stars 3.91k forks source link

Load balancer sticky cookie should have a Max-Age configuration #6393

Open JasonYuan869 opened 2 weeks ago

JasonYuan869 commented 2 weeks ago

I have a service routed with the following

reverse_proxy backend-blue:3000 backend-green:3000 {
    lb_policy cookie {
        fallback first
    }
}

This allows me to do zero-downtime upgrades on a stateful service by switching the order of the upstreams.

I think it would be useful to allow configuration of a Max-Age property for the cookie to ensure that eventually a client application will use the new backend when the cookie expires.

If this is a feature that seems appropriate for the project, I would love to help contribute!

mholt commented 2 weeks ago

Thanks for the issue. Do you have any suggestions as to what the config would look like for that?

JasonYuan869 commented 2 weeks ago

Perhaps something like this?

reverse_proxy backend-blue:3000 backend-green:3000 {
    lb_policy cookie {
        fallback first
        max_age 3600  # 1 hour
    }
}

It definitely makes more sense to use Max-Age over Expires since we're not trying to hardcode a specific expiration time but rather tell the cookie to refresh after X duration.

mholt commented 2 weeks ago

That LGTM. Want to submit a PR? :smiley:

mohammed90 commented 2 weeks ago

Consider using caddy.Duration