SQLStore: Enable migration locking by default (#84983)
* Introduce new configuration for migration locking * Remove feature toggle * Fix test and turn it into an integration * Fix docs
This commit is contained in:
@@ -83,12 +83,6 @@ var (
|
||||
Owner: grafanaAsCodeSquad,
|
||||
AllowSelfServe: true,
|
||||
},
|
||||
{
|
||||
Name: "migrationLocking",
|
||||
Description: "Lock database during migrations",
|
||||
Stage: FeatureStagePublicPreview,
|
||||
Owner: grafanaBackendPlatformSquad,
|
||||
},
|
||||
{
|
||||
Name: "storage",
|
||||
Description: "Configurable storage for dashboards, datasources, and resources",
|
||||
|
||||
@@ -8,7 +8,6 @@ publicDashboardsEmailSharing,preview,@grafana/sharing-squad,false,false,false
|
||||
publicDashboardsScene,experimental,@grafana/sharing-squad,false,false,true
|
||||
lokiExperimentalStreaming,experimental,@grafana/observability-logs,false,false,false
|
||||
featureHighlights,GA,@grafana/grafana-as-code,false,false,false
|
||||
migrationLocking,preview,@grafana/backend-platform,false,false,false
|
||||
storage,experimental,@grafana/grafana-app-platform-squad,false,false,false
|
||||
correlations,GA,@grafana/explore-squad,false,false,false
|
||||
exploreContentOutline,GA,@grafana/explore-squad,false,false,true
|
||||
|
||||
|
@@ -43,10 +43,6 @@ const (
|
||||
// Highlight Grafana Enterprise features
|
||||
FlagFeatureHighlights = "featureHighlights"
|
||||
|
||||
// FlagMigrationLocking
|
||||
// Lock database during migrations
|
||||
FlagMigrationLocking = "migrationLocking"
|
||||
|
||||
// FlagStorage
|
||||
// Configurable storage for dashboards, datasources, and resources
|
||||
FlagStorage = "storage"
|
||||
|
||||
@@ -1428,7 +1428,8 @@
|
||||
"metadata": {
|
||||
"name": "migrationLocking",
|
||||
"resourceVersion": "1709648236447",
|
||||
"creationTimestamp": "2024-03-05T14:17:16Z"
|
||||
"creationTimestamp": "2024-03-05T14:17:16Z",
|
||||
"deletionTimestamp": "2024-03-22T10:42:09Z"
|
||||
},
|
||||
"spec": {
|
||||
"description": "Lock database during migrations",
|
||||
|
||||
@@ -39,6 +39,7 @@ type DatabaseConfig struct {
|
||||
WALEnabled bool
|
||||
UrlQueryParams map[string][]string
|
||||
SkipMigrations bool
|
||||
MigrationLock bool
|
||||
MigrationLockAttemptTimeout int
|
||||
LogQueries bool
|
||||
// SQLite only
|
||||
@@ -113,6 +114,7 @@ func (dbCfg *DatabaseConfig) readConfig(cfg *setting.Cfg) error {
|
||||
dbCfg.CacheMode = sec.Key("cache_mode").MustString("private")
|
||||
dbCfg.WALEnabled = sec.Key("wal").MustBool(false)
|
||||
dbCfg.SkipMigrations = sec.Key("skip_migrations").MustBool()
|
||||
dbCfg.MigrationLock = sec.Key("migration_locking").MustBool(true)
|
||||
dbCfg.MigrationLockAttemptTimeout = sec.Key("locking_attempt_timeout_sec").MustInt()
|
||||
|
||||
dbCfg.QueryRetries = sec.Key("query_retries").MustInt()
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/go-sql-driver/mysql"
|
||||
"github.com/golang-migrate/migrate/v4/database"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/ini.v1"
|
||||
@@ -69,7 +70,11 @@ func TestMigrations(t *testing.T) {
|
||||
checkStepsAndDatabaseMatch(t, mg, expectedMigrations)
|
||||
}
|
||||
|
||||
func TestMigrationLock(t *testing.T) {
|
||||
func TestIntegrationMigrationLock(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
dbType := sqlutil.GetTestDBType()
|
||||
if dbType == SQLite {
|
||||
t.Skip()
|
||||
@@ -96,9 +101,12 @@ func TestMigrationLock(t *testing.T) {
|
||||
sess.Close()
|
||||
})
|
||||
|
||||
key, err := database.GenerateAdvisoryLockId("test")
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg := LockCfg{
|
||||
Session: sess,
|
||||
Key: "test",
|
||||
Key: key,
|
||||
}
|
||||
|
||||
t.Run("obtaining lock should succeed", func(t *testing.T) {
|
||||
@@ -143,7 +151,7 @@ func TestMigrationLock(t *testing.T) {
|
||||
err = dialect.Lock(cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = d2.Lock(LockCfg{Session: sess2})
|
||||
err = d2.Lock(LockCfg{Session: sess2, Key: key})
|
||||
require.Error(t, err)
|
||||
assert.ErrorIs(t, err, ErrLockDB)
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ func ProvideService(cfg *setting.Cfg,
|
||||
}
|
||||
s.features = features
|
||||
|
||||
if err := s.Migrate(features.IsEnabledGlobally(featuremgmt.FlagMigrationLocking)); err != nil {
|
||||
if err := s.Migrate(s.dbCfg.MigrationLock); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,6 @@ func MigrateEntityStore(db db.EntityDBInterface, features featuremgmt.FeatureTog
|
||||
}
|
||||
}
|
||||
|
||||
return mg.Start(
|
||||
features.IsEnabledGlobally(featuremgmt.FlagMigrationLocking),
|
||||
0)
|
||||
// since it's a new feature enable migration locking by default
|
||||
return mg.Start(true, 0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user