-
Notifications
You must be signed in to change notification settings - Fork 16
Add log retention period #291
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
base: main
Are you sure you want to change the base?
Conversation
e78f04f to
35a6df7
Compare
pkg/db.go
Outdated
| return fmt.Errorf("create log table: %w", err) | ||
| } | ||
|
|
||
| // Create index for efficient log rotation queries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bart6114 If I inspect the cheek sqlite file, I see that there's already a sqlite_autoindex_log_1 index, so I'm unsure whether this additional index adds any value.
|
@bart6114 Ready for review. |
9730579 to
af3aad0
Compare
af3aad0 to
968e6ef
Compare
|
Thanks for the PR @igitur! A few pieces of feedback from my pov. Could you have a look? 🙏 1. Rename To align with the "log rotation" terminology used elsewhere. 2. Negative duration handling This test caught my attention: {
name: "negative duration becomes positive",
durationStr: "-1 hour",
shouldError: false, // humanize converts negative to positive
}Silent conversion of 3. Add global-level support It's not unlikely that users will want a single retention period for all jobs. Please add support for setting 4. Documentation
|
|
Hi, thanks for the feedback.
I originally called the new property
Agreed. I thought I did explicitly test that these fail. I'll double-check.
Sure thing.
Gotcha. |
|
I'd like to fix support for negative durations upstream. See pawelszydlo/humanize#1 . Then we can avoid checking for a |
Fair point. Slight preference for rotate, but perhaps
Did you check out https://github.com/dustin/go-humanize? Not sure if they're related, but this one seems much better maintained. |
Fixes #274
@bart6114 Your comments/feedback on this would be greatly appreciated.
Add Log Retention Period Feature (AI generated content below)
Summary
This PR adds a new optional
log_retention_periodparameter to job configurations in cheek, allowing automatic cleanup of old log entries from the SQLite database. The feature uses thegithub.com/pawelszydlo/humanizelibrary to parse human-readable duration strings.Changes
1. New Configuration Parameter (
pkg/job.go)LogRetentionPeriod stringfield toJobSpecstruct with YAML taglog_retention_period,omitemptylogRetentionDuration time.Durationfield to store parsed duration (not serialized to YAML)2. Humanize Library Integration (
pkg/schedule.go)github.com/pawelszydlo/humanizedependencyHumanizerinstance usingsync.Oncefor performance"7 days","3 months","1 hour and 30 minutes","2.5 hours"3. Log Retention Implementation (
pkg/job.go)rotateLogs()method that deletes log entries older than the specified durationfinalize()method after each job execution4. Database Optimization (
pkg/db.go)idx_log_job_triggered_aton(job, triggered_at)columns for efficient deletion queries5. Comprehensive Testing (
pkg/job_test.go)6. Updated Example (
testdata/readme_example.yaml)log_retention_period: 7 daysto the coffee job as an exampleUsage Examples
Supported Duration Formats
"24 hours""7 days""2 weeks""3 months""1 hour and 30 minutes""90 minutes""2.5 hours"(decimal values)"0 seconds"(fails validation - must be positive)Validation Rules
Performance Considerations
Humanizerinstance avoids repeated initializationTesting Coverage
Future Considerations
This feature helps manage database growth by automatically cleaning up old log entries while maintaining flexibility through human-readable duration specifications.