From c4d32dd68714b419c3f3452e7e5fce928f8d3e71 Mon Sep 17 00:00:00 2001 From: George Robinson Date: Mon, 5 Sep 2022 18:24:19 +0100 Subject: [PATCH] Fix nil logger in SqlStore (#54726) --- pkg/services/datasources/service/cache.go | 4 ++-- pkg/services/datasources/service/store.go | 4 ++-- .../secrets/kvstore/migrations/datasource_mig_test.go | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/services/datasources/service/cache.go b/pkg/services/datasources/service/cache.go index 0d4729ec303..42d6b3df181 100644 --- a/pkg/services/datasources/service/cache.go +++ b/pkg/services/datasources/service/cache.go @@ -52,7 +52,7 @@ func (dc *CacheServiceImpl) GetDatasource( dc.logger.Debug("Querying for data source via SQL store", "id", datasourceID, "orgId", user.OrgID) query := &datasources.GetDataSourceQuery{Id: datasourceID, OrgId: user.OrgID} - ss := SqlStore{db: dc.SQLStore} + ss := SqlStore{db: dc.SQLStore, logger: dc.logger} err := ss.GetDataSource(ctx, query) if err != nil { return nil, err @@ -92,7 +92,7 @@ func (dc *CacheServiceImpl) GetDatasourceByUID( dc.logger.Debug("Querying for data source via SQL store", "uid", datasourceUID, "orgId", user.OrgID) query := &datasources.GetDataSourceQuery{Uid: datasourceUID, OrgId: user.OrgID} - ss := SqlStore{db: dc.SQLStore} + ss := SqlStore{db: dc.SQLStore, logger: dc.logger} err := ss.GetDataSource(ctx, query) if err != nil { return nil, err diff --git a/pkg/services/datasources/service/store.go b/pkg/services/datasources/service/store.go index e6dfaf94502..17d1478fd20 100644 --- a/pkg/services/datasources/service/store.go +++ b/pkg/services/datasources/service/store.go @@ -36,8 +36,8 @@ type SqlStore struct { logger log.Logger } -func CreateStore(db sqlstore.Store) *SqlStore { - return &SqlStore{db: db} +func CreateStore(db sqlstore.Store, logger log.Logger) *SqlStore { + return &SqlStore{db: db, logger: logger} } // GetDataSource adds a datasource to the query model by querying by org_id as well as diff --git a/pkg/services/secrets/kvstore/migrations/datasource_mig_test.go b/pkg/services/secrets/kvstore/migrations/datasource_mig_test.go index 8e3753199aa..50d6a90adb3 100644 --- a/pkg/services/secrets/kvstore/migrations/datasource_mig_test.go +++ b/pkg/services/secrets/kvstore/migrations/datasource_mig_test.go @@ -38,7 +38,7 @@ func TestMigrate(t *testing.T) { secretsService := secretsmng.SetupTestService(t, fakes.NewFakeSecretsStore()) secretsStore := secretskvs.NewSQLSecretsKVStore(sqlStore, secretsService, log.New("test.logger")) migService := SetupTestDataSourceSecretMigrationService(t, sqlStore, kvStore, secretsStore, false) - ds := dsservice.CreateStore(sqlStore) + ds := dsservice.CreateStore(sqlStore, log.NewNopLogger()) dataSourceName := "Test" dataSourceOrg := int64(1) err := ds.AddDataSource(context.Background(), &datasources.AddDataSourceCommand{ @@ -102,7 +102,7 @@ func TestMigrate(t *testing.T) { secretsService := secretsmng.SetupTestService(t, fakes.NewFakeSecretsStore()) secretsStore := secretskvs.NewSQLSecretsKVStore(sqlStore, secretsService, log.New("test.logger")) migService := SetupTestDataSourceSecretMigrationService(t, sqlStore, kvStore, secretsStore, true) - ds := dsservice.CreateStore(sqlStore) + ds := dsservice.CreateStore(sqlStore, log.NewNopLogger()) dataSourceName := "Test" dataSourceOrg := int64(1) @@ -169,7 +169,7 @@ func TestMigrate(t *testing.T) { secretsService := secretsmng.SetupTestService(t, fakes.NewFakeSecretsStore()) secretsStore := secretskvs.NewSQLSecretsKVStore(sqlStore, secretsService, log.New("test.logger")) migService := SetupTestDataSourceSecretMigrationService(t, sqlStore, kvStore, secretsStore, false) - ds := dsservice.CreateStore(sqlStore) + ds := dsservice.CreateStore(sqlStore, log.NewNopLogger()) dataSourceName := "Test" dataSourceOrg := int64(1) @@ -260,7 +260,7 @@ func TestMigrate(t *testing.T) { secretsService := secretsmng.SetupTestService(t, fakes.NewFakeSecretsStore()) secretsStore := secretskvs.NewSQLSecretsKVStore(sqlStore, secretsService, log.New("test.logger")) migService := SetupTestDataSourceSecretMigrationService(t, sqlStore, kvStore, secretsStore, true) - ds := dsservice.CreateStore(sqlStore) + ds := dsservice.CreateStore(sqlStore, log.NewNopLogger()) dataSourceName := "Test" dataSourceOrg := int64(1)