From 9362f5cfa93fa2e81f81d7865c84a779190b8864 Mon Sep 17 00:00:00 2001 From: Felipe Reyes Date: Tue, 4 Mar 2025 12:57:04 -0300 Subject: [PATCH] Add config option healthcheck-timeout This new configuration option allows to fine tune how long haproxy should wait before considering the healthcheck failed. This will be helpful for hyperconverged environments. https://www.haproxy.com/documentation/haproxy-configuration-manual/latest/#4-timeout%20check Change-Id: Ib2b03af19ed2aa7aaae32343452522a6f466a046 Closes-Bug: #2098804 Signed-off-by: Felipe Reyes --- config.yaml | 7 +++++++ hooks/keystone_context.py | 5 +++++ unit_tests/test_keystone_contexts.py | 5 ++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/config.yaml b/config.yaml index 03bb57ff..bba86817 100644 --- a/config.yaml +++ b/config.yaml @@ -494,3 +494,10 @@ options: When set to `True`, Keystone will be configured to send notifications using the `messagingv2` driver. The default value is `False`, meaning notifications are disabled unless explicitly enabled. + healthcheck-timeout: + type: int + default: 5000 + description: | + Set additional check timeout (in milisecond), but only after a connection + has been already established. This allows to give a better chance to the + backend to reply when the query is slow. diff --git a/hooks/keystone_context.py b/hooks/keystone_context.py index 1b6258bf..3d108ea7 100644 --- a/hooks/keystone_context.py +++ b/hooks/keystone_context.py @@ -43,6 +43,9 @@ from charmhelpers.contrib.openstack.utils import ( ) +MIN_HEALTHCHECK_TIMEOUT = 1 # msecs + + class MiddlewareContext(context.OSContextGenerator): interfaces = ['keystone-middleware'] @@ -166,6 +169,8 @@ class HAProxyContext(context.HAProxyContext): healthcheck = [{ 'option': 'httpchk GET /healthcheck', 'http-check': 'expect status 200', + 'timeout check': str(max(MIN_HEALTHCHECK_TIMEOUT, + config('healthcheck-timeout'))), }] backend_options = { diff --git a/unit_tests/test_keystone_contexts.py b/unit_tests/test_keystone_contexts.py index b703180d..249fc39d 100644 --- a/unit_tests/test_keystone_contexts.py +++ b/unit_tests/test_keystone_contexts.py @@ -108,11 +108,13 @@ class TestKeystoneContexts(CharmTestCase): is_ipv6_disabled, mock_https): os.environ['JUJU_UNIT_NAME'] = 'keystone' + self.test_config.set('healthcheck-timeout', 3000) + mock_relation_ids.return_value = ['identity-service:0', ] mock_get_relation_ip.return_value = '1.2.3.4' mock_relation_get.return_value = '10.0.0.0' mock_related_units.return_value = ['unit/0', ] - mock_config.return_value = None + mock_config.side_effect = self.test_config.get mock_get_address_in_network.return_value = None mock_get_netmask_for_address.return_value = '255.255.255.0' self.determine_apache_port.return_value = '34' @@ -125,6 +127,7 @@ class TestKeystoneContexts(CharmTestCase): healthcheck = [{ 'option': 'httpchk GET /healthcheck', 'http-check': 'expect status 200', + 'timeout check': '3000', }] self.maxDiff = None