mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
Add usage stats about correlations
This commit is contained in:
parent
defc230b2c
commit
6f0c70084a
23
pkg/services/correlations/correlationstest/fake.go
Normal file
23
pkg/services/correlations/correlationstest/fake.go
Normal file
@ -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
|
||||
}
|
@ -42,6 +42,7 @@ type SystemStats struct {
|
||||
DataKeys int64
|
||||
ActiveDataKeys int64
|
||||
PublicDashboards int64
|
||||
Correlations int64
|
||||
}
|
||||
|
||||
type DataSourceStats struct {
|
||||
|
@ -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)
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user