Skip to content

Commit

Permalink
Feat(): Set UNICORN_SIDEKIQ_MAX_RSS env variable (#307)
Browse files Browse the repository at this point in the history
* Feat(): Set `UNICORN_SIDEKIQ_MAX_RSS` env variable

* Chore(test): Add unit test for env variable

* Chore(): Lint
  • Loading branch information
alithethird authored Dec 9, 2024
1 parent 105065e commit 1f98f1b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1f98f1b

Please sign in to comment.