π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
server: summarize storage warning rollout skips
Neeraj Gupta5288ed8a1d44
diff --git a/server/pkg/controller/email/storage_warning.go b/server/pkg/controller/email/storage_warning.goindex da2087b602..b805192b6f 100644--- a/server/pkg/controller/email/storage_warning.go+++ b/server/pkg/controller/email/storage_warning.go@@ -78,12 +78,13 @@ type storageWarningMetrics struct {}type storageWarningRunStats struct {- ProcessedUsers int- SentEmails int- SuccessByStage map[string]int- FailureByStage map[string]int- PreStageFailures int- SkippedRolloutPct int+ ProcessedUsers int+ SentEmails int+ SuccessByStage map[string]int+ FailureByStage map[string]int+ SkippedRolloutByStage map[string]int+ PreStageFailures int+ SkippedRolloutPct int}type storageWarningProcessResult string@@ -110,19 +111,22 @@ var storageWarningStageOrder = []string{func newStorageWarningRunStats() storageWarningRunStats {successByStage := make(map[string]int, len(storageWarningStageOrder))failureByStage := make(map[string]int, len(storageWarningStageOrder))+ skippedRolloutByStage := make(map[string]int, len(storageWarningStageOrder))for _, stage := range storageWarningStageOrder {successByStage[stage] = 0failureByStage[stage] = 0+ skippedRolloutByStage[stage] = 0}return storageWarningRunStats{- SuccessByStage: successByStage,- FailureByStage: failureByStage,+ SuccessByStage: successByStage,+ FailureByStage: failureByStage,+ SkippedRolloutByStage: skippedRolloutByStage,}}-func hasAnyStorageWarningStageSuccess(successByStage map[string]int) bool {+func hasAnyStorageWarningStageCount(counts map[string]int) bool {for _, stage := range storageWarningStageOrder {- if successByStage[stage] > 0 {+ if counts[stage] > 0 {return true}}@@ -139,12 +143,13 @@ func formatStorageWarningStageCounts(counts map[string]int) string {func buildStorageWarningRunSummary(stats storageWarningRunStats, runAt int64) string {return fmt.Sprintf(- "Storage warning run summary (%s): processed=%d sent=%d | success={%s} | failures={%s} | pre_stage_failures=%d | skipped_rollout_percentage=%d | rollout_percentage=%d",+ "Storage warning run summary (%s): processed=%d sent=%d | success={%s} | failures={%s} | skipped_rollout={%s} | pre_stage_failures=%d | skipped_rollout_percentage=%d | rollout_percentage=%d",stdtime.UnixMicro(runAt).UTC().Format(stdtime.RFC3339),stats.ProcessedUsers,stats.SentEmails,formatStorageWarningStageCounts(stats.SuccessByStage),formatStorageWarningStageCounts(stats.FailureByStage),+ formatStorageWarningStageCounts(stats.SkippedRolloutByStage),stats.PreStageFailures,stats.SkippedRolloutPct,storageWarningRolloutPercentage,@@ -230,6 +235,9 @@ func (c *EmailNotificationController) SendStorageWarningMails() {skipped++skippedRolloutPct++stats.SkippedRolloutPct+++ if stage := storageWarningStageKey(snapshot); stage != "" {+ stats.SkippedRolloutByStage[stage]+++ }continue}if result == storageWarningProcessResultSent {@@ -257,14 +265,15 @@ func (c *EmailNotificationController) SendStorageWarningMails() {"failed_active_overage": failedByBucket[storageWarningBucketActiveOverage],"stage_success": stats.SuccessByStage,"stage_failures": stats.FailureByStage,+ "stage_skipped_rollout": stats.SkippedRolloutByStage,"pre_stage_failures": stats.PreStageFailures,"skipped_rollout_percentage": skippedRolloutPct,- "has_stage_movements": hasAnyStorageWarningStageSuccess(stats.SuccessByStage),+ "has_stage_movements": hasAnyStorageWarningStageCount(stats.SuccessByStage),"rollout_percentage": storageWarningRolloutPercentage,"rollout_nonce": storageWarningRolloutNonce,}).Info("Storage warning mail run completed")- if c.DiscordController != nil && hasAnyStorageWarningStageSuccess(stats.SuccessByStage) {+ if c.DiscordController != nil && (hasAnyStorageWarningStageCount(stats.SuccessByStage) || hasAnyStorageWarningStageCount(stats.SkippedRolloutByStage)) {c.DiscordController.NotifyAdminAction(buildStorageWarningRunSummary(stats, now))}}@@ -490,10 +499,6 @@ func (c *EmailNotificationController) processStorageWarningSnapshot(ctx context."template_filename": templateName,})if !isInStorageWarningRollout(snapshot.RecipientID, snapshot.AccountEmail) {- logger.WithFields(log.Fields{- "rollout_reason": "percentage",- "rollout_included": false,- }).Info("Skipping storage warning email due to rollout")return storageWarningProcessResultSkippedRollout, nil}if storageWarningShouldResetUserAccess(snapshot) {diff --git a/server/pkg/controller/email/storage_warning_test.go b/server/pkg/controller/email/storage_warning_test.goindex 894706e389..d8c43f33f1 100644--- a/server/pkg/controller/email/storage_warning_test.go+++ b/server/pkg/controller/email/storage_warning_test.go@@ -669,7 +669,7 @@ func TestStorageWarningTemplateDetailsActiveOverage(t *testing.T) {}}-func TestProcessStorageWarningSnapshotSkipsDueToRolloutAfterTemplateSelection(t *testing.T) {+func TestProcessStorageWarningSnapshotSkipsDueToRolloutWithoutPerRecipientLog(t *testing.T) {standardLogger := log.StandardLogger()originalHooks := standardLogger.ReplaceHooks(make(log.LevelHooks))hook := logtest.NewGlobal()@@ -694,24 +694,8 @@ func TestProcessStorageWarningSnapshotSkipsDueToRolloutAfterTemplateSelection(tt.Fatalf("unexpected result: got %q want %q", result, storageWarningProcessResultSkippedRollout)}- entry := hook.LastEntry()- if entry == nil {- t.Fatal("expected rollout skip log entry")- }- if entry.Message != "Skipping storage warning email due to rollout" {- t.Fatalf("unexpected log message: %q", entry.Message)- }- if got := entry.Data["template_id"]; got != storageWarningExpired30TemplateID {- t.Fatalf("unexpected template id in log: got %v want %q", got, storageWarningExpired30TemplateID)- }- if got := entry.Data["template_filename"]; got != storageWarningExpiredTemplate {- t.Fatalf("unexpected template filename in log: got %v want %q", got, storageWarningExpiredTemplate)- }- if got := entry.Data["subject"]; got != storageWarningExpired30Subject {- t.Fatalf("unexpected subject in log: got %v want %q", got, storageWarningExpired30Subject)- }- if got := entry.Data["rollout_included"]; got != false {- t.Fatalf("unexpected rollout flag in log: got %v want false", got)+ if entry := hook.LastEntry(); entry != nil {+ t.Fatalf("expected no per-recipient rollout log, got %q", entry.Message)}}@@ -722,11 +706,12 @@ func TestBuildStorageWarningRunSummary(t *testing.T) {stats.SuccessByStage[string(expiredWarningStage30)] = 1stats.SuccessByStage[string(activeOverageWarningStage0)] = 2stats.FailureByStage[string(activeOverageWarningStage60)] = 1+ stats.SkippedRolloutByStage[string(expiredWarningStage60)] = 39stats.PreStageFailures = 4stats.SkippedRolloutPct = 39got := buildStorageWarningRunSummary(stats, 0)- want := "Storage warning run summary (1970-01-01T00:00:00Z): processed=42 sent=3 | success={expired_30d=1, expired_60d=0, expired_90d=0, expired_119d=0, expired_scheduled_deletion=0, active_overage_0d=2, active_overage_30d=0, active_overage_60d=0, active_overage_89d=0, active_overage_scheduled_deletion=0} | failures={expired_30d=0, expired_60d=0, expired_90d=0, expired_119d=0, expired_scheduled_deletion=0, active_overage_0d=0, active_overage_30d=0, active_overage_60d=1, active_overage_89d=0, active_overage_scheduled_deletion=0} | pre_stage_failures=4 | skipped_rollout_percentage=39 | rollout_percentage=0"+ want := "Storage warning run summary (1970-01-01T00:00:00Z): processed=42 sent=3 | success={expired_30d=1, expired_60d=0, expired_90d=0, expired_119d=0, expired_scheduled_deletion=0, active_overage_0d=2, active_overage_30d=0, active_overage_60d=0, active_overage_89d=0, active_overage_scheduled_deletion=0} | failures={expired_30d=0, expired_60d=0, expired_90d=0, expired_119d=0, expired_scheduled_deletion=0, active_overage_0d=0, active_overage_30d=0, active_overage_60d=1, active_overage_89d=0, active_overage_scheduled_deletion=0} | skipped_rollout={expired_30d=0, expired_60d=39, expired_90d=0, expired_119d=0, expired_scheduled_deletion=0, active_overage_0d=0, active_overage_30d=0, active_overage_60d=0, active_overage_89d=0, active_overage_scheduled_deletion=0} | pre_stage_failures=4 | skipped_rollout_percentage=39 | rollout_percentage=0"if got != want {t.Fatalf("unexpected summary:\n got: %s\nwant: %s", got, want)}