From 7c2b4bead2e5334acd43a3dc42dd42a74fd346ba Mon Sep 17 00:00:00 2001 From: Michal Arbet Date: Mon, 15 Feb 2021 14:14:31 +0100 Subject: [PATCH] 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 --- .../haproxy_single_service_split.cfg.j2 | 7 ++++++- .../high-availability/haproxy-guide.rst | 17 +++++++++++++++++ ...service-backend-weight-e4a908f732a37b42.yaml | 10 ++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/haproxy-service-backend-weight-e4a908f732a37b42.yaml diff --git a/ansible/roles/haproxy-config/templates/haproxy_single_service_split.cfg.j2 b/ansible/roles/haproxy-config/templates/haproxy_single_service_split.cfg.j2 index f5e2fa9f7a..eb3547ea60 100644 --- a/ansible/roles/haproxy-config/templates/haproxy_single_service_split.cfg.j2 +++ b/ansible/roles/haproxy-config/templates/haproxy_single_service_split.cfg.j2 @@ -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 %} diff --git a/doc/source/reference/high-availability/haproxy-guide.rst b/doc/source/reference/high-availability/haproxy-guide.rst index ae7d90171e..008526b032 100644 --- a/doc/source/reference/high-availability/haproxy-guide.rst +++ b/doc/source/reference/high-availability/haproxy-guide.rst @@ -45,3 +45,20 @@ This is especially helpful for connections to MariaDB. See `here `__ and `here `__ 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 diff --git a/releasenotes/notes/haproxy-service-backend-weight-e4a908f732a37b42.yaml b/releasenotes/notes/haproxy-service-backend-weight-e4a908f732a37b42.yaml new file mode 100644 index 0000000000..1c75ddadf6 --- /dev/null +++ b/releasenotes/notes/haproxy-service-backend-weight-e4a908f732a37b42.yaml @@ -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.