diff --git a/pkg/services/correlations/correlationstest/fake.go b/pkg/services/correlations/correlationstest/fake.go new file mode 100644 index 00000000000..8180f35b9e5 --- /dev/null +++ b/pkg/services/correlations/correlationstest/fake.go @@ -0,0 +1,23 @@ +package correlationstest + +import ( + "github.com/grafana/grafana/pkg/api/routing" + "github.com/grafana/grafana/pkg/services/accesscontrol/acimpl" + "github.com/grafana/grafana/pkg/services/correlations" + "github.com/grafana/grafana/pkg/services/datasources" + fakeDatasources "github.com/grafana/grafana/pkg/services/datasources/fakes" + "github.com/grafana/grafana/pkg/services/quota/quotatest" + "github.com/grafana/grafana/pkg/services/sqlstore" + "github.com/grafana/grafana/pkg/setting" +) + +func New(sqlStore *sqlstore.SQLStore) *correlations.CorrelationsService { + ds := &fakeDatasources.FakeDataSourceService{ + DataSources: []*datasources.DataSource{ + {ID: 1, UID: "graphite", Type: datasources.DS_GRAPHITE}, + }, + } + + correlationsSvc, _ := correlations.ProvideService(sqlStore, routing.NewRouteRegister(), ds, acimpl.ProvideAccessControl(setting.NewCfg()), sqlStore.Bus(), quotatest.New(false, nil), sqlStore.Cfg) + return correlationsSvc +} diff --git a/pkg/services/stats/models.go b/pkg/services/stats/models.go index 66ab9dce1ad..ad8c4519531 100644 --- a/pkg/services/stats/models.go +++ b/pkg/services/stats/models.go @@ -42,6 +42,7 @@ type SystemStats struct { DataKeys int64 ActiveDataKeys int64 PublicDashboards int64 + Correlations int64 } type DataSourceStats struct { diff --git a/pkg/services/stats/statsimpl/stats.go b/pkg/services/stats/statsimpl/stats.go index dfc8875cd6b..122f6093707 100644 --- a/pkg/services/stats/statsimpl/stats.go +++ b/pkg/services/stats/statsimpl/stats.go @@ -73,6 +73,7 @@ func (ss *sqlStatsService) GetSystemStats(ctx context.Context, query *stats.GetS sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("star") + `) AS stars,`) sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("playlist") + `) AS playlists,`) sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("alert") + `) AS alerts,`) + sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("correlation") + `) AS correlations,`) now := time.Now() activeUserDeadlineDate := now.Add(-activeUserTimeLimit) diff --git a/pkg/services/stats/statsimpl/stats_test.go b/pkg/services/stats/statsimpl/stats_test.go index e458f49105c..cd8c06eb8ad 100644 --- a/pkg/services/stats/statsimpl/stats_test.go +++ b/pkg/services/stats/statsimpl/stats_test.go @@ -3,6 +3,8 @@ package statsimpl import ( "context" "fmt" + "github.com/grafana/grafana/pkg/services/correlations" + "github.com/grafana/grafana/pkg/services/correlations/correlationstest" "testing" "github.com/stretchr/testify/assert" @@ -38,6 +40,7 @@ func TestIntegrationStatsDataAccess(t *testing.T) { assert.Equal(t, int64(0), result.LibraryPanels) assert.Equal(t, int64(0), result.LibraryVariables) assert.Equal(t, int64(0), result.APIKeys) + assert.Equal(t, int64(2), result.Correlations) }) t.Run("Get system user count stats should not results in error", func(t *testing.T) { @@ -77,6 +80,25 @@ func populateDB(t *testing.T, sqlStore *sqlstore.SQLStore) { orgService, _ := orgimpl.ProvideService(sqlStore, sqlStore.Cfg, quotatest.New(false, nil)) userSvc, _ := userimpl.ProvideService(sqlStore, orgService, sqlStore.Cfg, nil, nil, "atest.FakeQuotaService{}, supportbundlestest.NewFakeBundleService()) + correlationsSvc := correlationstest.New(sqlStore) + + c := make([]correlations.Correlation, 2) + for i := range c { + cmd := correlations.CreateCorrelationCommand{ + Label: fmt.Sprintf("correlation %v", i), + SourceUID: "graphite", + OrgId: 1, + Config: correlations.CorrelationConfig{ + Field: "field", + Target: map[string]interface{}{}, + Type: correlations.ConfigTypeQuery, + }, + } + correlation, err := correlationsSvc.CreateCorrelation(context.Background(), cmd) + require.NoError(t, err) + c[i] = correlation + } + users := make([]user.User, 3) for i := range users { cmd := user.CreateUserCommand{