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

refactor: store logs as Redis hashes #823

Merged
merged 1 commit into from
Mar 31, 2025

Conversation

elfkuzco
Copy link
Contributor

Rationale

This PR implements the functionality to save logs to Redis. By setting expiry on the logs while saving, we can be sure that logs are not saved for years and there is no need for reliance on a cron job to delete old logs.

Changes

  • set up connection to Redis in BaseWPOneDbTest
  • save logs to Redis as hashes instead of SQL DB
  • use a key naming pattern which allows us to filter logs that match the pattern. This emulates SQL-like AND queries for logs
  • update tests to use appropriate self.redis

Fixes

This fixes #778
This fixes #49

@elfkuzco
Copy link
Contributor Author

If the PR is accpeted, there should be a newer PR to drop the logging table. This would be implemented if all the logs are moved from SQL to Redis in order to avoid data loss. Thus, I have avoided the need to include a migration in this PR.

Copy link
Member

@audiodude audiodude 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 great!

But I think we do need the migration in the same PR, because once this gets deployed, we will lose the logs from the past 7 days unless we migrate. We don't need to put the entire logging table into redis, just the logs from the past 7 days. Probably the easiest way to do it is as a YoYo migration, even though it doesn't actually touch the database. That is, we should not drop the logging table as part of the migration, that should be done as a separate manual step.

@audiodude
Copy link
Member

If you like, I can write the migration and append it to this PR. Just let me know.

@elfkuzco
Copy link
Contributor Author

If you like, I can write the migration and append it to this PR. Just let me know.

Okay. You can append it to the PR.

@audiodude
Copy link
Member

Oh actually I don't think I can add to the PR because it's on a branch in your repo. I've opened #826

@audiodude audiodude force-pushed the write-logs-to-redis branch from 1c88d94 to 9bcd8e6 Compare March 31, 2025 00:27
Copy link

codecov bot commented Mar 31, 2025

Codecov Report

Attention: Patch coverage is 97.87234% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.57%. Comparing base (3bc5e88) to head (9bcd8e6).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
wp1/logic/log.py 96.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #823      +/-   ##
==========================================
+ Coverage   91.55%   91.57%   +0.02%     
==========================================
  Files          66       66              
  Lines        3575     3597      +22     
==========================================
+ Hits         3273     3294      +21     
- Misses        302      303       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@audiodude audiodude merged commit 113c138 into openzim:main Mar 31, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants