Add way to change weight of haproxy backend per service

This patch adding option to control weight of haproxy
backends per service via host variable.

Example:

[control]
server1 haproxy_nova_api_weight=10
server2 haproxy_nova_api_weight=2 haproxy_keystone_internal_weight=10
server3 haproxy_keystone_admin_weight=50

If weight is not defined, everything is working as before.

Change-Id: Ie8cc228198651c57f8ffe3eb060875e45d1f0700
This commit is contained in:
Michal Arbet 2021-02-15 14:14:31 +01:00
parent 18fd27feff
commit 7c2b4bead2
3 changed files with 33 additions and 1 deletions

View File

@ -93,7 +93,12 @@ backend {{ service_name }}_back
{% for host in groups[host_group] %}
{% set host_name = hostvars[host]['ansible_hostname'] %}
{% set host_ip = 'api' | kolla_address(host) %}
server {{ host_name }} {{ host_ip }}:{{ listen_port }} {{ haproxy_health_check_final }} {{ backend_tls_info }}
{% set service_weight = 'haproxy_' + service_name + '_weight' %}
{% set backend_weight_info = '' %}
{% if hostvars[host][service_weight] is defined and hostvars[host][service_weight] | int != 0 and hostvars[host][service_weight] <= 256 %}
{% set backend_weight_info = 'weight %s'|format(hostvars[host][service_weight]) %}
{% endif %}
server {{ host_name }} {{ host_ip }}:{{ listen_port }} {{ haproxy_health_check_final }} {{ backend_tls_info }} {{ backend_weight_info }}
{% endfor %}
{% endif %}
{% endmacro %}

View File

@ -45,3 +45,20 @@ This is especially helpful for connections to MariaDB. See
`here <https://blog.cloudflare.com/when-tcp-sockets-refuse-to-die/>`__ and
`here <https://access.redhat.com/solutions/726753>`__ for
further information about this kernel option.
Backend weights
---------------
When different baremetal are used in infrastructure as haproxy backends
or they are overloaded for some reason, kolla-ansible is able to change
weight of backend per sevice. Weight can be any integer value from 1 to
256.
To set weight of backend per service, modify inventory file as below:
.. code-block:: ini
[control]
server1 haproxy_nova_api_weight=10
server2 haproxy_nova_api_weight=2 haproxy_keystone_internal_weight=10
server3 haproxy_keystone_admin_weight=50

View File

@ -0,0 +1,10 @@
---
features:
- |
The haproxy-config role now allows user to set weight per
haproxy's backend. This can be achieved by setting a hostvar
``haproxy_{{ service }}_weight`` in inventory file to any integer
value in range from 1 to 256, so the higher the weight, the higher
the load. This can be set per ``{{ service }}``. If hostvar is not
specified, backend's weight is not rendered in final haproxy
configuration.