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-5324] Increase linting rules #740

Merged
merged 23 commits into from
Dec 19, 2024
Merged

[DPE-5324] Increase linting rules #740

merged 23 commits into from
Dec 19, 2024

Conversation

dragomirp
Copy link
Contributor

@dragomirp dragomirp commented Oct 14, 2024

Add more linting rules and change and suppress the reported issues. Added rules are:

Copy link

codecov bot commented Oct 14, 2024

Codecov Report

Attention: Patch coverage is 68.25397% with 20 lines in your changes missing coverage. Please review.

Project coverage is 75.57%. Comparing base (7da9c8c) to head (a3fd51c).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/charm.py 20.00% 7 Missing and 1 partial ⚠️
src/relations/async_replication.py 33.33% 4 Missing ⚠️
src/patroni.py 62.50% 3 Missing ⚠️
src/relations/db.py 60.00% 2 Missing ⚠️
src/relations/postgresql_provider.py 33.33% 2 Missing ⚠️
src/upgrade.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #740      +/-   ##
==========================================
+ Coverage   75.48%   75.57%   +0.09%     
==========================================
  Files          12       12              
  Lines        3121     3108      -13     
  Branches      475      464      -11     
==========================================
- Hits         2356     2349       -7     
+ Misses        622      620       -2     
+ Partials      143      139       -4     

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

Comment on lines +180 to +182
cursor.execute(
SQL("SELECT datname FROM pg_database WHERE datname={};").format(Literal(database))
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bandit checks don't like rendering directly in the SQL string.

Comment on lines +100 to +107
return not (
not self.charm._patroni.member_started
and (
(len(self.charm._peers.data.keys()) == 2)
or (
"tls" not in self.charm.unit_peer_data
and any("tls" in unit_data for _, unit_data in self.charm._peers.data.items())
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ugly

@@ -28,6 +28,7 @@
from constants import POSTGRESQL_LOGS_PATH, POSTGRESQL_LOGS_PATTERN, REWIND_USER, TLS_CA_FILE

RUNNING_STATES = ["running", "streaming"]
PATRONI_TIMEOUT = 10
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Arbitrary timeout for REST calls. IIRC otherwise TCP defaults are used.

@@ -109,14 +108,14 @@ def __init__(
user: str,
password: str,
database: str,
system_users: List[str] = [],
system_users: Optional[list[str]] = 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.

We can't use implicit union (list[str] | None) for compatibility with focal (Python 3.8)

@@ -10,7 +10,8 @@
def main():
"""Main loop that calls logrotate."""
while True:
subprocess.run(["logrotate", "-f", "/etc/logrotate.d/pgbackrest.logrotate"])
# Command is hardcoded
subprocess.run(["/usr/sbin/logrotate", "-f", "/etc/logrotate.d/pgbackrest.logrotate"]) # noqa: S603

# Wait 60 seconds before executing logrotate again.
time.sleep(60)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can most probably use pebble backoff to do the same

Comment on lines +224 to +227
patch(
"relations.async_replication.PostgreSQLAsyncReplication._get_unit_ip",
return_value="1.1.1.1",
) as _get_unit_ip,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fails on non-Ubutu hosts without the patch.

@dragomirp dragomirp marked this pull request as ready for review November 9, 2024 13:45
@dragomirp dragomirp requested review from a team, taurus-forever, marceloneppel and lucasgameiroborges and removed request for a team November 9, 2024 13:45
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 about of work and passion invested here.
LGTM and thank you!

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.

Thanks for the great work, Dragomir!

@dragomirp dragomirp merged commit 0a1c149 into main Dec 19, 2024
111 checks passed
@dragomirp dragomirp deleted the dpe-5324-ruff branch December 19, 2024 08:37
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.

4 participants