Repository navigation
feat(botwall): opt-in log retention via SCRAPER_BOTWALL_LOG_RETENTION_DAYS - #7
Merged
Merged
Conversation
…_DAYS The botwall audit logs (botwall_events.jsonl, botwall_excluded.jsonl, botwall_excluded.log) only ever grow, so long-running deployments have to rotate them by hand or keep years of per-scrape rows they never read. - New SCRAPER_BOTWALL_LOG_RETENTION_DAYS (default 0 = keep everything, so existing installs see no change). - When >0, the logging path trims all three files to the last N days at most once an hour per process: temp file + os.replace, original file mode kept, lines without a readable timestamp kept, failures only warn. - A module lock serialises in-process appends with the rewrite. botwall_db.json is never trimmed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in setting,
SCRAPER_BOTWALL_LOG_RETENTION_DAYS, that keeps the botwall audit logs to the last N days. The default is 0, which keeps everything exactly as today.Background
botwall_events.jsonl,botwall_excluded.jsonlandbotwall_excluded.logget one line per scrape event or exclusion and are never trimmed. On OwnFeed's server they hold every event since July (2.4 MB, 9,000+ lines). Long-running deployments have to rotate them by hand or let them grow forever.What changed
_int_envand documented in the config comment block, the README Tunables list and the CHANGELOG (Unreleased)._log_eventand_log_exclusiontrim all three files after appending, at most once an hour per process. A trim keeps:ts, or the first token of a.logline);os.replace. A file with nothing to drop isn't rewritten._LOG_LOCKcovers the appends and the rewrite, so writes from other threads in the same process aren't lost.botwall: log trim failed for <path>: ..., and scraping continues.botwall_db.jsonis never touched.What correct output looks like
With
=5, the first write in a process (and the first after each hour) leaves each file with only lines from the last 5 days, plus lines whose timestamp can't be read. The file mode is unchanged, no*.tmp.*files are left behind, and writes within the same hour don't rewrite the files.Default unchanged
Unset or
0:_maybe_trim_logsreturns at once. Log contents, formats, paths, signatures and return types are identical.test_default_unset_keeps_everythingpins this.Tests
tests/test_log_retention.py:5: old lines are dropped in all three files, recent and unreadable lines are kept, the file mode is kept, and no temp file is left;Full suite: 117 passed, 6 skipped (main: 114 passed).
Known limit
If another process appends to the same state folder during a rewrite, that line can be lost (noted in a
shortcut:comment). A file lock would fix it if several processes ever share one state folder.After merge
Release a new version. OwnFeed then bumps
switchback>=and setsSCRAPER_BOTWALL_LOG_RETENTION_DAYS=5.