Skip to content

Conversation

dragomirp
Copy link
Contributor

@dragomirp dragomirp commented Nov 21, 2024

Port of canonical/postgresql-operator#672
Implements DA135 configuration for synchronous node count.

  • Adds logic to update the number of synchronous standbys and sets all replicas to sync.
  • Adds all and majority sync standby policies and ability to set constant number of sync standbys.

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

Attention: Patch coverage is 68.75000% with 10 lines in your changes missing coverage. Please review.

Project coverage is 75.48%. Comparing base (62f5987) to head (f628e2c).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/charm.py 53.84% 6 Missing ⚠️
src/patroni.py 73.33% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #784      +/-   ##
==========================================
- Coverage   75.56%   75.48%   -0.09%     
==========================================
  Files          12       12              
  Lines        3127     3157      +30     
  Branches      467      471       +4     
==========================================
+ Hits         2363     2383      +20     
- Misses        623      632       +9     
- Partials      141      142       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dragomirp dragomirp marked this pull request as ready for review November 21, 2024 23:14
Comment on lines 513 to 528
async def get_leader(model: Model, application_name: str) -> str:
"""Get the standby leader name.
Args:
model: the model instance.
application_name: the name of the application to get the value for.
Returns:
the name of the standby leader.
"""
status = await model.get_status()
first_unit_ip = list(status["applications"][application_name]["units"].values())[0]["address"]
cluster = get_patroni_cluster(first_unit_ip)
for member in cluster["members"]:
if member["role"] == "leader":
return member["name"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_primary from the main helpers is not model aware.

Comment on lines -436 to -428
new_sync_standby = await get_sync_standby(first_model, DATABASE_APP_NAME)
logger.info(f"New sync-standby: {new_sync_standby}")
assert new_sync_standby != sync_standby, "Sync-standby is the same as before"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sync standby will not change, since all the replicas are sync standbys.

@dragomirp dragomirp requested review from a team, lucasgameiroborges, marceloneppel and taurus-forever and removed request for a team November 21, 2024 23:18
Copy link
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The great job done! Thank you!

@dragomirp dragomirp added the enhancement New feature, UI change, or workload upgrade label Feb 14, 2025
@dragomirp dragomirp merged commit 842aa47 into main Feb 18, 2025
96 checks passed
@dragomirp dragomirp deleted the dpe-5827-all-sync branch February 18, 2025 22:08
dragomirp added a commit that referenced this pull request Mar 19, 2025
* try using pg 16 rock

* try fix integration tests

* remove argument on helper

* more fixes

* fix test issues

* REVERT LATER: Adapt build_charm function

* remove base=CHARM_BASE from deploy

* remove juju 2.9 tests

* grat permissions to public schema

* fix linting and unit test

* try refactor the permissions change

* Update dependency uv to v0.5.27 (#847)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* grant public access to public schemas

* [DPE-6053] Fix ports (#846)

* Fix ports

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>

* Remove unused import

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>

* Remove unused charm library and fix unit tests

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>

* Fix identation

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>

* Bump libs

* Conditional set_ports logic

* Unit test

* Don't expect juju managed resources

---------

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Co-authored-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>

* mark smoke test as unstable

* test release charm to 16/edge

* fix test release workflow

* fix typo

* Sync docs from Discourse (#801)

Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>

* Update dependency uv to v0.5.29 (#848)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* [MISC] Define charm utility properties (#842)

* Update data-platform-workflows to v29.1.0 (#849)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* revert metadata.yaml

* nits

* Use `charmcraft test` & concierge (#852)

* [MISC] Split topology script (#853)

* Update charmcraft.yaml build tools (#851)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency uv to v0.5.31 (#858)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update canonical/data-platform-workflows action to v30 (#859)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Use _promote_charm.yaml (#860)

Use `charmcraft promote` and auto-generate release notes

* Update dependency cryptography to v44.0.1 [SECURITY] (#855)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Sync docs from Discourse (#854)

Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>

* Update data-platform-workflows to v30.0.2 (#863)

* Update canonical/has-signed-canonical-cla action to v2 (#865)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* [DPE-5827] Set all nodes to synchronous replicas (#784)

* Update patroni configuration

* Update test assertion

* Copy update_synchronous_node_count from VM

* Add unit test

* Set sync node count during upgrade

* Fix tls test

* Switchover primary

* Add different helper to get leader

* Add config boilerplate

* Use config value when setting sync node count

* Escape tuple

* Add policy values

* Add integration test

* Fix casting

* Fix test

* Update to spec

* Bump retry timout

* Switch to planned units

* Fix generator

* Update conf description

* Spread task

* Pass the charm

* [DPE-6484] Add scope to promote to primary (#850)

* Promote unit action

* Tweaks for failing REST calls

* VM parity

* [MISC] Enable RBAC in tests (#861)

* Enable RBAC

* Bump cosl

* Add trust

* Bump libs

* [MISC] Define charm constants (#862)

* Lock file maintenance Python dependencies (#835)

* Lock file maintenance Python dependencies

* Backoff boto3 1.36

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Dragomir Penev <dragomir.penev@canonical.com>

* Update canonical/data-platform-workflows action to v30.1.3 (#856)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update charmcraft.yaml build tools (#868)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Handle missing stanza output (#866)

* Update ghcr.io/canonical/charmed-postgresql:14.15-22.04_edge Docker digest to 71d49b6 (#870)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* [MISC] Disable storage test on arm (#872)

* Disable storage test on Arm

* Bump libs

* Correct import path

* Update charmcraft.yaml build tools (#871)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* [MISC] Add degraded status to primary message (#874)

* Add degraded status on to primary message

* Use const running tests

* [MISC] Sanitize PostgreSQL extra-user-roles arg (#876)

* [MISC] Fix PostgreSQL lib function signature (#879)

* [MISC] Skip backup tests without creds (#884)

* Bump libs

* Skip backups tests if no creds are set

* Check that the cloud config is set to a value

* Typo

* Update tests/integration/conftest.py

Co-authored-by: Carl Csaposs <carl.csaposs@canonical.com>

* Switch all checks to gets

* Typo

---------

Co-authored-by: Carl Csaposs <carl.csaposs@canonical.com>

* [DPE-6679] PostgreSQL Config Improvement (#867)

* config improvement

* config improvement

* config improvement

* config improvement

* config improvement

* config improvement

* config improvement

* config improvement

* config improvement

* config improvement

* Update dependency jinja2 to v3.1.6 [SECURITY] (#882)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update canonical/data-platform-workflows action to v30.2.0 (#887)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Reduce required approvals on Renovate pull requests by 1 (#880)

* Update dependency uv to v0.6.5 (#878)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Don't run juju2 and legacy tests

* Use correct charm

* Dual branch config

* Remove 14 specific tests

* Remove eer data secrets

* Skip upgrade from stable

* Upgrade on Noble

* Build and deploy noble

* Linting

* Disable pgaudit during tests

* Linting

* Use common deploy for smoke test

* Tweaks

* Remove legacy rels

* Tweak tests

* Cleanup markers

* Deploy without pgaudit in plugin tests

* Update ghcr.io/canonical/charmed-postgresql Docker tag to v14.17 (#877)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Correct remove relation

* Bump rock

* Remove check for port forwarding

---------

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Co-authored-by: Lucas Gameiro Borges <lucas.borges@canonical.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Dragomir Penev <6687393+dragomirp@users.noreply.github.com>
Co-authored-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Sinclert Pérez <sinclert.perez@canonical.com>
Co-authored-by: lucas.gameiro-borges <lucas.gameiro-borges@student-cs.fr>
Co-authored-by: Carl Csaposs <carl.csaposs@canonical.com>
Co-authored-by: Dragomir Penev <dragomir.penev@canonical.com>
Co-authored-by: Danylo Bereznenko <pepsiqqfanta@gmail.com>
dragomirp added a commit that referenced this pull request Mar 20, 2025
* Update dependency uv to v0.5.27 (#847)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* [DPE-6053] Fix ports (#846)

* Fix ports

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>

* Remove unused import

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>

* Remove unused charm library and fix unit tests

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>

* Fix identation

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>

* Bump libs

* Conditional set_ports logic

* Unit test

* Don't expect juju managed resources

---------

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Co-authored-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>

* Sync docs from Discourse (#801)

Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>

* Update dependency uv to v0.5.29 (#848)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* [MISC] Define charm utility properties (#842)

* Update data-platform-workflows to v29.1.0 (#849)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Use `charmcraft test` & concierge (#852)

* [MISC] Split topology script (#853)

* Update charmcraft.yaml build tools (#851)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency uv to v0.5.31 (#858)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update canonical/data-platform-workflows action to v30 (#859)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Use _promote_charm.yaml (#860)

Use `charmcraft promote` and auto-generate release notes

* Update dependency cryptography to v44.0.1 [SECURITY] (#855)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Sync docs from Discourse (#854)

Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>

* Update data-platform-workflows to v30.0.2 (#863)

* Update canonical/has-signed-canonical-cla action to v2 (#865)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* [DPE-5827] Set all nodes to synchronous replicas (#784)

* Update patroni configuration

* Update test assertion

* Copy update_synchronous_node_count from VM

* Add unit test

* Set sync node count during upgrade

* Fix tls test

* Switchover primary

* Add different helper to get leader

* Add config boilerplate

* Use config value when setting sync node count

* Escape tuple

* Add policy values

* Add integration test

* Fix casting

* Fix test

* Update to spec

* Bump retry timout

* Switch to planned units

* Fix generator

* Update conf description

* Spread task

* Pass the charm

* [DPE-6484] Add scope to promote to primary (#850)

* Promote unit action

* Tweaks for failing REST calls

* VM parity

* [MISC] Enable RBAC in tests (#861)

* Enable RBAC

* Bump cosl

* Add trust

* Bump libs

* [MISC] Define charm constants (#862)

* Lock file maintenance Python dependencies (#835)

* Lock file maintenance Python dependencies

* Backoff boto3 1.36

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Dragomir Penev <dragomir.penev@canonical.com>

* Update canonical/data-platform-workflows action to v30.1.3 (#856)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update charmcraft.yaml build tools (#868)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Handle missing stanza output (#866)

* Update ghcr.io/canonical/charmed-postgresql:14.15-22.04_edge Docker digest to 71d49b6 (#870)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* [MISC] Disable storage test on arm (#872)

* Disable storage test on Arm

* Bump libs

* Correct import path

* Update charmcraft.yaml build tools (#871)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* [MISC] Add degraded status to primary message (#874)

* Add degraded status on to primary message

* Use const running tests

* [MISC] Sanitize PostgreSQL extra-user-roles arg (#876)

* [MISC] Fix PostgreSQL lib function signature (#879)

* [MISC] Skip backup tests without creds (#884)

* Bump libs

* Skip backups tests if no creds are set

* Check that the cloud config is set to a value

* Typo

* Update tests/integration/conftest.py

Co-authored-by: Carl Csaposs <carl.csaposs@canonical.com>

* Switch all checks to gets

* Typo

---------

Co-authored-by: Carl Csaposs <carl.csaposs@canonical.com>

* [DPE-6679] PostgreSQL Config Improvement (#867)

* config improvement

* config improvement

* config improvement

* config improvement

* config improvement

* config improvement

* config improvement

* config improvement

* config improvement

* config improvement

* Update dependency jinja2 to v3.1.6 [SECURITY] (#882)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update canonical/data-platform-workflows action to v30.2.0 (#887)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Reduce required approvals on Renovate pull requests by 1 (#880)

* Update dependency uv to v0.6.5 (#878)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update ghcr.io/canonical/charmed-postgresql Docker tag to v14.17 (#877)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency uv to v0.6.7 (#890)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update canonical/data-platform-workflows action to v31 (#891)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Try the new timescale

* Check PR on */edge

* Enable cache, disable pgaudit

* Use the right base

* Arm tests

---------

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Sinclert Pérez <sinclert.perez@canonical.com>
Co-authored-by: Carl Csaposs <carl.csaposs@canonical.com>
Co-authored-by: Danylo Bereznenko <pepsiqqfanta@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature, UI change, or workload upgrade Libraries: Out of sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants