Skip to content

Conversation

@mircealungu
Copy link
Member

Summary

  • Add DATA_RETENTION_DAYS config option to automatically clean up old request data
  • Default retention is 30 days (set to 0 to disable)
  • Cleanup runs daily at 2 AM via APScheduler background job
  • Uses efficient batch deletes instead of per-row iteration for better performance on large tables

Problem

The FMD database grows unbounded over time, causing slow startup (15+ seconds when tables have millions of rows):

  • StackLine table: 16GB, 289M rows
  • Request table: 97MB, 1.6M rows
  • Outlier table: 274MB, 47K rows

Solution

Add a config option for data retention:

[database]
DATA_RETENTION_DAYS=30    # Keep 30 days of data (default)
DATA_RETENTION_DAYS=0     # Disable automatic cleanup
DATA_RETENTION_DAYS=90    # Keep 90 days

When DATA_RETENTION_DAYS > 0, cleanup is automatically scheduled on dashboard.bind(app).

Changes

  • flask_monitoringdashboard/core/config/__init__.py - Add config option
  • flask_monitoringdashboard/core/database_pruning.py - Add batch delete function and scheduler
  • flask_monitoringdashboard/__init__.py - Auto-schedule cleanup in bind()
  • config.cfg - Add example config
  • tests/unit/core/test_database_pruning.py - New test file (6 tests)
  • tests/unit/core/config/test_config.py - Add config parsing tests (3 tests)

Test plan

  • Run existing unit tests - all 88 tests pass
  • Test old requests are deleted while recent ones are preserved
  • Test related records (Outlier, StackLine, ExceptionOccurrence) are cascaded
  • Test orphan cleanup works correctly
  • Manual testing with real database

🤖 Generated with Claude Code

Add DATA_RETENTION_DAYS config option that automatically schedules
database cleanup to run daily at 2 AM. This addresses the issue of
unbounded database growth causing slow startup times.

Key changes:
- Add DATA_RETENTION_DAYS config option (default: 30 days, 0 to disable)
- Add prune_database_older_than_days() with efficient batch deletes
- Auto-schedule cleanup in bind() when retention is enabled
- Delete Request, StackLine, Outlier, ExceptionOccurrence and orphans

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@codecov
Copy link

codecov bot commented Jan 7, 2026

Codecov Report

❌ Patch coverage is 95.06173% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.97%. Comparing base (2a07170) to head (2eb83fd).

Files with missing lines Patch % Lines
flask_monitoringdashboard/__init__.py 0.00% 3 Missing ⚠️
flask_monitoringdashboard/core/database_pruning.py 92.30% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #545      +/-   ##
==========================================
+ Coverage   86.73%   86.97%   +0.23%     
==========================================
  Files         115      116       +1     
  Lines        3611     3692      +81     
==========================================
+ Hits         3132     3211      +79     
- Misses        479      481       +2     
Files with missing lines Coverage Δ
flask_monitoringdashboard/core/config/__init__.py 82.22% <100.00%> (+0.40%) ⬆️
tests/unit/core/config/test_config.py 100.00% <100.00%> (ø)
tests/unit/core/test_database_pruning.py 100.00% <100.00%> (ø)
flask_monitoringdashboard/core/database_pruning.py 65.90% <92.30%> (+17.52%) ⬆️
flask_monitoringdashboard/__init__.py 69.81% <0.00%> (-4.19%) ⬇️
🚀 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.

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.

2 participants