Skip to content

Conversation

marceloneppel
Copy link
Member

@marceloneppel marceloneppel commented Sep 29, 2022

Issue

  • Jira issue: DPE-533
  • For at least some HA shakedown integration tests we need to ensure, along other requirements, that the PostgreSQL HA deployment correctly continues to handle incoming writes after some unexpected situations happen, like the DB process is killed, freezes, is restarted and so on.

Solution

  • Add a charm that perform continuous writes to the PostgreSQL charm during for shakedown tests.

Context

  • database_requires.py is an imported library and can be ignored while reviewing this PR.

  • You can FOCUS on the code from the following files while reviewing this PR:

    • charm.py:

      • has event handlers to get the connections details from the PostgreSQL from the relation data (postgresql_client interface).

      • has action handlers to start and stop the continuous writes process from continuous_writes.py and also for erasing the written data.

    • continuous_writes.py:

      • this is a Python script that continuously writes data to the PostgreSQL database. It was adapted to PostgreSQL based on the amazing code that Mia implemented on Charmed MongoDB Operator.

      • it reconnects again to the database in every loop iteration because the current established connection can fail when the primary changes (Patroni sometimes take some seconds to reassign the primary role; this happens due to some values in some Patroni settings that are needed to avoid more frequent split brain scenarios).

Testing

Release Notes

  • Add continuous writes test charm (for HA shakedown tests).

@codecov-commenter
Copy link

codecov-commenter commented Sep 29, 2022

Codecov Report

Merging #36 (e9c2353) into main (ceeba02) will increase coverage by 0.20%.
The diff coverage is 61.39%.

@@            Coverage Diff             @@
##             main      #36      +/-   ##
==========================================
+ Coverage   60.11%   60.32%   +0.20%     
==========================================
  Files           6        6              
  Lines         692      809     +117     
  Branches      103      119      +16     
==========================================
+ Hits          416      488      +72     
- Misses        256      293      +37     
- Partials       20       28       +8     
Impacted Files Coverage Δ
src/cluster.py 55.94% <55.17%> (+1.46%) ⬆️
src/charm.py 53.25% <60.33%> (+1.08%) ⬆️
src/constants.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@MiaAltieri MiaAltieri left a comment

Choose a reason for hiding this comment

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

This looks awesome! Initially when I did mine I wanted to do it as an application charm but I was too lazy. This is really awesome to see!

start-continuous-writes:
description: Start continuous writes.
stop-continuous-writes:
description: Stop continuous writes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Neat way of doing this

"""Starts continuous writes to PostgreSQL instance."""
if self._connection_string is None:
return

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit add '# stop any writes that might be going'

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice. Added on e9c2353.

Copy link
Contributor

@shayancanonical shayancanonical left a comment

Choose a reason for hiding this comment

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

lgtm!

@marceloneppel
Copy link
Member Author

Thanks for the reviews!

@marceloneppel
Copy link
Member Author

This looks awesome! Initially when I did mine I wanted to do it as an application charm but I was too lazy. This is really awesome to see!

You made most part of the work needed on this, Mia! It was your amazing implementation that made it easy to create the charm.

@marceloneppel marceloneppel merged commit 37c700d into main Sep 30, 2022
@marceloneppel marceloneppel deleted the continuous-writes-test-charm branch September 30, 2022 14:13
BON4 pushed a commit to BON4/postgresql-operator that referenced this pull request Apr 23, 2024
* Add continuous writes test charm

* Add comment
github-actions bot added a commit to canonical/test-runners-2-github-x64-postgresql-operator that referenced this pull request May 21, 2024
github-actions bot added a commit to canonical/test-runners-2-is-x64-postgresql-operator that referenced this pull request May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants