Chore: Remove datasources from the Store interface (#53515)

This commit is contained in:
Serge Zaitsev
2022-08-10 15:04:51 +02:00
committed by GitHub
parent 86030493a8
commit 6e4b537ba6
6 changed files with 18 additions and 66 deletions
-2
View File
@@ -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{}
@@ -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
}
@@ -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,