chore: add logging around migration cli (#107046)
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/urfave/cli/v2"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
|
||||
authlib "github.com/grafana/authlib/types"
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
dashboard "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1beta1"
|
||||
folders "github.com/grafana/grafana/apps/folder/pkg/apis/folder/v1beta1"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
@@ -52,8 +54,10 @@ func ToUnifiedStorage(c utils.CommandLine, cfg *setting.Cfg, sqlStore db.DB) err
|
||||
},
|
||||
LargeObjects: nil, // TODO... from config
|
||||
Progress: func(count int, msg string) {
|
||||
if count < 1 || time.Since(last) > time.Second {
|
||||
fmt.Printf("[%4d] %s\n", count, msg)
|
||||
const minInterval = time.Second
|
||||
shouldPrint := count < 1 || time.Since(last) > minInterval
|
||||
if shouldPrint {
|
||||
logger.Info(fmt.Sprintf("[%4d] %s", count, msg))
|
||||
last = time.Now()
|
||||
}
|
||||
},
|
||||
@@ -67,7 +71,10 @@ func ToUnifiedStorage(c utils.CommandLine, cfg *setting.Cfg, sqlStore db.DB) err
|
||||
migrator := legacy.NewDashboardAccess(
|
||||
legacysql.NewDatabaseProvider(sqlStore),
|
||||
authlib.OrgNamespaceFormatter,
|
||||
nil, provisioning, nil, sort.ProvideService(),
|
||||
nil, // no dashboards.Store
|
||||
provisioning,
|
||||
nil, // no librarypanels.Service
|
||||
sort.ProvideService(),
|
||||
)
|
||||
|
||||
if c.Bool("non-interactive") {
|
||||
@@ -80,12 +87,13 @@ func ToUnifiedStorage(c utils.CommandLine, cfg *setting.Cfg, sqlStore db.DB) err
|
||||
opts.BlobStore = client
|
||||
rsp, err := migrator.Migrate(ctx, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
msg := fmt.Sprintf("Failed to migrate legacy resources: %+v", err)
|
||||
return cli.Exit(msg, 1)
|
||||
}
|
||||
fmt.Printf("Unified storage export: %s\n", time.Since(start))
|
||||
logger.Info("Migrated legacy resources successfully in", time.Since(start))
|
||||
if rsp != nil {
|
||||
jj, _ := json.MarshalIndent(rsp, "", " ")
|
||||
fmt.Printf("%s\n", string(jj))
|
||||
logger.Info("Migration summary:", string(jj))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user