mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
chore: remove sqlstore & mockstore dependencies from (most) packages (#57087)
* chore: add alias for InitTestDB and Session Adds an alias for the sqlstore InitTestDB and Session, and updates tests using these to reduce dependencies on the sqlstore.Store. * next pass of removing sqlstore imports * last little bit * remove mockstore where possible
This commit is contained in:
@@ -3,9 +3,9 @@ package searchV2
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/permissions"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/searchstore"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
@@ -22,7 +22,7 @@ type FutureAuthService interface {
|
||||
var _ FutureAuthService = (*simpleSQLAuthService)(nil)
|
||||
|
||||
type simpleSQLAuthService struct {
|
||||
sql *sqlstore.SQLStore
|
||||
sql db.DB
|
||||
ac accesscontrol.Service
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func (a *simpleSQLAuthService) getDashboardTableAuthFilter(user *user.SignedInUs
|
||||
return permissions.DashboardPermissionFilter{
|
||||
OrgRole: user.OrgRole,
|
||||
OrgId: user.OrgID,
|
||||
Dialect: a.sql.Dialect,
|
||||
Dialect: a.sql.GetDialect(),
|
||||
UserId: user.UserID,
|
||||
PermissionLevel: models.PERMISSION_VIEW,
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func (a *simpleSQLAuthService) GetDashboardReadFilter(user *user.SignedInUser) (
|
||||
filter := a.getDashboardTableAuthFilter(user)
|
||||
rows := make([]*dashIdQueryResult, 0)
|
||||
|
||||
err := a.sql.WithDbSession(context.Background(), func(sess *sqlstore.DBSession) error {
|
||||
err := a.sql.WithDbSession(context.Background(), func(sess *db.Session) error {
|
||||
sql, params := filter.Where()
|
||||
sess.Table("dashboard").
|
||||
Where(sql, params...).
|
||||
|
||||
@@ -13,17 +13,17 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/blugelabs/bluge"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/store"
|
||||
kdash "github.com/grafana/grafana/pkg/services/store/kind/dashboard"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
|
||||
"github.com/blugelabs/bluge"
|
||||
)
|
||||
|
||||
type dashboardLoader interface {
|
||||
@@ -805,13 +805,13 @@ func (i *searchIndex) updateDashboard(ctx context.Context, orgID int64, index *o
|
||||
}
|
||||
|
||||
type sqlDashboardLoader struct {
|
||||
sql *sqlstore.SQLStore
|
||||
sql db.DB
|
||||
logger log.Logger
|
||||
tracer tracing.Tracer
|
||||
settings setting.SearchSettings
|
||||
}
|
||||
|
||||
func newSQLDashboardLoader(sql *sqlstore.SQLStore, tracer tracing.Tracer, settings setting.SearchSettings) *sqlDashboardLoader {
|
||||
func newSQLDashboardLoader(sql db.DB, tracer tracing.Tracer, settings setting.SearchSettings) *sqlDashboardLoader {
|
||||
return &sqlDashboardLoader{sql: sql, logger: log.New("sqlDashboardLoader"), tracer: tracer, settings: settings}
|
||||
}
|
||||
|
||||
@@ -847,7 +847,7 @@ func (l sqlDashboardLoader) loadAllDashboards(ctx context.Context, limit int, or
|
||||
dashboardQuerySpan.SetAttributes("lastID", lastID, attribute.Key("lastID").Int64(lastID))
|
||||
|
||||
rows := make([]*dashboardQueryResult, 0)
|
||||
err := l.sql.WithDbSession(dashboardQueryCtx, func(sess *sqlstore.DBSession) error {
|
||||
err := l.sql.WithDbSession(dashboardQueryCtx, func(sess *db.Session) error {
|
||||
sess.Table("dashboard").
|
||||
Where("org_id = ?", orgID)
|
||||
|
||||
@@ -978,10 +978,10 @@ func (l sqlDashboardLoader) LoadDashboards(ctx context.Context, orgID int64, das
|
||||
return dashboards, err
|
||||
}
|
||||
|
||||
func newFolderIDLookup(sql *sqlstore.SQLStore) folderUIDLookup {
|
||||
func newFolderIDLookup(sql db.DB) folderUIDLookup {
|
||||
return func(ctx context.Context, folderID int64) (string, error) {
|
||||
uid := ""
|
||||
err := sql.WithDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
err := sql.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
res, err := sess.Query("SELECT uid FROM dashboard WHERE id=?", folderID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -7,17 +7,18 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana/pkg/services/querylibrary"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/querylibrary"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/registry"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/store"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -64,7 +65,7 @@ type StandardSearchService struct {
|
||||
registry.BackgroundService
|
||||
|
||||
cfg *setting.Cfg
|
||||
sql *sqlstore.SQLStore
|
||||
sql db.DB
|
||||
auth FutureAuthService // eventually injected from elsewhere
|
||||
ac accesscontrol.Service
|
||||
orgService org.Service
|
||||
@@ -82,7 +83,7 @@ func (s *StandardSearchService) IsReady(ctx context.Context, orgId int64) IsSear
|
||||
return s.dashboardIndex.isInitialized(ctx, orgId)
|
||||
}
|
||||
|
||||
func ProvideService(cfg *setting.Cfg, sql *sqlstore.SQLStore, entityEventStore store.EntityEventsService,
|
||||
func ProvideService(cfg *setting.Cfg, sql db.DB, entityEventStore store.EntityEventsService,
|
||||
ac accesscontrol.Service, tracer tracing.Tracer, features featuremgmt.FeatureToggles, orgService org.Service,
|
||||
userService user.Service, queries querylibrary.Service) SearchService {
|
||||
extender := &NoopExtender{}
|
||||
|
||||
Reference in New Issue
Block a user