diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index a1df871d90a..d8ec0222878 100644 --- a/pkg/api/frontendsettings.go +++ b/pkg/api/frontendsettings.go @@ -203,7 +203,7 @@ func (hs *HTTPServer) getFSDataSources(c *models.ReqContext, enabledPlugins Enab if c.OrgId != 0 { query := datasources.GetDataSourcesQuery{OrgId: c.OrgId, DataSourceLimit: hs.Cfg.DataSourceLimit} - err := hs.SQLStore.GetDataSources(c.Req.Context(), &query) + err := hs.DataSourcesService.GetDataSources(c.Req.Context(), &query) if err != nil { return nil, err diff --git a/pkg/infra/usagestats/service/api_test.go b/pkg/infra/usagestats/service/api_test.go index fd172164d94..756dae9d293 100644 --- a/pkg/infra/usagestats/service/api_test.go +++ b/pkg/infra/usagestats/service/api_test.go @@ -12,7 +12,6 @@ import ( "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/contexthandler/ctxkey" - "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/sqlstore/mockstore" "github.com/grafana/grafana/pkg/services/user" "github.com/grafana/grafana/pkg/setting" @@ -52,7 +51,6 @@ func TestApi_getUsageStats(t *testing.T) { sqlStore.ExpectedSystemStats = &models.SystemStats{} sqlStore.ExpectedDataSourceStats = []*models.DataSourceStats{} - sqlStore.ExpectedDataSources = []*datasources.DataSource{} sqlStore.ExpectedDataSourcesAccessStats = []*models.DataSourceAccessStats{} sqlStore.ExpectedNotifierUsageStats = []*models.NotifierUsageStats{} diff --git a/pkg/infra/usagestats/statscollector/service.go b/pkg/infra/usagestats/statscollector/service.go index 49acd8eb0e8..ae503063342 100644 --- a/pkg/infra/usagestats/statscollector/service.go +++ b/pkg/infra/usagestats/statscollector/service.go @@ -257,7 +257,7 @@ func (s *Service) collectDatasourceStats(ctx context.Context) (map[string]interf func (s *Service) collectElasticStats(ctx context.Context) (map[string]interface{}, error) { m := map[string]interface{}{} esDataSourcesQuery := datasources.GetDataSourcesByTypeQuery{Type: datasources.DS_ES} - if err := s.sqlstore.GetDataSourcesByType(ctx, &esDataSourcesQuery); err != nil { + if err := s.datasources.GetDataSourcesByType(ctx, &esDataSourcesQuery); err != nil { s.log.Error("Failed to get elasticsearch json data", "error", err) return nil, err } diff --git a/pkg/infra/usagestats/statscollector/service_test.go b/pkg/infra/usagestats/statscollector/service_test.go index 73e60b87b73..41ca2b68127 100644 --- a/pkg/infra/usagestats/statscollector/service_test.go +++ b/pkg/infra/usagestats/statscollector/service_test.go @@ -121,7 +121,7 @@ func TestFeatureUsageStats(t *testing.T) { func TestCollectingUsageStats(t *testing.T) { sqlStore := mockstore.NewSQLStoreMock() - sqlStore.ExpectedDataSources = []*datasources.DataSource{ + expectedDataSources := []*datasources.DataSource{ { JsonData: simplejson.NewFromAny(map[string]interface{}{ "esVersion": "2.0.0", @@ -149,7 +149,7 @@ func TestCollectingUsageStats(t *testing.T) { Packaging: "deb", ReportingDistributor: "hosted-grafana", }, sqlStore, - withDatasources(mockDatasourceService{datasources: sqlStore.ExpectedDataSources})) + withDatasources(mockDatasourceService{datasources: expectedDataSources})) s.startTime = time.Now().Add(-1 * time.Minute) @@ -204,19 +204,7 @@ func TestCollectingUsageStats(t *testing.T) { func TestElasticStats(t *testing.T) { sqlStore := mockstore.NewSQLStoreMock() - s := createService(t, &setting.Cfg{ - ReportingEnabled: true, - BuildVersion: "5.0.0", - AnonymousEnabled: true, - BasicAuthEnabled: true, - LDAPEnabled: true, - AuthProxyEnabled: true, - Packaging: "deb", - ReportingDistributor: "hosted-grafana", - }, sqlStore, - withDatasources(mockDatasourceService{datasources: sqlStore.ExpectedDataSources})) - - sqlStore.ExpectedDataSources = []*datasources.DataSource{ + expectedDataSources := []*datasources.DataSource{ { JsonData: simplejson.NewFromAny(map[string]interface{}{ "esVersion": "2.0.0", @@ -234,6 +222,18 @@ func TestElasticStats(t *testing.T) { }, } + s := createService(t, &setting.Cfg{ + ReportingEnabled: true, + BuildVersion: "5.0.0", + AnonymousEnabled: true, + BasicAuthEnabled: true, + LDAPEnabled: true, + AuthProxyEnabled: true, + Packaging: "deb", + ReportingDistributor: "hosted-grafana", + }, sqlStore, + withDatasources(mockDatasourceService{datasources: expectedDataSources})) + metrics, err := s.collectElasticStats(context.Background()) require.NoError(t, err) @@ -265,7 +265,7 @@ func TestDatasourceStats(t *testing.T) { }, } - sqlStore.ExpectedDataSources = []*datasources.DataSource{ + _ = []*datasources.DataSource{ { JsonData: simplejson.NewFromAny(map[string]interface{}{ "esVersion": 2, diff --git a/pkg/services/sqlstore/mockstore/mockstore.go b/pkg/services/sqlstore/mockstore/mockstore.go index e1a62d0c847..aec5f4d3def 100644 --- a/pkg/services/sqlstore/mockstore/mockstore.go +++ b/pkg/services/sqlstore/mockstore/mockstore.go @@ -5,7 +5,6 @@ import ( "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/apikey" - "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/sqlstore" "github.com/grafana/grafana/pkg/services/sqlstore/migrator" "github.com/grafana/grafana/pkg/services/user" @@ -21,7 +20,6 @@ type SQLStoreMock struct { LatestUserId int64 ExpectedUser *user.User - ExpectedDatasource *datasources.DataSource ExpectedAlert *models.Alert ExpectedPluginSetting *models.PluginSetting ExpectedDashboards []*models.Dashboard @@ -31,11 +29,9 @@ type SQLStoreMock struct { ExpectedTeamsByUser []*models.TeamDTO ExpectedSearchOrgList []*models.OrgDTO ExpectedSearchUsers models.SearchUserQueryResult - ExpectedDatasources []*datasources.DataSource ExpectedOrg *models.Org ExpectedSystemStats *models.SystemStats ExpectedDataSourceStats []*models.DataSourceStats - ExpectedDataSources []*datasources.DataSource ExpectedDataSourcesAccessStats []*models.DataSourceAccessStats ExpectedNotifierUsageStats []*models.NotifierUsageStats ExpectedPersistedDashboards models.HitList @@ -374,40 +370,6 @@ func (m *SQLStoreMock) GetDashboards(ctx context.Context, query *models.GetDashb return m.ExpectedError } -func (m SQLStoreMock) GetDataSource(ctx context.Context, query *datasources.GetDataSourceQuery) error { - query.Result = m.ExpectedDatasource - return m.ExpectedError -} - -func (m *SQLStoreMock) GetDataSources(ctx context.Context, query *datasources.GetDataSourcesQuery) error { - query.Result = m.ExpectedDataSources - return m.ExpectedError -} - -func (m *SQLStoreMock) GetDataSourcesByType(ctx context.Context, query *datasources.GetDataSourcesByTypeQuery) error { - query.Result = m.ExpectedDataSources - return m.ExpectedError -} - -func (m *SQLStoreMock) GetDefaultDataSource(ctx context.Context, query *datasources.GetDefaultDataSourceQuery) error { - query.Result = m.ExpectedDatasource - return m.ExpectedError -} - -func (m *SQLStoreMock) DeleteDataSource(ctx context.Context, cmd *datasources.DeleteDataSourceCommand) error { - return m.ExpectedError -} - -func (m *SQLStoreMock) AddDataSource(ctx context.Context, cmd *datasources.AddDataSourceCommand) error { - cmd.Result = m.ExpectedDatasource - return m.ExpectedError -} - -func (m *SQLStoreMock) UpdateDataSource(ctx context.Context, cmd *datasources.UpdateDataSourceCommand) error { - cmd.Result = m.ExpectedDatasource - return m.ExpectedError -} - func (m *SQLStoreMock) Migrate(_ bool) error { return m.ExpectedError } diff --git a/pkg/services/sqlstore/store.go b/pkg/services/sqlstore/store.go index d53c58dff02..89e0fee78c0 100644 --- a/pkg/services/sqlstore/store.go +++ b/pkg/services/sqlstore/store.go @@ -5,7 +5,6 @@ import ( "time" "github.com/grafana/grafana/pkg/models" - "github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/sqlstore/migrator" "github.com/grafana/grafana/pkg/services/user" ) @@ -70,13 +69,6 @@ type Store interface { GetOrgUsers(ctx context.Context, query *models.GetOrgUsersQuery) error SearchOrgUsers(ctx context.Context, query *models.SearchOrgUsersQuery) error RemoveOrgUser(ctx context.Context, cmd *models.RemoveOrgUserCommand) error - GetDataSource(ctx context.Context, query *datasources.GetDataSourceQuery) error - GetDataSources(ctx context.Context, query *datasources.GetDataSourcesQuery) error - GetDataSourcesByType(ctx context.Context, query *datasources.GetDataSourcesByTypeQuery) error - GetDefaultDataSource(ctx context.Context, query *datasources.GetDefaultDataSourceQuery) error - DeleteDataSource(ctx context.Context, cmd *datasources.DeleteDataSourceCommand) error - AddDataSource(ctx context.Context, cmd *datasources.AddDataSourceCommand) error - UpdateDataSource(ctx context.Context, cmd *datasources.UpdateDataSourceCommand) error Migrate(bool) error Sync() error Reset() error