Hi! I am using HAProxy and I would like to use the Data Plane API to dynamically configure the proxy at runtime. I am looking for an API that allows updating the balancing weights of servers within a backend, but I have not found a specific endpoint for this purpose. The only relevant option I found is:
PUT /services/haproxy/configuration/backends/{parent_name}/servers/{name} (docs), but it seems this endpoint requires a proxy reload. Is there a way to update server weights without reloading the proxy and without relying on the socket based API?
Hi, after digging into the Data Plane API v3 documentation and doing some testing, I found the following two APIs:
- PUT
/services/haproxy/runtime/backends/{parent_name}/servers/{name}(doc) - POST
/services/haproxy/runtime/backends/{parent_name}/servers(doc)
These are sufficient to avoid restarting the proxy. I was missing the “runtime” part of the API path.
The only minor issue is that the Data Plane API does not seem to expose the current weights, even though they are applied and used by HAProxy for load balancing. However, this is not really a problem for my use case.
cURL logs
$ curl -s -u admin:admin "http://localhost:30555/v3/services/haproxy/runtime/backends/function_figlet_forwarded/servers" | jq
[
{
"address": "IP_X",
"admin_state": "ready",
"id": "1",
"name": "openfaas-local",
"operational_state": "up",
"port": 31112
},
{
"address": "IP_Y",
"admin_state": "ready",
"id": "2",
"name": "test",
"operational_state": "up",
"port": 31112
}
]
$ curl -s -u admin:admin -X PUT "http://localhost:30555/v3/services/haproxy/runtime/backends/function_figlet_forwarded/servers/openfaas-local" -H "Content-Type: application/json" -d '{"weight": 80}' | jq
{
"address": "IP_X",
"admin_state": "ready",
"id": "1",
"name": "openfaas-local",
"operational_state": "up",
"port": 31112
}
$ curl -s -u admin:admin "http://localhost:30555/v3/services/haproxy/runtime/backends/function_figlet_forwarded/servers" | jq
[
{
"address": "IP_X",
"admin_state": "ready",
"id": "1",
"name": "openfaas-local",
"operational_state": "up",
"port": 31112
},
{
"address": "IP_Y",
"admin_state": "ready",
"id": "2",
"name": "test",
"operational_state": "up",
"port": 31112
}
]