Skip to content

feat: Support runtime control of connection rate limiting via socket#930

Open
b1tamara wants to merge 2 commits into
cloudfoundry:masterfrom
sap-contributions:introduce-vars
Open

feat: Support runtime control of connection rate limiting via socket#930
b1tamara wants to merge 2 commits into
cloudfoundry:masterfrom
sap-contributions:introduce-vars

Conversation

@b1tamara
Copy link
Copy Markdown
Contributor

@b1tamara b1tamara commented Jun 1, 2026

The PR introduces process-level variables (for the properties block and connections) for the connection rate limit feature, enabling runtime control via the HAProxy Runtime API. It allows dynamic start/stop of rate limiting and on-the-fly threshold changes
Co-Authored-By: @Dariquest and @Mrizwanshaik

Co-authored-by: Alexander Nicke <alexander.nicke@sap.com>
Co-authored-by: Dariquest <daria.anton@sap.com>
Co-authored-by: M Rizwan Shaik <m.rizwan.shaik@sap.com>
@b1tamara b1tamara requested review from a team and CFN-CI as code owners June 1, 2026 10:15
@b1tamara b1tamara added the run-ci Allow this PR to be tested on Concourse label Jun 1, 2026
@b1tamara b1tamara removed the run-ci Allow this PR to be tested on Concourse label Jun 2, 2026
@b1tamara b1tamara added the run-ci Allow this PR to be tested on Concourse label Jun 2, 2026
if_p("ha_proxy.connections_rate_limit.table_size", "ha_proxy.connections_rate_limit.window_size") do
if p("ha_proxy.connections_rate_limit.block", false)
if !p("ha_proxy.connections_rate_limit.connections", nil)
abort "Conflicting configuration: connections_rate_limit.connections must be set when connections_rate_limit.block is true (otherwise every client with >= 1 connection would be blocked)"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The abort is reasonable as a UX guard, but the rationale ("every client with >= 1 connection would be blocked") is not what would actually happen with the new rule: when proc.conn_rate_limit is undefined, the second guard { var(proc.conn_rate_limit) -m int gt 0 } evaluates falsy and the reject does not fire. So the real failure mode is "block flag honored but never enforced" (silent no-op), not "everyone locked out". The latter was true of the old reject rule format, but no longer applies. Suggest rewording, e.g.:

Suggested change
abort "Conflicting configuration: connections_rate_limit.connections must be set when connections_rate_limit.block is true (otherwise every client with >= 1 connection would be blocked)"
abort "connections_rate_limit.connections must be set in the manifest as the initial threshold when block is true; otherwise rate-limiting will be silently disabled until a value is set via the runtime API."

Comment thread docs/rate_limiting.md

The `connections_rate_limit.block` flag and `connections_rate_limit.connections` threshold are stored as HAProxy process-level variables (`proc.conn_rate_block` and `proc.conn_rate_limit`) and can be changed at runtime without a reload. This requires `ha_proxy.master_cli_enable: true` or `ha_proxy.stats_enable: true`.

The socket is located at `/var/vcap/sys/run/haproxy/stats.sock`. You will likely need `sudo` to access it.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The socket is located at `/var/vcap/sys/run/haproxy/stats.sock`. You will likely need `sudo` to access it.
The socket is located at `/var/vcap/sys/run/haproxy/stats.sock`. You will likely need `root` permissions to access it.

Comment thread docs/rate_limiting.md

> Note: You will likely need `sudo` permission to run socat.

## Control Connection Rate Limiting via HAProxy Runtime API
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make the two new proc. variables more prominent, by introducing them in an unsorted list, similar to the variables and options listed in the section "Configuration Options". It was first a bit hard for me to understand why we have these proc variables now.

One point about the naming:
connections_rate_limit.block -> proc.conn_rate_block
connections_rate_limit.connections -> proc.conn_rate_limit

Is inconsistent. If we could still change the it and accept it's breaking, I'd prefer the following variable naming:

connection_rate_limit.enabled -> proc.connection_rate_limit_enabled
connection_rate_limit.connections -> proc.connection_rate_limit_connections

This would be more consistent, and having enabled instead of block indicates that this is a boolean switch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci Allow this PR to be tested on Concourse

Projects

Development

Successfully merging this pull request may close these issues.

2 participants