diff --git a/config.yaml b/config.yaml index 446ced93..fb0ceeff 100644 --- a/config.yaml +++ b/config.yaml @@ -138,3 +138,8 @@ options: type: string description: "Throttle level - blocks excessive usage by ip. Accepted values: none, permissive, strict." default: none + sidekiq_max_memory: + description: Maximum memory for sidekiq in megabytes. This configuration + will set the UNICORN_SIDEKIQ_MAX_RSS environment variable. + type: int + default: 1000 diff --git a/src/charm.py b/src/charm.py index 52228db7..9c7989d9 100755 --- a/src/charm.py +++ b/src/charm.py @@ -453,6 +453,7 @@ def _create_discourse_environment_settings(self) -> typing.Dict[str, str]: "DISCOURSE_SMTP_PORT": str(self.config["smtp_port"]), "DISCOURSE_SMTP_USER_NAME": self.config["smtp_username"], "RAILS_ENV": "production", + "UNICORN_SIDEKIQ_MAX_RSS": str(self.config["sidekiq_max_memory"]), } pod_config.update(self._get_saml_config()) diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 4bba490c..ecf9ebce 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -516,6 +516,28 @@ def bundle_handler(args: ops.testing.ExecArgs) -> None: assert expected_exec_call_was_made +def test_sidekiq_env_variable(): + """ + arrange: given a deployed discourse charm with all the required relations + act: trigger the pebble ready event on a leader unit + assert: the pebble plan gets updated + """ + harness = helpers.start_harness(run_initial_hooks=False) + + harness.set_can_connect(CONTAINER_NAME, True) + harness.container_pebble_ready(CONTAINER_NAME) + plan_before_set_config = ( + harness.get_container_pebble_plan(CONTAINER_NAME).services["discourse"].environment + ) + harness.update_config({"sidekiq_max_memory": 500}) + plan_after_set_config = ( + harness.get_container_pebble_plan(CONTAINER_NAME).services["discourse"].environment + ) + assert plan_before_set_config != plan_after_set_config + assert "1000" in plan_before_set_config["UNICORN_SIDEKIQ_MAX_RSS"] + assert "500" in plan_after_set_config["UNICORN_SIDEKIQ_MAX_RSS"] + + def test_handle_pebble_ready_event(): """ arrange: given a deployed discourse charm with all the required relations