k8s: remove dependency on app_mode development (#85474)
* k8s: remove dependency on app_mode development * remove dev conditions on storage server * remove logic to drop entity tables
This commit is contained in:
@@ -243,7 +243,7 @@ func (s *service) start(ctx context.Context) error {
|
||||
|
||||
case grafanaapiserveroptions.StorageTypeUnified:
|
||||
if !s.features.IsEnabledGlobally(featuremgmt.FlagUnifiedStorage) {
|
||||
return fmt.Errorf("unified storage requires the unifiedStorage feature flag (and app_mode = development)")
|
||||
return fmt.Errorf("unified storage requires the unifiedStorage feature flag")
|
||||
}
|
||||
|
||||
eDB, err := dbimpl.ProvideEntityDB(s.db, s.cfg, s.features)
|
||||
|
||||
@@ -224,7 +224,7 @@ var (
|
||||
Name: "unifiedStorage",
|
||||
Description: "SQL-based k8s storage",
|
||||
Stage: FeatureStageExperimental,
|
||||
RequiresDevMode: true,
|
||||
RequiresDevMode: false,
|
||||
RequiresRestart: true, // new SQL tables created
|
||||
Owner: grafanaAppPlatformSquad,
|
||||
},
|
||||
|
||||
@@ -27,7 +27,7 @@ logRequestsInstrumentedAsUnknown,experimental,@grafana/hosted-grafana-team,false
|
||||
topnav,deprecated,@grafana/grafana-frontend-platform,false,false,false
|
||||
returnToPrevious,GA,@grafana/grafana-frontend-platform,false,false,true
|
||||
grpcServer,preview,@grafana/grafana-app-platform-squad,false,false,false
|
||||
unifiedStorage,experimental,@grafana/grafana-app-platform-squad,true,true,false
|
||||
unifiedStorage,experimental,@grafana/grafana-app-platform-squad,false,true,false
|
||||
cloudWatchCrossAccountQuerying,GA,@grafana/aws-datasources,false,false,false
|
||||
showDashboardValidationWarnings,experimental,@grafana/dashboards-squad,false,false,false
|
||||
mysqlAnsiQuotes,experimental,@grafana/search-and-storage,false,false,false
|
||||
|
||||
|
@@ -437,14 +437,16 @@
|
||||
{
|
||||
"metadata": {
|
||||
"name": "unifiedStorage",
|
||||
"resourceVersion": "1713545444177",
|
||||
"creationTimestamp": "2024-04-19T16:50:44Z"
|
||||
"resourceVersion": "1714723955745",
|
||||
"creationTimestamp": "2024-04-19T16:50:44Z",
|
||||
"annotations": {
|
||||
"grafana.app/updatedTimestamp": "2024-05-03 08:12:35.745103 +0000 UTC"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"description": "SQL-based k8s storage",
|
||||
"stage": "experimental",
|
||||
"codeowner": "@grafana/grafana-app-platform-squad",
|
||||
"requiresDevMode": true,
|
||||
"requiresRestart": true
|
||||
}
|
||||
},
|
||||
|
||||
@@ -17,8 +17,6 @@ There are 2 main tables, the `entity` table stores a "current" view of the objec
|
||||
The minimum config settings required are:
|
||||
|
||||
```ini
|
||||
; dev mode is required
|
||||
app_mode = development
|
||||
; need to specify target here for override to work later
|
||||
target = all
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/session"
|
||||
"github.com/grafana/grafana/pkg/services/store/entity/db"
|
||||
)
|
||||
|
||||
@@ -24,51 +20,7 @@ func MigrateEntityStore(db db.EntityDBInterface, features featuremgmt.FeatureTog
|
||||
mg := migrator.NewScopedMigrator(engine, db.GetCfg(), "entity")
|
||||
mg.AddCreateMigration()
|
||||
|
||||
marker := initEntityTables(mg)
|
||||
|
||||
// While this feature is under development, we can completly wipe and recreate
|
||||
// The initial plan is to keep the source of truth in existing SQL tables, and mirrot it
|
||||
// to a kubernetes model. Once the kubernetes model needs to be preserved,
|
||||
// this code should be removed
|
||||
exists, err := engine.IsTableExist("entity_migration_log")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if exists {
|
||||
log, err := mg.GetMigrationLog()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, found := log[marker]
|
||||
if !found && len(log) > 0 {
|
||||
// Remove the migration log (and potential other orphan tables)
|
||||
tables := []string{"entity_migration_log"}
|
||||
|
||||
ctx := context.Background()
|
||||
sess, err := db.GetSession()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = sess.WithTransaction(ctx, func(tx *session.SessionTx) error {
|
||||
for _, t := range tables {
|
||||
_, err := tx.Exec(ctx, fmt.Sprintf("DROP TABLE IF EXISTS %s", t))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// remove old entries from in-memory log
|
||||
for id := range log {
|
||||
mg.RemoveMigrationLogs(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
initEntityTables(mg)
|
||||
|
||||
// since it's a new feature enable migration locking by default
|
||||
return mg.Start(true, 0)
|
||||
|
||||
Reference in New Issue
Block a user