unified-storage: make sql backend update key_path for kv store (#114879)

* unified-storage: update resource_history_update_rv.sql to populate key_path in resource_history
This commit is contained in:
Will Assis
2025-12-10 07:06:06 -05:00
committed by GitHub
parent 532a2e5f4d
commit 755b479be4
9 changed files with 346 additions and 9 deletions
@@ -15,5 +15,6 @@ func TestIntegrationBenchmarkSQLStorageBackend(t *testing.T) {
if db.IsTestDbSQLite() {
opts.Concurrency = 1 // to avoid SQLite database is locked error
}
test.BenchmarkStorageBackend(t, newTestBackend(t, true, 2*time.Millisecond), opts)
backend, _ := newTestBackend(t, true, 2*time.Millisecond)
test.BenchmarkStorageBackend(t, backend, opts)
}
@@ -24,6 +24,7 @@ import (
"github.com/grafana/grafana/pkg/storage/unified/resourcepb"
"github.com/grafana/grafana/pkg/storage/unified/search"
"github.com/grafana/grafana/pkg/storage/unified/sql"
sqldb "github.com/grafana/grafana/pkg/storage/unified/sql/db"
"github.com/grafana/grafana/pkg/storage/unified/sql/db/dbimpl"
unitest "github.com/grafana/grafana/pkg/storage/unified/testing"
"github.com/grafana/grafana/pkg/tests/testsuite"
@@ -38,7 +39,7 @@ var initMutex = &sync.Mutex{}
// newTestBackend creates a fresh database and backend for a test.
// It uses a mutex to ensure the entire initialization and migration
// process is atomic and does not race with other parallel tests.
func newTestBackend(t *testing.T, isHA bool, simulatedNetworkLatency time.Duration) resource.StorageBackend {
func newTestBackend(t *testing.T, isHA bool, simulatedNetworkLatency time.Duration) (resource.StorageBackend, sqldb.DB) {
// Lock to ensure the entire init block is atomic.
initMutex.Lock()
// Unlock once the function returns the initialized backend.
@@ -61,7 +62,11 @@ func newTestBackend(t *testing.T, isHA bool, simulatedNetworkLatency time.Durati
// Use a context with a reasonable timeout for migrations.
err = backend.Init(testutil.NewTestContext(t, time.Now().Add(1*time.Minute)))
require.NoError(t, err)
return backend
sqlDB, err := eDB.Init(testutil.NewTestContext(t, time.Now().Add(1*time.Minute)))
require.NoError(t, err)
return backend, sqlDB
}
func TestMain(m *testing.M) {
@@ -73,7 +78,8 @@ func TestIntegrationStorageServer(t *testing.T) {
t.Cleanup(db.CleanupTestDB)
unitest.RunStorageServerTest(t, func(ctx context.Context) resource.StorageBackend {
return newTestBackend(t, true, 0)
backend, _ := newTestBackend(t, true, 0)
return backend
})
}
@@ -84,12 +90,31 @@ func TestIntegrationSQLStorageBackend(t *testing.T) {
t.Run("IsHA (polling notifier)", func(t *testing.T) {
unitest.RunStorageBackendTest(t, func(ctx context.Context) resource.StorageBackend {
return newTestBackend(t, true, 0)
backend, _ := newTestBackend(t, true, 0)
return backend
}, nil)
})
t.Run("NotHA (in process notifier)", func(t *testing.T) {
unitest.RunStorageBackendTest(t, func(ctx context.Context) resource.StorageBackend {
backend, _ := newTestBackend(t, false, 0)
return backend
}, nil)
})
}
func TestIntegrationSQLStorageAndSQLKVCompatibilityTests(t *testing.T) {
testutil.SkipIntegrationTestInShortMode(t)
t.Cleanup(db.CleanupTestDB)
t.Run("IsHA (polling notifier)", func(t *testing.T) {
unitest.RunSQLStorageBackendCompatibilityTest(t, func(ctx context.Context) (resource.StorageBackend, sqldb.DB) {
return newTestBackend(t, true, 0)
}, nil)
})
t.Run("NotHA (in process notifier)", func(t *testing.T) {
unitest.RunSQLStorageBackendCompatibilityTest(t, func(ctx context.Context) (resource.StorageBackend, sqldb.DB) {
return newTestBackend(t, false, 0)
}, nil)
})
@@ -110,7 +135,7 @@ func TestIntegrationSearchAndStorage(t *testing.T) {
t.Cleanup(search.Stop)
// Create a new resource backend
storage := newTestBackend(t, false, 0)
storage, _ := newTestBackend(t, false, 0)
require.NotNil(t, storage)
// Run the shared storage and search tests