i'm trying to use NGINX ngx_http_api_module to control list of upstream servers. So far, I had a success with adding new servers to upstream. But I noticed that I'm unable to delete the servers that have been added via API. The server's ID that was assigned by NGINX is incorrect.
Example:
# add new server to upstream
curl -X POST -d '{"server": "clickhouse-01:8123", "weight": 1 }' -s http://localhost:80/api/6/http/upstreams/clickhouse_8123/servers
# output
{"id":0,"server":"clickhouse-01:8123","weight":1,"max_conns":0,"max_fails":1,"fail_timeout":"10s","slow_start":"0s","route":"","backup":false,"down":false}%
curl -X POST -d '{"server": "clickhouse-02:8123", "weight": 1 }' -s http://localhost:80/api/6/http/upstreams/clickhouse_8123/servers
# output
{"id":2,"server":"clickhouse-02:8123","weight":1,"max_conns":0,"max_fails":1,"fail_timeout":"10s","slow_start":"0s","route":"","backup":false,"down":false}%
# list available servers
curl localhost:80/api/6/http/upstreams/clickhouse_8123 |jq -c '.peers[] | {name, id}'
# output
{"server":"clickhouse-01:8123","id":1}
{"server":"clickhouse-02:8123","id":3}
So, it's noticeable that ID assinged to host during POST doesn't correspond with the ID shown in GET method;
When I try to delete the host by the ID from GET method, I get the following error:
curl -X DELETE -s 'http://localhost:80/api/6/http/upstreams/clickhouse_8123/servers/3'
#output
{"error":{"status":400,"text":"server not removable","code":"UpstreamServerImmutable"},"request_id":"c04d78b3b30baeb79af31b457419a506","href":"https://nginx.org/en/docs/http/ngx_http_api_module.html"}%
But if I use the ID from POST response, everything is OK:
curl -X DELETE -s 'http://localhost:80/api/6/http/upstreams/clickhouse_8123/servers/2'
#output
(here goes the list of upstream hosts without clickhouse-02)
The documentation I used: https://docs.nginx.com/nginx/admin-guide/load-balancer/dynamic-configuration-api/#using-the-api-for-dynamic-configuration