Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DPE-5833] Create new PostgreSQL version 16 charm #788

Open
wants to merge 19 commits into
base: 16/edge
Choose a base branch
from

Conversation

lucasgameiroborges
Copy link
Contributor

@lucasgameiroborges lucasgameiroborges commented Nov 26, 2024

Part of the 4-PR bundle to merge PostgreSQL 16. See doc for further info: https://docs.google.com/document/d/1K4xMxKDOiHfdCTc_hxMh6bW1DCZ6HC6wa6g8tAJAtno/edit?tab=t.0

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

Attention: Patch coverage is 45.45455% with 6 lines in your changes missing coverage. Please review.

Project coverage is 75.53%. Comparing base (ab80bae) to head (66cf401).

Files with missing lines Patch % Lines
src/charm.py 40.00% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           16/edge     #788      +/-   ##
===========================================
- Coverage    75.53%   75.53%   -0.01%     
===========================================
  Files           12       12              
  Lines         3115     3123       +8     
  Branches       466      468       +2     
===========================================
+ Hits          2353     2359       +6     
  Misses         621      621              
- Partials       141      143       +2     

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


integration-test:
strategy:
fail-fast: false
matrix:
juju:
- agent: 2.9.51 # renovate: juju-agent-pin-minor
libjuju: ==2.9.49.1 # renovate: latest libjuju 2
allure_on_amd64: false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no more juju 2

for extension, enable in ordered_extensions.items():
if extension == "postgis":
cursor.execute("SET pgaudit.log = 'none';")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

necessary for postgis to work

Copy link
Member

Choose a reason for hiding this comment

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

Interesting. So, postgis and pgaudit don't work together?

sslrootcert: {{ conf_path }}/ca.pem
sslcert: {{ conf_path }}/cert.pem
sslkey: {{ conf_path }}/key.pem
{%- endif %}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no idea why this wasn't an issue before.


@pytest.fixture(scope="module")
async def database_charm(ops_test: OpsTest):
"""Build the database charm."""
charm = await ops_test.build_charm(".")
charm = await build_charm(".")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

workaround for multi-base integration testing (currently hardcoded to jammy)

@@ -43,7 +42,6 @@ async def test_build_and_deploy(ops_test: OpsTest) -> None:
await ops_test.model.deploy(
APPLICATION_NAME,
application_name=APPLICATION_NAME,
base=CHARM_BASE,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this parameter still doesn't play nice with noble base.

@@ -372,6 +374,7 @@ def _generate_database_privileges_statements(
) -> List[Composed]:
"""Generates a list of databases privileges statements."""
statements = []
statements.append(SQL("GRANT USAGE, CREATE ON SCHEMA public TO PUBLIC;"))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here and below are the specific workarounds mentioned in the doc for the new restrictive permissions added on PG 15/16.

@lucasgameiroborges lucasgameiroborges marked this pull request as ready for review February 11, 2025 15:01
Copy link
Member

@marceloneppel marceloneppel left a comment

Choose a reason for hiding this comment

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

Great work, Lucas! Thanks for all those updates to the code to match what's needed for PG 16.

@@ -17,6 +17,7 @@
CHARM_SERIES,
DATABASE_APP_NAME,
METADATA,
build_charm,
Copy link
Member

Choose a reason for hiding this comment

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

This test file and tests/integration/ha_tests/test_rollback_to_master_label.py can be removed as we don't have a previous version without the primary label for PG 16.

Comment on lines +65 to +68
ORAFCE_EXTENSION_STATEMENT = "SELECT oracle.add_months(date '2005-05-31',1);"
PG_SIMILARITY_EXTENSION_STATEMENT = (
"SET pg_similarity.levenshtein_threshold = 0.7; SELECT 'aaa', 'aab', lev('aaa','aab');"
)
Copy link
Member

Choose a reason for hiding this comment

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

Do these statements also work on PG 14? If so, I think we can create a ticket to remember to backport it later.

for extension, enable in ordered_extensions.items():
if extension == "postgis":
cursor.execute("SET pgaudit.log = 'none';")
Copy link
Member

Choose a reason for hiding this comment

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

Interesting. So, postgis and pgaudit don't work together?

@@ -534,7 +534,7 @@ def render_patroni_yml_file(
)
self._render_file(f"{self._storage_path}/patroni.yml", rendered, 0o644)

@retry(stop=stop_after_attempt(10), wait=wait_exponential(multiplier=1, min=2, max=30))
@retry(stop=stop_after_attempt(20), wait=wait_exponential(multiplier=1, min=2, max=30))
Copy link
Member

Choose a reason for hiding this comment

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

Did you have a link to a failing test that motivated this change? Did it happen multiple times?

Comment on lines +434 to +437
SQL("GRANT USAGE, CREATE ON SCHEMA {} TO {};").format(
schema, Identifier(user)
),
SQL("GRANT USAGE, CREATE ON SCHEMA {} TO admin;").format(schema),
Copy link
Member

Choose a reason for hiding this comment

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

I checked the PostgreSQL 15 release notes and changed my mind about the approach here. Now, I think that it's important that we don't grant those permissions to users on the public schema to avoid CVE-2018-1058.

@@ -28,7 +28,7 @@ resources:
postgresql-image:
type: oci-image
description: OCI image for PostgreSQL
upstream-source: ghcr.io/canonical/charmed-postgresql@sha256:7e41d7f60e45ee2f5463aa9aafcd3c35121423423ee08c26a174b99ad0235b7e # renovate: oci-image tag: 14.15-22.04_edge
upstream-source: ghcr.io/canonical/charmed-postgresql:16.4-24.04_edge
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to keep the SHA256 digest here because it'll prevent us from publishing the charm with a newer and not yet tested version of the OCI image.

@marceloneppel marceloneppel self-requested a review February 13, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants