feat: setup logs retention by max file size

This commit is contained in:
fsylvain committed 2026-10-07 22:02:13 +02:00
1 parent 70c8492f4f
commit f914eae3c5
44 files changed
+2316 -161

No files matched your search

+8 -8
View File
@@ -50,7 +50,7 @@ func TestSettingsNextCleanupDomain(t *testing.T) {
func TestSettingsNextCleanupUseCases(t *testing.T) {
t.Run("Get returns the next cleanup from the clock or nil for Forever", func(t *testing.T) {
fake := newActivitySettingsFake()
get := useCases.NewGetActivityRetentionUseCase(fake, settingsTestClock)
get := useCases.NewGetActivityRetentionUseCase(fake, newSizeEvents(t), settingsTestClock)
current, err := get.GetActivityRetention()
if err != nil || current.NextCleanupAt == nil || current.NextCleanupAt.Format(time.RFC3339) != "2026-10-07T03:00:00+02:00" {
@@ -66,17 +66,17 @@ func TestSettingsNextCleanupUseCases(t *testing.T) {
t.Run("Update returns the next cleanup of the new period", func(t *testing.T) {
fake := newActivitySettingsFake()
update := useCases.NewUpdateActivityRetentionUseCase(fake, discardRecorder, settingsTestClock)
update := useCases.NewUpdateActivityRetentionUseCase(fake, newSizeEvents(t), discardRecorder, settingsTestClock)
forever, err := update.UpdateActivityRetention(testCtx, 0)
forever, err := update.UpdateActivityRetention(testCtx, retentionDays(0))
if err != nil || forever.RetentionDays != 0 || forever.NextCleanupAt != nil {
t.Fatalf("unexpected %+v, %v", forever, err)
}
back, err := update.UpdateActivityRetention(testCtx, 365)
back, err := update.UpdateActivityRetention(testCtx, retentionDays(365))
if err != nil || back.NextCleanupAt == nil || back.NextCleanupAt.Format(time.RFC3339) != "2026-10-07T03:00:00+02:00" {
t.Fatalf("unexpected %+v, %v", back, err)
}
same, err := update.UpdateActivityRetention(testCtx, 365)
same, err := update.UpdateActivityRetention(testCtx, retentionDays(365))
if err != nil || same.NextCleanupAt == nil {
t.Fatalf("unexpected %+v, %v", same, err)
}
@@ -84,7 +84,7 @@ func TestSettingsNextCleanupUseCases(t *testing.T) {
t.Run("Update refuses an invalid period and saves nothing", func(t *testing.T) {
fake := newActivitySettingsFake()
_, err := useCases.NewUpdateActivityRetentionUseCase(fake, discardRecorder, settingsTestClock).UpdateActivityRetention(testCtx, 7)
_, err := useCases.NewUpdateActivityRetentionUseCase(fake, newSizeEvents(t), discardRecorder, settingsTestClock).UpdateActivityRetention(testCtx, retentionDays(7))
if !errors.Is(err, audit.ErrInvalidRetention) || fake.retentionOK != 0 {
t.Fatalf("expected a refusal, got %v", err)
}
@@ -101,7 +101,7 @@ func TestSettingsNextCleanupHttp(t *testing.T) {
return decoded
}
t.Run("GET keeps the existing fields and adds exactly one", func(t *testing.T) {
t.Run("GET keeps the existing fields and adds exactly one next cleanup and the size fields", func(t *testing.T) {
e := newActivityHTTPEnv(t, 1000)
e.settings.settings.LastCleanupAt = activityPtr(time.Date(2026, time.October, 6, 1, 0, 0, 0, time.UTC))
e.settings.settings.LastCleanupRemoved = 142
@@ -109,7 +109,7 @@ func TestSettingsNextCleanupHttp(t *testing.T) {
rec := e.get("/v1/settings", asUser(e, activityEditorID))
body := keys(t, rec.Body.String())
if rec.Code != http.StatusOK || len(body) != 5 || body["activity_next_cleanup_at"] != "2026-10-07T03:00:00Z" || body["activity_last_cleanup_removed"] != float64(142) {
if rec.Code != http.StatusOK || len(body) != 7 || body["activity_next_cleanup_at"] != "2026-10-07T03:00:00Z" || body["activity_last_cleanup_removed"] != float64(142) {
t.Errorf("unexpected %d %v", rec.Code, body)
}
})