From edf7791f4032951ccfaa336c7ccd734bdef1873d Mon Sep 17 00:00:00 2001 From: Kevin Nasto Date: Wed, 29 May 2024 12:26:51 -0500 Subject: [PATCH] Add consumer-timeout config option Exposes the consumer timeout configuration value that was changed in the jammy version of rabbitmq. The value used to default to unlimited, but was changed to 30 minutes. This causes clients to timeout for longer-running jobs. This change doesn't alter the payload's default value, it override it only when the user provides a value via juju config. Closes-Bug: #2020909 Related-Bug: #2067424 Change-Id: I552c04c964c98b2a700cd47e98a2ae491f5fd47b --- config.yaml | 10 ++++++++++ hooks/rabbitmq_context.py | 3 +++ templates/rabbitmq.conf | 4 ++++ unit_tests/test_rabbitmq_context.py | 2 ++ 4 files changed, 19 insertions(+) diff --git a/config.yaml b/config.yaml index d33f3b90..86f76f4b 100644 --- a/config.yaml +++ b/config.yaml @@ -166,6 +166,16 @@ options: internally to the charm if no value is set here. Also, if this value is left unset and this application is running inside a container, the number of threads will be capped based on a maximum of 2 cores. + consumer-timeout: + type: int + default: + description: | + Timeout value in milliseconds. If a consumer does not ack its delivery + for more than the timeout value, its channel will be closed. If the value + is not specified and rabbitmq version is 3.9 and above, then 30 minutes is the + default. For 3.8 the default value is unlimited. For before that then this feature + is not supported (timeout is unlimited). (See + https://www.rabbitmq.com/docs/consumers#acknowledgement-timeout for more info). # SSL configuration ssl: type: string diff --git a/hooks/rabbitmq_context.py b/hooks/rabbitmq_context.py index 14280eb8..2b471cae 100644 --- a/hooks/rabbitmq_context.py +++ b/hooks/rabbitmq_context.py @@ -200,6 +200,9 @@ class RabbitMQClusterContext(object): if config('connection-backlog'): ctxt['connection_backlog'] = config('connection-backlog') + if config('consumer-timeout'): + ctxt['consumer_timeout'] = config('consumer-timeout') + if cmp_pkgrevno('rabbitmq-server', '3.6') >= 0: ctxt['queue_master_locator'] = config('queue-master-locator') diff --git a/templates/rabbitmq.conf b/templates/rabbitmq.conf index 97c7dfb1..3f557185 100644 --- a/templates/rabbitmq.conf +++ b/templates/rabbitmq.conf @@ -8,6 +8,10 @@ listeners.tcp = none tcp_listen_options.backlog = {{connection_backlog}} {%- endif %} +{%- if consumer_timeout %} +consumer_timeout = {{consumer_timeout}} +{%- endif %} + {%- if ssl_port %} listeners.ssl.1 = {{ ssl_port }} {%- endif %} diff --git a/unit_tests/test_rabbitmq_context.py b/unit_tests/test_rabbitmq_context.py index 309e871c..0a05a31e 100644 --- a/unit_tests/test_rabbitmq_context.py +++ b/unit_tests/test_rabbitmq_context.py @@ -117,6 +117,7 @@ class TestRabbitMQClusterContext(unittest.TestCase): mock_leader_get.return_value = 'ignore' config_data = {'cluster-partition-handling': 'ignore', 'connection-backlog': 200, + 'consumer-timeout': 20000, 'mnesia-table-loading-retry-timeout': 25000, 'mnesia-table-loading-retry-limit': 12, 'queue-master-locator': 'client-local'} @@ -129,6 +130,7 @@ class TestRabbitMQClusterContext(unittest.TestCase): 'mnesia_table_loading_retry_timeout': 25000, 'mnesia_table_loading_retry_limit': 12, 'connection_backlog': 200, + 'consumer_timeout': 20000, 'queue_master_locator': 'client-local', })