Browse Source

fix(backup): Fix too-frequent status messages (#68566)

These now appear less frequently (every 5 seconds instead of every
100ms), and never before confirmation dialogs, which have been hoisted
to the proper level (ie, the CLI wrapping functions, not the library
functions that they call).

Closes getsentry/self-hosted#2944
Alex Zaslavsky 11 months ago
parent
commit
bdeadf7167
2 changed files with 18 additions and 12 deletions
  1. 0 8
      src/sentry/backup/imports.py
  2. 18 4
      src/sentry/runner/commands/backup.py

+ 0 - 8
src/sentry/backup/imports.py

@@ -381,14 +381,6 @@ def _import(
     if SiloMode.get_current_mode() == SiloMode.MONOLITH and not is_split_db():
         with unguarded_write(using="default"), transaction.atomic(using="default"):
             if scope == ImportScope.Global:
-                confirmed = printer.confirm(
-                    """Proceeding with this operation will irrecoverably delete all existing
-                    low-volume data - are you sure want to continue?"""
-                )
-                if not confirmed:
-                    printer.echo("Import cancelled.")
-                    return
-
                 try:
                     _clear_model_tables_before_import()
                 except DatabaseError:

+ 18 - 4
src/sentry/runner/commands/backup.py

@@ -25,7 +25,9 @@ from sentry.backup.findings import Finding, FindingJSONEncoder
 from sentry.backup.helpers import ImportFlags, Printer, Side
 from sentry.backup.validate import validate
 from sentry.runner.decorators import configuration
+from sentry.silo.base import SiloMode
 from sentry.utils import json
+from sentry.utils.env import is_split_db
 
 DEFAULT_INDENT = 2
 
@@ -256,8 +258,7 @@ def print_elapsed_time(kind: str, interval_ms: int, done_event: Event, printer:
     """
     start_time = time()
     last_print_time = start_time
-    # TODO(azaslavsky): adjust this to a more reasonable figure
-    check_interval = 0.1  # Check every second if we should exit
+    check_interval = 1  # Check every second if we should exit
 
     while not done_event.is_set():
         current_time = time()
@@ -279,7 +280,9 @@ def write_import_findings(
     from sentry.backup.imports import ImportingError
 
     done_event = Event()
-    updater_thread = Thread(target=print_elapsed_time, args=("Importing", 100, done_event, printer))
+    updater_thread = Thread(
+        target=print_elapsed_time, args=("Still importing", 5000, done_event, printer)
+    )
 
     try:
         updater_thread.start()
@@ -306,7 +309,9 @@ def write_export_findings(
     from sentry.backup.exports import ExportingError
 
     done_event = Event()
-    updater_thread = Thread(target=print_elapsed_time, args=("Exporting", 100, done_event, printer))
+    updater_thread = Thread(
+        target=print_elapsed_time, args=("Still exporting", 5000, done_event, printer)
+    )
 
     try:
         updater_thread.start()
@@ -769,6 +774,15 @@ def import_global(
     from sentry.backup.imports import import_in_global_scope
 
     printer = get_printer(silent=silent, no_prompt=no_prompt)
+    if SiloMode.get_current_mode() == SiloMode.MONOLITH and not is_split_db():
+        confirmed = printer.confirm(
+            """Proceeding with this operation will irrecoverably delete all existing
+            low-volume data - are you sure want to continue?"""
+        )
+        if not confirmed:
+            printer.echo("Import cancelled.")
+            return
+
     with write_import_findings(findings_file, printer):
         import_in_global_scope(
             src,