From 6e7fb03c3a5ac14ab9cdecc65cbab8e15338e6d9 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Fri, 21 Feb 2025 15:04:43 +0300 Subject: [PATCH] Provisioning: Show progress more often (#101128) * show progress bar earlier * show progress bar earlier * update wording to be less specific --- .betterer.results | 3 +- .../apis/provisioning/jobs/migrate/worker.go | 34 ++++++++++++++----- .../apis/provisioning/jobs/progress.go | 2 +- .../features/provisioning/OnboardingPage.tsx | 5 ++- .../provisioning/Wizard/MigrateStep.tsx | 13 +------ 5 files changed, 31 insertions(+), 26 deletions(-) diff --git a/.betterer.results b/.betterer.results index 447ddf16d5f..8a8733abfa2 100644 --- a/.betterer.results +++ b/.betterer.results @@ -5908,8 +5908,7 @@ exports[`better eslint`] = { [0, 0, 0, "No untranslated strings. Wrap text with ", "6"], [0, 0, 0, "No untranslated strings. Wrap text with ", "7"], [0, 0, 0, "No untranslated strings. Wrap text with ", "8"], - [0, 0, 0, "No untranslated strings. Wrap text with ", "9"], - [0, 0, 0, "No untranslated strings. Wrap text with ", "10"] + [0, 0, 0, "No untranslated strings. Wrap text with ", "9"] ], "public/app/features/provisioning/Wizard/ProvisioningWizard.tsx:5381": [ [0, 0, 0, "No untranslated strings. Wrap text with ", "0"] diff --git a/pkg/registry/apis/provisioning/jobs/migrate/worker.go b/pkg/registry/apis/provisioning/jobs/migrate/worker.go index 1377f210e55..2781ea66018 100644 --- a/pkg/registry/apis/provisioning/jobs/migrate/worker.go +++ b/pkg/registry/apis/provisioning/jobs/migrate/worker.go @@ -1,10 +1,11 @@ package migrate import ( + "bufio" "context" "errors" "fmt" - "os" + "io" "github.com/grafana/grafana-app-sdk/logging" "github.com/grafana/grafana/pkg/apimachinery/utils" @@ -88,12 +89,21 @@ func (w *MigrationWorker) Process(ctx context.Context, repo repository.Repositor buffered *gogit.GoGitRepo ) + progress.SetTotal(10) // will show a progress bar if repo.Config().Spec.GitHub != nil { - progress.SetMessage("clone target") + progress.SetMessage("clone " + repo.Config().Spec.GitHub.URL) + reader, writer := io.Pipe() + go func() { + scanner := bufio.NewScanner(reader) + for scanner.Scan() { + progress.SetMessage(scanner.Text()) + } + }() + buffered, err = gogit.Clone(ctx, repo.Config(), gogit.GoGitCloneOptions{ Root: w.clonedir, SingleCommitBeforePush: !options.History, - }, w.secrets, os.Stdout) + }, w.secrets, writer) if err != nil { return fmt.Errorf("unable to clone target: %w", err) } @@ -132,7 +142,7 @@ func (w *MigrationWorker) Process(ctx context.Context, repo repository.Repositor } if options.History { - progress.SetMessage("load users") + progress.SetMessage("loading users") err = worker.loadUsers(ctx) if err != nil { return fmt.Errorf("error loading users: %w", err) @@ -140,21 +150,29 @@ func (w *MigrationWorker) Process(ctx context.Context, repo repository.Repositor } // Load and write all folders - progress.SetMessage("start folder export") + progress.SetMessage("exporting folders") err = worker.loadFolders(ctx) if err != nil { return err } - progress.SetMessage("start resource export") + progress.SetMessage("exporting resources") err = worker.loadResources(ctx) if err != nil { return err } if buffered != nil { - progress.SetMessage("push changes") - if err := buffered.Push(ctx, os.Stdout); err != nil { + progress.SetMessage("pushing changes") + reader, writer := io.Pipe() + go func() { + scanner := bufio.NewScanner(reader) + for scanner.Scan() { + progress.SetMessage(scanner.Text()) + } + }() + + if err := buffered.Push(ctx, writer); err != nil { return fmt.Errorf("error pushing changes: %w", err) } } diff --git a/pkg/registry/apis/provisioning/jobs/progress.go b/pkg/registry/apis/provisioning/jobs/progress.go index 8533457c2e5..f52a6431e85 100644 --- a/pkg/registry/apis/provisioning/jobs/progress.go +++ b/pkg/registry/apis/provisioning/jobs/progress.go @@ -53,7 +53,7 @@ type jobProgressRecorder struct { func newJobProgressRecorder(progressFn progressFn) JobProgressRecorder { return &jobProgressRecorder{ started: time.Now(), - progressFn: maybeNotifyProgress(15*time.Second, progressFn), + progressFn: maybeNotifyProgress(5*time.Second, progressFn), summaries: make(map[string]*provisioning.JobResourceSummary), } } diff --git a/public/app/features/provisioning/OnboardingPage.tsx b/public/app/features/provisioning/OnboardingPage.tsx index 2a7ce2a3110..dc1f30473dd 100644 --- a/public/app/features/provisioning/OnboardingPage.tsx +++ b/public/app/features/provisioning/OnboardingPage.tsx @@ -15,9 +15,8 @@ export default function OnboardingPage() { - When you connect your whole instance, depending on its size, the setup might make the dashboard unavailable to - users for up to 30 minutes. We recommend warning your users before starting the process. You can use the - announcement banner or your preferred channels. + When you connect your whole instance, dashboards will be unavailable while running the migration. We recommend + warning your users before starting the process. { - migrateQuery.reset(); - setShowMigrateStatus(false); - onMigrationStatusChange(false); - }; - if (showMigrateStatus && migrateName) { return ( - - - ); } @@ -70,7 +59,7 @@ export function MigrateStep({ onMigrationStatusChange }: MigrateStepProps) { - Dashboards app/Grafana will be unavailable when starting this process. + Dashboards will be unavailable while running this process. {Boolean(stats.length) && (