-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.go
58 lines (49 loc) · 1.65 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package app
import (
"github.com/aws-observability/amazon-managed-grafana-migrator/internal/pkg/log"
gapi "github.com/grafana/grafana-api-golang-client"
)
// allows unit testing to provide mock api clients
type api interface {
// Alerts(params url.Values) ([]gapi.Alert, error)
DataSources() ([]*gapi.DataSource, error)
Dashboards() ([]gapi.FolderDashboardSearchResponse, error)
DashboardsByIDs(ids []int64) ([]gapi.FolderDashboardSearchResponse, error)
DashboardByUID(uid string) (*gapi.Dashboard, error)
Folders() ([]gapi.Folder, error)
NewDataSource(s *gapi.DataSource) (int64, error)
NewDashboard(dashboard gapi.Dashboard) (*gapi.DashboardSaveResponse, error)
NewFolder(title string, uid ...string) (gapi.Folder, error)
NewAlertRule(ar *gapi.AlertRule) (string, error)
}
// App is the main application struct. Contains all the required clients
type App struct {
// Grafana api clients for source and destination workspaces
Src, Dst api
// SrcInput GrafanaInput
Verbose bool
}
// const minAlertingMigrationVersion = 9.4
// Run orchestrates the migration of grafana contents
func (a *App) Run() error {
log.Info()
migratedDs, err := a.migrateDataSources()
if err != nil {
return err
}
log.Success("Migrated ", migratedDs, " data sources")
foldersResponse, err := a.migrateFolders()
log.Debug(a.Verbose, foldersResponse)
if err != nil {
return err
}
log.Success("Migrated ", len(foldersResponse.MigratedFolders), " folders")
dashboards, err := a.migrateDashboards(&foldersResponse.AllDstFolders)
if err != nil {
return err
}
log.Success("Migrated ", dashboards, " dashboards")
log.Info()
log.Info("Skipping alert rules migration")
return nil
}