Skip to content

Commit 69b2c13

Browse files
[DPE-3095] Fix profile limit memory config option (#348)
* Update data-platform-workflows to v7 * Fix profile limit memory config option Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Add related unit tests Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Remove unused calls in unit test Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Add CRAFT_SHARED_CACHE env variable to charmcraft pack wrapper Signed-off-by: Marcelo Henrique Neppel <[email protected]> --------- Signed-off-by: Marcelo Henrique Neppel <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent 5a21d70 commit 69b2c13

File tree

11 files changed

+175
-19
lines changed

11 files changed

+175
-19
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ on:
2222
jobs:
2323
lint:
2424
name: Lint
25-
uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v6.3.3
25+
uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v7.0.0
2626

2727
unit-test:
2828
name: Unit test charm
@@ -45,7 +45,7 @@ jobs:
4545

4646
build:
4747
name: Build charm
48-
uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v6.3.3
48+
uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v7.0.0
4949
permissions:
5050
actions: write # Needed to manage GitHub Actions cache
5151

@@ -62,7 +62,7 @@ jobs:
6262
- lint
6363
- unit-test
6464
- build
65-
uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v6.3.3
65+
uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v7.0.0
6666
with:
6767
artifact-name: ${{ needs.build.outputs.artifact-name }}
6868
cloud: microk8s

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ jobs:
4141

4242
build:
4343
name: Build charm
44-
uses: canonical/data-platform-workflows/.github/workflows/build_charm_without_cache.yaml@v6.3.3
44+
uses: canonical/data-platform-workflows/.github/workflows/build_charm_without_cache.yaml@v7.0.0
4545

4646
release:
4747
name: Release charm
4848
needs:
4949
- ci-tests
5050
- build
51-
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v6.3.3
51+
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v7.0.0
5252
with:
5353
channel: 14/edge
5454
artifact-name: ${{ needs.build.outputs.artifact-name }}

.github/workflows/sync_issue_to_jira.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
sync:
1111
name: Sync GitHub issue to Jira
12-
uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v6.3.3
12+
uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v7.0.0
1313
with:
1414
jira-base-url: https://warthogs.atlassian.net
1515
jira-project-key: DPE

config.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,19 @@ options:
228228
type: string
229229
default: "production"
230230
profile-limit-memory:
231+
type: int
232+
description: |
233+
[DEPRECTATED] Use profile_limit_memory instead. Amount of memory in Megabytes to limit PostgreSQL
234+
and associated process to. If unset, this will be decided according to the default memory limit
235+
in the selected profile. Only comes into effect when the `production` profile is selected. This
236+
config option cannot be set at the same time as profile_limit_memory.
237+
profile_limit_memory:
231238
type: int
232239
description: |
233240
Amount of memory in Megabytes to limit PostgreSQL and associated process to.
234241
If unset, this will be decided according to the default memory limit in the selected profile.
235-
Only comes into effect when the `production` profile is selected.
242+
Only comes into effect when the `production` profile is selected. This config option cannot be
243+
set at the same time as profile-limit-memory.
236244
request_date_style:
237245
description: |
238246
Sets the display format for date and time values. Allowed formats are explained

poetry.lock

Lines changed: 30 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ optional = true
7070
[tool.poetry.group.integration.dependencies]
7171
lightkube = "^0.15.0"
7272
pytest = "^7.4.3"
73-
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v6.3.3", subdirectory = "python/pytest_plugins/github_secrets"}
73+
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v7.0.0", subdirectory = "python/pytest_plugins/github_secrets"}
7474
pytest-operator = "^0.31.0"
75-
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v6.3.3", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
76-
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v6.3.3", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
75+
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v7.0.0", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
76+
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v7.0.0", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
7777
juju = "^3.2.2"
7878
psycopg2 = {version = "^2.9.9", extras = ["binary"]}
7979
boto3 = "^1.33.1"

src/charm.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,13 @@ def _is_workload_running(self) -> bool:
13381338
def update_config(self, is_creating_backup: bool = False) -> bool:
13391339
"""Updates Patroni config file based on the existence of the TLS files."""
13401340
# Retrieve PostgreSQL parameters.
1341+
if (
1342+
self.model.config.get("profile-limit-memory") is not None
1343+
and self.model.config.get("profile_limit_memory") is not None
1344+
):
1345+
raise ValueError(
1346+
"Both profile-limit-memory and profile_limit_memory are set. Please use only one of them."
1347+
)
13411348
if self.config.profile_limit_memory:
13421349
limit_memory = self.config.profile_limit_memory * 10**6
13431350
else:

src/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def profile_limit_memory_validator(cls, value: int) -> Optional[int]:
203203
if value < 128:
204204
raise ValueError("PostgreSQL Charm requires at least 128MB")
205205
if value > 9999999:
206-
raise ValueError("`profile-limit-memory` limited to 7 digits (9999999MB)")
206+
raise ValueError("`profile_limit_memory` limited to 7 digits (9999999MB)")
207207

208208
return value
209209

tests/unit/test_charm.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,3 +916,74 @@ def test_migartion(self, scope):
916916
secret_label = self.harness.charm.set_secret(scope, "my-secret", "blablabla")
917917
assert self.harness.charm.model.get_secret(label=secret_label)
918918
assert self.harness.charm.get_secret(scope, "my-secret") == "blablabla"
919+
920+
@patch(
921+
"charm.PostgresqlOperatorCharm._is_workload_running",
922+
new_callable=PropertyMock(return_value=False),
923+
)
924+
@patch(
925+
"upgrade.PostgreSQLUpgrade.is_no_sync_member",
926+
new_callable=PropertyMock(return_value=False),
927+
)
928+
@patch("charm.Patroni.render_patroni_yml_file")
929+
def test_update_config(
930+
self, _render_patroni_yml_file, _is_no_sync_member, _is_workload_running
931+
):
932+
# Test when no config option is changed.
933+
parameters = {
934+
"synchronous_commit": "on",
935+
"default_text_search_config": "pg_catalog.simple",
936+
"password_encryption": "scram-sha-256",
937+
"log_connections": False,
938+
"log_disconnections": False,
939+
"log_lock_waits": False,
940+
"log_min_duration_statement": -1,
941+
"maintenance_work_mem": 65536,
942+
"max_prepared_transactions": 0,
943+
"temp_buffers": 1024,
944+
"work_mem": 4096,
945+
"constraint_exclusion": "partition",
946+
"default_statistics_target": 100,
947+
"from_collapse_limit": 8,
948+
"join_collapse_limit": 8,
949+
"DateStyle": "ISO, MDY",
950+
"standard_conforming_strings": True,
951+
"TimeZone": "UTC",
952+
"bytea_output": "hex",
953+
"lc_monetary": "C",
954+
"lc_numeric": "C",
955+
"lc_time": "C",
956+
"autovacuum_analyze_scale_factor": 0.1,
957+
"autovacuum_analyze_threshold": 50,
958+
"autovacuum_freeze_max_age": 200000000,
959+
"autovacuum_vacuum_cost_delay": 2.0,
960+
"autovacuum_vacuum_scale_factor": 0.2,
961+
"vacuum_freeze_table_age": 150000000,
962+
"shared_buffers": "0MB",
963+
"effective_cache_size": "0MB",
964+
}
965+
self.charm.update_config()
966+
_render_patroni_yml_file.assert_called_once_with(
967+
connectivity=True,
968+
is_creating_backup=False,
969+
enable_tls=False,
970+
is_no_sync_member=False,
971+
backup_id=None,
972+
stanza=None,
973+
restore_stanza=None,
974+
parameters=parameters,
975+
)
976+
977+
# Test when only one of the two config options for profile limit memory is set.
978+
self.harness.update_config({"profile-limit-memory": 1000})
979+
self.charm.update_config()
980+
981+
# Test when only one of the two config options for profile limit memory is set.
982+
self.harness.update_config({"profile_limit_memory": 1000}, unset={"profile-limit-memory"})
983+
self.charm.update_config()
984+
985+
# Test when the two config options for profile limit memory are set at the same time.
986+
_render_patroni_yml_file.reset_mock()
987+
self.harness.update_config({"profile-limit-memory": 1000})
988+
with self.assertRaises(ValueError):
989+
self.charm.update_config()

0 commit comments

Comments
 (0)