Add estimated time remaining for batched background migrations
## Problem
When running long-duration batched background migrations (like the CI builds metadata migration), users need visibility into how long the migration will take to complete. Currently, there's no built-in way to estimate the remaining time.
## Proposal
Add `estimated_time_remaining` method to `Gitlab::Database::BackgroundMigration::BatchedMigration` to calculate and display estimated completion time. This can be exposed through chatops commands to provide users with migration progress estimates.
## Implementation
```diff
diff --git i/lib/gitlab/database/background_migration/batched_migration.rb w/lib/gitlab/database/background_migration/batched_migration.rb
index 54b083b35df7..2f8ffae47789 100644
--- i/lib/gitlab/database/background_migration/batched_migration.rb
+++ w/lib/gitlab/database/background_migration/batched_migration.rb
@@ -334,7 +334,22 @@ def progress
return unless total_tuple_count.to_i > 0
- 100 * migrated_tuple_count / total_tuple_count
+ 100.0 * migrated_tuple_count / total_tuple_count
+ end
+
+ def estimated_time_remaining
+ @estimated_time_remaining ||= ChronicDuration.output(compute_estimated_seconds_remaining, format: :long)
+ end
+
+ def compute_estimated_seconds_remaining
+ return if progress.to_f == 0
+
+ duration = batched_jobs.with_status(:succeeded).pluck(:finished_at, :started_at).sum { |a, b| a - b }
+
+ progress_rate = progress / duration
+ estimated_seconds_remaining = (100 - progress) / progress_rate
+
+ estimated_seconds_remaining.to_i
end
def finalize_command
```
## Related
- Related to #579807
issue