Chore: Remove pkg/models/stats.go (#61613)
* remove pkg/models/stats.go * rename models package in tests
This commit is contained in:
@@ -21,28 +21,28 @@ func ProvideService(db db.DB) stats.Service {
|
||||
|
||||
type sqlStatsService struct{ db db.DB }
|
||||
|
||||
func (ss *sqlStatsService) GetAlertNotifiersUsageStats(ctx context.Context, query *models.GetAlertNotifierUsageStatsQuery) error {
|
||||
func (ss *sqlStatsService) GetAlertNotifiersUsageStats(ctx context.Context, query *stats.GetAlertNotifierUsageStatsQuery) error {
|
||||
return ss.db.WithDbSession(ctx, func(dbSession *db.Session) error {
|
||||
var rawSQL = `SELECT COUNT(*) AS count, type FROM ` + ss.db.GetDialect().Quote("alert_notification") + ` GROUP BY type`
|
||||
query.Result = make([]*models.NotifierUsageStats, 0)
|
||||
query.Result = make([]*stats.NotifierUsageStats, 0)
|
||||
err := dbSession.SQL(rawSQL).Find(&query.Result)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (ss *sqlStatsService) GetDataSourceStats(ctx context.Context, query *models.GetDataSourceStatsQuery) error {
|
||||
func (ss *sqlStatsService) GetDataSourceStats(ctx context.Context, query *stats.GetDataSourceStatsQuery) error {
|
||||
return ss.db.WithDbSession(ctx, func(dbSession *db.Session) error {
|
||||
var rawSQL = `SELECT COUNT(*) AS count, type FROM ` + ss.db.GetDialect().Quote("data_source") + ` GROUP BY type`
|
||||
query.Result = make([]*models.DataSourceStats, 0)
|
||||
query.Result = make([]*stats.DataSourceStats, 0)
|
||||
err := dbSession.SQL(rawSQL).Find(&query.Result)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (ss *sqlStatsService) GetDataSourceAccessStats(ctx context.Context, query *models.GetDataSourceAccessStatsQuery) error {
|
||||
func (ss *sqlStatsService) GetDataSourceAccessStats(ctx context.Context, query *stats.GetDataSourceAccessStatsQuery) error {
|
||||
return ss.db.WithDbSession(ctx, func(dbSession *db.Session) error {
|
||||
var rawSQL = `SELECT COUNT(*) AS count, type, access FROM ` + ss.db.GetDialect().Quote("data_source") + ` GROUP BY type, access`
|
||||
query.Result = make([]*models.DataSourceAccessStats, 0)
|
||||
query.Result = make([]*stats.DataSourceAccessStats, 0)
|
||||
err := dbSession.SQL(rawSQL).Find(&query.Result)
|
||||
return err
|
||||
})
|
||||
@@ -53,7 +53,7 @@ func notServiceAccount(dialect migrator.Dialect) string {
|
||||
dialect.BooleanStr(false)
|
||||
}
|
||||
|
||||
func (ss *sqlStatsService) GetSystemStats(ctx context.Context, query *models.GetSystemStatsQuery) error {
|
||||
func (ss *sqlStatsService) GetSystemStats(ctx context.Context, query *stats.GetSystemStatsQuery) error {
|
||||
return ss.db.WithDbSession(ctx, func(dbSession *db.Session) error {
|
||||
sb := &db.SQLBuilder{}
|
||||
sb.Write("SELECT ")
|
||||
@@ -120,7 +120,7 @@ func (ss *sqlStatsService) GetSystemStats(ctx context.Context, query *models.Get
|
||||
|
||||
sb.Write(ss.roleCounterSQL(ctx))
|
||||
|
||||
var stats models.SystemStats
|
||||
var stats stats.SystemStats
|
||||
_, err := dbSession.SQL(sb.GetSQLString(), sb.GetParams()...).Get(&stats)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -164,7 +164,7 @@ func viewersPermissionsCounterSQL(db db.DB, statName string, isFolder bool, perm
|
||||
) AS ` + statName + `, `
|
||||
}
|
||||
|
||||
func (ss *sqlStatsService) GetAdminStats(ctx context.Context, query *models.GetAdminStatsQuery) error {
|
||||
func (ss *sqlStatsService) GetAdminStats(ctx context.Context, query *stats.GetAdminStatsQuery) error {
|
||||
return ss.db.WithDbSession(ctx, func(dbSession *db.Session) error {
|
||||
dialect := ss.db.GetDialect()
|
||||
now := time.Now()
|
||||
@@ -231,7 +231,7 @@ func (ss *sqlStatsService) GetAdminStats(ctx context.Context, query *models.GetA
|
||||
FROM ` + dialect.Quote("user_auth_token") + ` WHERE rotated_at > ?
|
||||
) AS daily_active_sessions`
|
||||
|
||||
var stats models.AdminStats
|
||||
var stats stats.AdminStats
|
||||
_, err := dbSession.SQL(rawSQL, activeEndDate, dailyActiveEndDate, monthlyActiveEndDate, activeEndDate.Unix(), dailyActiveEndDate.Unix()).Get(&stats)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -242,10 +242,10 @@ func (ss *sqlStatsService) GetAdminStats(ctx context.Context, query *models.GetA
|
||||
})
|
||||
}
|
||||
|
||||
func (ss *sqlStatsService) GetSystemUserCountStats(ctx context.Context, query *models.GetSystemUserCountStatsQuery) error {
|
||||
func (ss *sqlStatsService) GetSystemUserCountStats(ctx context.Context, query *stats.GetSystemUserCountStatsQuery) error {
|
||||
return ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
var rawSQL = `SELECT COUNT(id) AS Count FROM ` + ss.db.GetDialect().Quote("user")
|
||||
var stats models.SystemUserCountStats
|
||||
var stats stats.SystemUserCountStats
|
||||
_, err := sess.SQL(rawSQL).Get(&stats)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -269,9 +269,9 @@ func (ss *sqlStatsService) updateUserRoleCountsIfNecessary(ctx context.Context,
|
||||
}
|
||||
|
||||
type memoUserStats struct {
|
||||
active models.UserStats
|
||||
dailyActive models.UserStats
|
||||
total models.UserStats
|
||||
active stats.UserStats
|
||||
dailyActive stats.UserStats
|
||||
total stats.UserStats
|
||||
|
||||
memoized time.Time
|
||||
}
|
||||
@@ -338,7 +338,7 @@ GROUP BY active, daily_active, role;`
|
||||
})
|
||||
}
|
||||
|
||||
func addToStats(base models.UserStats, role org.RoleType, count int64) models.UserStats {
|
||||
func addToStats(base stats.UserStats, role org.RoleType, count int64) stats.UserStats {
|
||||
base.Users += count
|
||||
|
||||
switch role {
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/org/orgimpl"
|
||||
"github.com/grafana/grafana/pkg/services/quota/quotatest"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/stats"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/services/user/userimpl"
|
||||
)
|
||||
@@ -26,7 +26,7 @@ func TestIntegrationStatsDataAccess(t *testing.T) {
|
||||
populateDB(t, db)
|
||||
|
||||
t.Run("Get system stats should not results in error", func(t *testing.T) {
|
||||
query := models.GetSystemStatsQuery{}
|
||||
query := stats.GetSystemStatsQuery{}
|
||||
err := statsService.GetSystemStats(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, int64(3), query.Result.Users)
|
||||
@@ -39,31 +39,31 @@ func TestIntegrationStatsDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Get system user count stats should not results in error", func(t *testing.T) {
|
||||
query := models.GetSystemUserCountStatsQuery{}
|
||||
query := stats.GetSystemUserCountStatsQuery{}
|
||||
err := statsService.GetSystemUserCountStats(context.Background(), &query)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("Get datasource stats should not results in error", func(t *testing.T) {
|
||||
query := models.GetDataSourceStatsQuery{}
|
||||
query := stats.GetDataSourceStatsQuery{}
|
||||
err := statsService.GetDataSourceStats(context.Background(), &query)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("Get datasource access stats should not results in error", func(t *testing.T) {
|
||||
query := models.GetDataSourceAccessStatsQuery{}
|
||||
query := stats.GetDataSourceAccessStatsQuery{}
|
||||
err := statsService.GetDataSourceAccessStats(context.Background(), &query)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("Get alert notifier stats should not results in error", func(t *testing.T) {
|
||||
query := models.GetAlertNotifierUsageStatsQuery{}
|
||||
query := stats.GetAlertNotifierUsageStatsQuery{}
|
||||
err := statsService.GetAlertNotifiersUsageStats(context.Background(), &query)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("Get admin stats should not result in error", func(t *testing.T) {
|
||||
query := models.GetAdminStatsQuery{}
|
||||
query := stats.GetAdminStatsQuery{}
|
||||
err := statsService.GetAdminStats(context.Background(), &query)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
@@ -123,7 +123,7 @@ func TestIntegration_GetAdminStats(t *testing.T) {
|
||||
db := sqlstore.InitTestDB(t)
|
||||
statsService := ProvideService(db)
|
||||
|
||||
query := models.GetAdminStatsQuery{}
|
||||
query := stats.GetAdminStatsQuery{}
|
||||
err := statsService.GetAdminStats(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user