Chore: Unite wire graphs for cli and server (#61143)

* Chore: unite wire graphs for cli and server

* remove cli wire once again

* try to fix runner wire injection

* unify runner initialisation
This commit is contained in:
Serge Zaitsev 2023-03-17 16:36:39 +01:00 committed by GitHub
parent f5cb8c660e
commit 2d30f33ad8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 84 additions and 466 deletions

View File

@ -77,7 +77,7 @@ gen-cue: ## Do all CUE/Thema code generation
gen-go: $(WIRE) gen-cue
@echo "generate go files"
$(WIRE) gen -tags $(WIRE_TAGS) ./pkg/server ./pkg/cmd/grafana-cli/runner
$(WIRE) gen -tags $(WIRE_TAGS) ./pkg/server
fix-cue: $(CUE)
@echo "formatting cue files"

View File

@ -10,33 +10,25 @@ import (
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands/datamigrations"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands/secretsmigrations"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/runner"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/server"
"github.com/grafana/grafana/pkg/services/sqlstore/migrations"
"github.com/grafana/grafana/pkg/setting"
)
func runRunnerCommand(command func(commandLine utils.CommandLine, runner runner.Runner) error) func(context *cli.Context) error {
func runRunnerCommand(command func(commandLine utils.CommandLine, runner server.Runner) error) func(context *cli.Context) error {
return func(context *cli.Context) error {
cmd := &utils.ContextCommandLine{Context: context}
cfg, err := initCfg(cmd)
if err != nil {
return fmt.Errorf("%v: %w", "failed to load configuration", err)
}
r, err := runner.Initialize(cfg)
runner, err := initializeRunner(cmd)
if err != nil {
return fmt.Errorf("%v: %w", "failed to initialize runner", err)
}
if err := command(cmd, r); err != nil {
if err := command(cmd, runner); err != nil {
return err
}
logger.Info("\n\n")
return nil
}
@ -45,20 +37,19 @@ func runRunnerCommand(command func(commandLine utils.CommandLine, runner runner.
func runDbCommand(command func(commandLine utils.CommandLine, sqlStore db.DB) error) func(context *cli.Context) error {
return func(context *cli.Context) error {
cmd := &utils.ContextCommandLine{Context: context}
cfg, err := initCfg(cmd)
runner, err := initializeRunner(cmd)
if err != nil {
return fmt.Errorf("%v: %w", "failed to load configuration", err)
return fmt.Errorf("%v: %w", "failed to initialize runner", err)
}
tracer, err := tracing.ProvideService(cfg)
tracer, err := tracing.ProvideService(runner.Cfg)
if err != nil {
return fmt.Errorf("%v: %w", "failed to initialize tracer service", err)
}
bus := bus.ProvideBus(tracer)
sqlStore, err := db.ProvideService(cfg, nil, &migrations.OSSMigrations{}, bus, tracer)
sqlStore, err := db.ProvideService(runner.Cfg, nil, &migrations.OSSMigrations{}, bus, tracer)
if err != nil {
return fmt.Errorf("%v: %w", "failed to initialize SQL store", err)
}
@ -72,24 +63,22 @@ func runDbCommand(command func(commandLine utils.CommandLine, sqlStore db.DB) er
}
}
func initCfg(cmd *utils.ContextCommandLine) (*setting.Cfg, error) {
func initializeRunner(cmd *utils.ContextCommandLine) (server.Runner, error) {
configOptions := strings.Split(cmd.String("configOverrides"), " ")
cfg, err := setting.NewCfgFromArgs(setting.CommandLineArgs{
runner, err := server.InitializeForCLI(setting.CommandLineArgs{
Config: cmd.ConfigFile(),
HomePath: cmd.HomePath(),
// tailing arguments have precedence over the options string
Args: append(configOptions, cmd.Args().Slice()...),
})
if err != nil {
return nil, err
return server.Runner{}, fmt.Errorf("%v: %w", "failed to initialize runner", err)
}
if cmd.Bool("debug") {
cfg.LogConfigSources()
runner.Cfg.LogConfigSources()
}
return cfg, nil
return runner, nil
}
func runPluginCommand(command func(commandLine utils.CommandLine) error) func(context *cli.Context) error {

View File

@ -9,15 +9,15 @@ import (
"github.com/fatih/color"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/runner"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
"github.com/grafana/grafana/pkg/server"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/util"
)
const DefaultAdminUserId = 1
func resetPasswordCommand(c utils.CommandLine, runner runner.Runner) error {
func resetPasswordCommand(c utils.CommandLine, runner server.Runner) error {
newPassword := ""
adminId := int64(c.Int("user-id"))

View File

@ -3,20 +3,20 @@ package secretsmigrations
import (
"context"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/runner"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
"github.com/grafana/grafana/pkg/server"
)
func ReEncryptDEKS(_ utils.CommandLine, runner runner.Runner) error {
func ReEncryptDEKS(_ utils.CommandLine, runner server.Runner) error {
return runner.SecretsService.ReEncryptDataKeys(context.Background())
}
func ReEncryptSecrets(_ utils.CommandLine, runner runner.Runner) error {
func ReEncryptSecrets(_ utils.CommandLine, runner server.Runner) error {
_, err := runner.SecretsMigrator.ReEncryptSecrets(context.Background())
return err
}
func RollBackSecrets(_ utils.CommandLine, runner runner.Runner) error {
func RollBackSecrets(_ utils.CommandLine, runner server.Runner) error {
_, err := runner.SecretsMigrator.RollBackSecrets(context.Background())
return err
}

View File

@ -1,352 +0,0 @@
//go:build wireinject
// +build wireinject
package runner
import (
"context"
"github.com/grafana/grafana/pkg/services/folder"
"github.com/grafana/grafana/pkg/services/folder/folderimpl"
"github.com/google/wire"
sdkhttpclient "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
"github.com/grafana/grafana/pkg/api"
"github.com/grafana/grafana/pkg/api/avatar"
"github.com/grafana/grafana/pkg/api/routing"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/cuectx"
"github.com/grafana/grafana/pkg/expr"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/db/dbtest"
"github.com/grafana/grafana/pkg/infra/httpclient"
"github.com/grafana/grafana/pkg/infra/httpclient/httpclientprovider"
"github.com/grafana/grafana/pkg/infra/kvstore"
"github.com/grafana/grafana/pkg/infra/localcache"
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/infra/remotecache"
"github.com/grafana/grafana/pkg/infra/serverlock"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/infra/usagestats"
uss "github.com/grafana/grafana/pkg/infra/usagestats/service"
"github.com/grafana/grafana/pkg/infra/usagestats/statscollector"
loginpkg "github.com/grafana/grafana/pkg/login"
"github.com/grafana/grafana/pkg/login/social"
"github.com/grafana/grafana/pkg/middleware/csrf"
pluginDashboards "github.com/grafana/grafana/pkg/plugins/manager/dashboards"
"github.com/grafana/grafana/pkg/registry/corekind"
"github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
"github.com/grafana/grafana/pkg/services/accesscontrol/ossaccesscontrol"
"github.com/grafana/grafana/pkg/services/alerting"
"github.com/grafana/grafana/pkg/services/auth/jwt"
"github.com/grafana/grafana/pkg/services/cleanup"
"github.com/grafana/grafana/pkg/services/contexthandler"
"github.com/grafana/grafana/pkg/services/contexthandler/authproxy"
"github.com/grafana/grafana/pkg/services/dashboardimport"
dashboardimportservice "github.com/grafana/grafana/pkg/services/dashboardimport/service"
dashboardstore "github.com/grafana/grafana/pkg/services/dashboards/database"
dashboardservice "github.com/grafana/grafana/pkg/services/dashboards/service"
"github.com/grafana/grafana/pkg/services/dashboardsnapshots"
dashsnapstore "github.com/grafana/grafana/pkg/services/dashboardsnapshots/database"
dashsnapsvc "github.com/grafana/grafana/pkg/services/dashboardsnapshots/service"
"github.com/grafana/grafana/pkg/services/dashboardversion/dashverimpl"
"github.com/grafana/grafana/pkg/services/datasourceproxy"
"github.com/grafana/grafana/pkg/services/datasources"
datasourceservice "github.com/grafana/grafana/pkg/services/datasources/service"
"github.com/grafana/grafana/pkg/services/encryption"
encryptionservice "github.com/grafana/grafana/pkg/services/encryption/service"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/guardian"
"github.com/grafana/grafana/pkg/services/hooks"
"github.com/grafana/grafana/pkg/services/libraryelements"
"github.com/grafana/grafana/pkg/services/librarypanels"
"github.com/grafana/grafana/pkg/services/live"
"github.com/grafana/grafana/pkg/services/live/pushhttp"
"github.com/grafana/grafana/pkg/services/login"
"github.com/grafana/grafana/pkg/services/login/authinfoservice"
authinfodatabase "github.com/grafana/grafana/pkg/services/login/authinfoservice/database"
"github.com/grafana/grafana/pkg/services/login/loginservice"
"github.com/grafana/grafana/pkg/services/loginattempt"
"github.com/grafana/grafana/pkg/services/loginattempt/loginattemptimpl"
"github.com/grafana/grafana/pkg/services/ngalert"
ngmetrics "github.com/grafana/grafana/pkg/services/ngalert/metrics"
"github.com/grafana/grafana/pkg/services/notifications"
"github.com/grafana/grafana/pkg/services/oauthtoken"
"github.com/grafana/grafana/pkg/services/org/orgimpl"
"github.com/grafana/grafana/pkg/services/playlist/playlistimpl"
"github.com/grafana/grafana/pkg/services/plugindashboards"
plugindashboardsservice "github.com/grafana/grafana/pkg/services/plugindashboards/service"
"github.com/grafana/grafana/pkg/services/pluginsintegration"
"github.com/grafana/grafana/pkg/services/preference/prefimpl"
"github.com/grafana/grafana/pkg/services/publicdashboards"
publicdashboardsApi "github.com/grafana/grafana/pkg/services/publicdashboards/api"
publicdashboardsStore "github.com/grafana/grafana/pkg/services/publicdashboards/database"
publicdashboardsService "github.com/grafana/grafana/pkg/services/publicdashboards/service"
"github.com/grafana/grafana/pkg/services/query"
"github.com/grafana/grafana/pkg/services/queryhistory"
"github.com/grafana/grafana/pkg/services/quota/quotaimpl"
"github.com/grafana/grafana/pkg/services/rendering"
"github.com/grafana/grafana/pkg/services/search"
"github.com/grafana/grafana/pkg/services/searchV2"
"github.com/grafana/grafana/pkg/services/secrets"
secretsDatabase "github.com/grafana/grafana/pkg/services/secrets/database"
secretsStore "github.com/grafana/grafana/pkg/services/secrets/kvstore"
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
secretsMigrator "github.com/grafana/grafana/pkg/services/secrets/migrator"
"github.com/grafana/grafana/pkg/services/serviceaccounts"
serviceaccountsmanager "github.com/grafana/grafana/pkg/services/serviceaccounts/manager"
"github.com/grafana/grafana/pkg/services/shorturls"
"github.com/grafana/grafana/pkg/services/shorturls/shorturlimpl"
"github.com/grafana/grafana/pkg/services/sqlstore"
starApi "github.com/grafana/grafana/pkg/services/star/api"
"github.com/grafana/grafana/pkg/services/star/starimpl"
"github.com/grafana/grafana/pkg/services/store"
entitystoredummy "github.com/grafana/grafana/pkg/services/store/entity/dummy"
"github.com/grafana/grafana/pkg/services/store/sanitizer"
"github.com/grafana/grafana/pkg/services/supportbundles"
"github.com/grafana/grafana/pkg/services/supportbundles/bundleregistry"
"github.com/grafana/grafana/pkg/services/tag"
"github.com/grafana/grafana/pkg/services/tag/tagimpl"
"github.com/grafana/grafana/pkg/services/team/teamimpl"
"github.com/grafana/grafana/pkg/services/teamguardian"
teamguardianDatabase "github.com/grafana/grafana/pkg/services/teamguardian/database"
teamguardianManager "github.com/grafana/grafana/pkg/services/teamguardian/manager"
"github.com/grafana/grafana/pkg/services/thumbs"
"github.com/grafana/grafana/pkg/services/updatechecker"
"github.com/grafana/grafana/pkg/services/user/userimpl"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/tsdb/azuremonitor"
"github.com/grafana/grafana/pkg/tsdb/cloudmonitoring"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch"
"github.com/grafana/grafana/pkg/tsdb/elasticsearch"
"github.com/grafana/grafana/pkg/tsdb/grafanads"
"github.com/grafana/grafana/pkg/tsdb/graphite"
"github.com/grafana/grafana/pkg/tsdb/influxdb"
"github.com/grafana/grafana/pkg/tsdb/legacydata"
legacydataservice "github.com/grafana/grafana/pkg/tsdb/legacydata/service"
"github.com/grafana/grafana/pkg/tsdb/loki"
"github.com/grafana/grafana/pkg/tsdb/mssql"
"github.com/grafana/grafana/pkg/tsdb/mysql"
"github.com/grafana/grafana/pkg/tsdb/opentsdb"
"github.com/grafana/grafana/pkg/tsdb/parca"
"github.com/grafana/grafana/pkg/tsdb/phlare"
"github.com/grafana/grafana/pkg/tsdb/postgres"
"github.com/grafana/grafana/pkg/tsdb/prometheus"
"github.com/grafana/grafana/pkg/tsdb/tempo"
"github.com/grafana/grafana/pkg/tsdb/testdatasource"
"github.com/grafana/grafana/pkg/web"
)
var wireSet = wire.NewSet(
New,
localcache.ProvideService,
tracing.ProvideService,
bus.ProvideBus,
featuremgmt.ProvideManagerService,
featuremgmt.ProvideToggles,
wire.Bind(new(bus.Bus), new(*bus.InProcBus)),
db.ProvideService,
wire.InterfaceValue(new(usagestats.Service), noOpUsageStats{}),
wire.InterfaceValue(new(routing.RouteRegister), noOpRouteRegister{}),
encryptionservice.ProvideEncryptionService,
wire.Bind(new(encryption.Internal), new(*encryptionservice.Service)),
secretsDatabase.ProvideSecretsStore,
wire.Bind(new(secrets.Store), new(*secretsDatabase.SecretsStoreImpl)),
secretsManager.ProvideSecretsService,
wire.Bind(new(secrets.Service), new(*secretsManager.SecretsService)),
bundleregistry.ProvideService,
wire.Bind(new(supportbundles.Service), new(*bundleregistry.Service)),
hooks.ProvideService,
legacydataservice.ProvideService,
wire.Bind(new(legacydata.RequestHandler), new(*legacydataservice.Service)),
alerting.ProvideAlertStore,
alerting.ProvideAlertEngine,
wire.Bind(new(alerting.UsageStatsQuerier), new(*alerting.AlertEngine)),
api.ProvideHTTPServer,
query.ProvideService,
thumbs.ProvideService,
rendering.ProvideService,
wire.Bind(new(rendering.Service), new(*rendering.RenderingService)),
kvstore.ProvideService,
updatechecker.ProvideGrafanaService,
updatechecker.ProvidePluginsService,
uss.ProvideService,
pluginsintegration.WireSet,
pluginDashboards.ProvideFileStoreManager,
wire.Bind(new(pluginDashboards.FileStore), new(*pluginDashboards.FileStoreManager)),
cloudwatch.ProvideService,
cloudmonitoring.ProvideService,
azuremonitor.ProvideService,
postgres.ProvideService,
mysql.ProvideService,
mssql.ProvideService,
store.ProvideEntityEventsService,
httpclientprovider.New,
wire.Bind(new(httpclient.Provider), new(*sdkhttpclient.Provider)),
serverlock.ProvideService,
cleanup.ProvideService,
shorturlimpl.ProvideService,
wire.Bind(new(shorturls.Service), new(*shorturlimpl.ShortURLService)),
queryhistory.ProvideService,
wire.Bind(new(queryhistory.Service), new(*queryhistory.QueryHistoryService)),
quotaimpl.ProvideService,
remotecache.ProvideService,
loginservice.ProvideService,
wire.Bind(new(login.Service), new(*loginservice.Implementation)),
authinfoservice.ProvideAuthInfoService,
wire.Bind(new(login.AuthInfoService), new(*authinfoservice.Implementation)),
authinfodatabase.ProvideAuthInfoStore,
loginpkg.ProvideService,
wire.Bind(new(loginpkg.Authenticator), new(*loginpkg.AuthenticatorService)),
loginattemptimpl.ProvideService,
wire.Bind(new(loginattempt.Service), new(*loginattemptimpl.Service)),
datasourceproxy.ProvideService,
search.ProvideService,
searchV2.ProvideService,
store.ProvideService,
live.ProvideService,
pushhttp.ProvideService,
contexthandler.ProvideService,
jwt.ProvideService,
wire.Bind(new(jwt.JWTService), new(*jwt.AuthService)),
ngalert.ProvideService,
librarypanels.ProvideService,
wire.Bind(new(librarypanels.Service), new(*librarypanels.LibraryPanelService)),
libraryelements.ProvideService,
wire.Bind(new(libraryelements.Service), new(*libraryelements.LibraryElementService)),
notifications.ProvideService,
notifications.ProvideSmtpService,
metrics.ProvideService,
testdatasource.ProvideService,
social.ProvideService,
influxdb.ProvideService,
wire.Bind(new(social.Service), new(*social.SocialService)),
oauthtoken.ProvideService,
wire.Bind(new(oauthtoken.OAuthTokenService), new(*oauthtoken.Service)),
tempo.ProvideService,
loki.ProvideService,
graphite.ProvideService,
prometheus.ProvideService,
elasticsearch.ProvideService,
phlare.ProvideService,
parca.ProvideService,
secretsMigrator.ProvideSecretsMigrator,
wire.Bind(new(secrets.Migrator), new(*secretsMigrator.SecretsMigrator)),
grafanads.ProvideService,
wire.Bind(new(dashboardsnapshots.Store), new(*dashsnapstore.DashboardSnapshotStore)),
dashsnapstore.ProvideStore,
wire.Bind(new(dashboardsnapshots.Service), new(*dashsnapsvc.ServiceImpl)),
dashsnapsvc.ProvideService,
datasourceservice.ProvideService,
wire.Bind(new(datasources.DataSourceService), new(*datasourceservice.Service)),
alerting.ProvideService,
ossaccesscontrol.ProvideServiceAccountPermissions,
wire.Bind(new(accesscontrol.ServiceAccountPermissionsService), new(*ossaccesscontrol.ServiceAccountPermissionsService)),
serviceaccountsmanager.ProvideServiceAccountsService,
wire.Bind(new(serviceaccounts.Service), new(*serviceaccountsmanager.ServiceAccountsService)),
expr.ProvideService,
teamguardianDatabase.ProvideTeamGuardianStore,
wire.Bind(new(teamguardian.Store), new(*teamguardianDatabase.TeamGuardianStoreImpl)),
teamguardianManager.ProvideService,
dashboardservice.ProvideDashboardServiceImpl,
dashboardstore.ProvideDashboardStore,
dashboardservice.ProvideDashboardService,
dashboardservice.ProvideDashboardProvisioningService,
dashboardservice.ProvideDashboardPluginService,
folderimpl.ProvideDashboardFolderStore,
wire.Bind(new(folder.FolderStore), new(*folderimpl.DashboardFolderStoreImpl)),
dashboardimportservice.ProvideService,
wire.Bind(new(dashboardimport.Service), new(*dashboardimportservice.ImportDashboardService)),
plugindashboardsservice.ProvideService,
wire.Bind(new(plugindashboards.Service), new(*plugindashboardsservice.Service)),
plugindashboardsservice.ProvideDashboardUpdater,
alerting.ProvideDashAlertExtractorService,
wire.Bind(new(alerting.DashAlertExtractor), new(*alerting.DashAlertExtractorService)),
guardian.ProvideService,
sanitizer.ProvideService,
secretsStore.ProvideService,
avatar.ProvideAvatarCacheServer,
authproxy.ProvideAuthProxy,
statscollector.ProvideService,
corekind.KindSet,
cuectx.GrafanaCUEContext,
cuectx.GrafanaThemaRuntime,
csrf.ProvideCSRFFilter,
ossaccesscontrol.ProvideTeamPermissions,
wire.Bind(new(accesscontrol.TeamPermissionsService), new(*ossaccesscontrol.TeamPermissionsService)),
ossaccesscontrol.ProvideFolderPermissions,
wire.Bind(new(accesscontrol.FolderPermissionsService), new(*ossaccesscontrol.FolderPermissionsService)),
ossaccesscontrol.ProvideDashboardPermissions,
wire.Bind(new(accesscontrol.DashboardPermissionsService), new(*ossaccesscontrol.DashboardPermissionsService)),
starimpl.ProvideService,
playlistimpl.ProvideService,
dashverimpl.ProvideService,
publicdashboardsService.ProvideService,
wire.Bind(new(publicdashboards.Service), new(*publicdashboardsService.PublicDashboardServiceImpl)),
publicdashboardsStore.ProvideStore,
wire.Bind(new(publicdashboards.Store), new(*publicdashboardsStore.PublicDashboardStoreImpl)),
publicdashboardsApi.ProvideApi,
starApi.ProvideApi,
userimpl.ProvideService,
orgimpl.ProvideService,
teamimpl.ProvideService,
ngmetrics.ProvideServiceForTest,
notifications.MockNotificationService,
entitystoredummy.ProvideFakeEntityServer,
wire.Bind(new(notifications.TempUserStore), new(*dbtest.FakeDB)),
wire.Bind(new(notifications.Service), new(*notifications.NotificationServiceMock)),
wire.Bind(new(notifications.WebhookSender), new(*notifications.NotificationServiceMock)),
wire.Bind(new(notifications.EmailSender), new(*notifications.NotificationServiceMock)),
dbtest.NewFakeDB,
wire.Bind(new(db.DB), new(*sqlstore.SQLStore)),
prefimpl.ProvideService,
opentsdb.ProvideService,
acimpl.ProvideAccessControl,
wire.Bind(new(accesscontrol.AccessControl), new(*acimpl.AccessControl)),
tagimpl.ProvideService,
wire.Bind(new(tag.Service), new(*tagimpl.Service)),
)
func Initialize(cfg *setting.Cfg) (Runner, error) {
wire.Build(wireExtsSet)
return Runner{}, nil
}
// NoOp implementations of those dependencies that makes no sense to
// inject on CLI command executions (like the route registerer, for instance).
type noOpUsageStats struct{}
func (noOpUsageStats) GetUsageReport(context.Context) (usagestats.Report, error) {
return usagestats.Report{}, nil
}
func (noOpUsageStats) RegisterMetricsFunc(_ usagestats.MetricsFunc) {}
func (noOpUsageStats) RegisterSendReportCallback(_ usagestats.SendReportCallbackFunc) {}
func (noOpUsageStats) ShouldBeReported(context.Context, string) bool { return false }
type noOpRouteRegister struct{}
func (noOpRouteRegister) Get(string, ...web.Handler) {}
func (noOpRouteRegister) Post(string, ...web.Handler) {}
func (noOpRouteRegister) Delete(string, ...web.Handler) {}
func (noOpRouteRegister) Put(string, ...web.Handler) {}
func (noOpRouteRegister) Patch(string, ...web.Handler) {}
func (noOpRouteRegister) Any(string, ...web.Handler) {}
func (noOpRouteRegister) Group(string, func(routing.RouteRegister), ...web.Handler) {}
func (noOpRouteRegister) Insert(string, func(routing.RouteRegister), ...web.Handler) {}
func (noOpRouteRegister) Register(routing.Router, ...routing.RegisterNamedMiddleware) {}
func (noOpRouteRegister) Reset() {}

View File

@ -1,82 +0,0 @@
//go:build wireinject && oss
// +build wireinject,oss
package runner
import (
"github.com/google/wire"
"github.com/grafana/grafana/pkg/registry"
"github.com/grafana/grafana/pkg/server/backgroundsvcs"
"github.com/grafana/grafana/pkg/server/usagestatssvcs"
"github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
"github.com/grafana/grafana/pkg/services/accesscontrol/ossaccesscontrol"
"github.com/grafana/grafana/pkg/services/auth"
"github.com/grafana/grafana/pkg/services/auth/authimpl"
"github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/datasources/permissions"
datasourceservice "github.com/grafana/grafana/pkg/services/datasources/service"
"github.com/grafana/grafana/pkg/services/encryption"
encryptionprovider "github.com/grafana/grafana/pkg/services/encryption/provider"
"github.com/grafana/grafana/pkg/services/kmsproviders"
"github.com/grafana/grafana/pkg/services/kmsproviders/osskmsproviders"
"github.com/grafana/grafana/pkg/services/ldap"
"github.com/grafana/grafana/pkg/services/licensing"
"github.com/grafana/grafana/pkg/services/login"
"github.com/grafana/grafana/pkg/services/login/authinfoservice"
"github.com/grafana/grafana/pkg/services/pluginsintegration"
"github.com/grafana/grafana/pkg/services/provisioning"
"github.com/grafana/grafana/pkg/services/searchusers"
"github.com/grafana/grafana/pkg/services/searchusers/filters"
"github.com/grafana/grafana/pkg/services/sqlstore/migrations"
"github.com/grafana/grafana/pkg/services/thumbs"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/services/validations"
"github.com/grafana/grafana/pkg/setting"
)
var wireExtsSet = wire.NewSet(
wireSet,
migrations.ProvideOSSMigrations,
licensing.ProvideService,
wire.Bind(new(licensing.Licensing), new(*licensing.OSSLicensingService)),
wire.Bind(new(registry.DatabaseMigrator), new(*migrations.OSSMigrations)),
setting.ProvideProvider,
wire.Bind(new(setting.Provider), new(*setting.OSSImpl)),
osskmsproviders.ProvideService,
wire.Bind(new(kmsproviders.Service), new(osskmsproviders.Service)),
authimpl.ProvideUserAuthTokenService,
wire.Bind(new(auth.UserTokenService), new(*authimpl.UserAuthTokenService)),
wire.Bind(new(auth.UserTokenBackgroundService), new(*authimpl.UserAuthTokenService)),
acimpl.ProvideService,
wire.Bind(new(accesscontrol.Service), new(*acimpl.Service)),
wire.Bind(new(accesscontrol.RoleRegistry), new(*acimpl.Service)),
thumbs.ProvideCrawlerAuthSetupService,
wire.Bind(new(thumbs.CrawlerAuthSetupService), new(*thumbs.OSSCrawlerAuthSetupService)),
validations.ProvideValidator,
wire.Bind(new(validations.PluginRequestValidator), new(*validations.OSSPluginRequestValidator)),
provisioning.ProvideService,
wire.Bind(new(provisioning.ProvisioningService), new(*provisioning.ProvisioningServiceImpl)),
backgroundsvcs.ProvideBackgroundServiceRegistry,
wire.Bind(new(registry.BackgroundServiceRegistry), new(*backgroundsvcs.BackgroundServiceRegistry)),
datasourceservice.ProvideCacheService,
wire.Bind(new(datasources.CacheService), new(*datasourceservice.CacheServiceImpl)),
authinfoservice.ProvideOSSUserProtectionService,
wire.Bind(new(login.UserProtectionService), new(*authinfoservice.OSSUserProtectionImpl)),
filters.ProvideOSSSearchUserFilter,
wire.Bind(new(user.SearchUserFilter), new(*filters.OSSSearchUserFilter)),
searchusers.ProvideUsersService,
wire.Bind(new(searchusers.Service), new(*searchusers.OSSService)),
ldap.ProvideGroupsService,
wire.Bind(new(ldap.Groups), new(*ldap.OSSGroups)),
permissions.ProvideDatasourcePermissionsService,
wire.Bind(new(permissions.DatasourcePermissionsService), new(*permissions.OSSDatasourcePermissionsService)),
usagestatssvcs.ProvideUsageStatsProvidersRegistry,
wire.Bind(new(registry.UsageStatsProvidersRegistry), new(*usagestatssvcs.UsageStatsProvidersRegistry)),
ossaccesscontrol.ProvideDatasourcePermissionsService,
wire.Bind(new(accesscontrol.DatasourcePermissionsService), new(*ossaccesscontrol.DatasourcePermissionsService)),
encryptionprovider.ProvideEncryptionProvider,
wire.Bind(new(encryption.Provider), new(encryptionprovider.Provider)),
pluginsintegration.WireExtensionSet,
)

39
pkg/server/runner.go Normal file
View File

@ -0,0 +1,39 @@
package server
import (
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/services/encryption"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/secrets"
"github.com/grafana/grafana/pkg/services/secrets/manager"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/setting"
)
type Runner struct {
Cfg *setting.Cfg
SQLStore db.DB
SettingsProvider setting.Provider
Features featuremgmt.FeatureToggles
EncryptionService encryption.Internal
SecretsService *manager.SecretsService
SecretsMigrator secrets.Migrator
UserService user.Service
}
func NewRunner(cfg *setting.Cfg, sqlStore db.DB, settingsProvider setting.Provider,
encryptionService encryption.Internal, features featuremgmt.FeatureToggles,
secretsService *manager.SecretsService, secretsMigrator secrets.Migrator,
userService user.Service,
) Runner {
return Runner{
Cfg: cfg,
SQLStore: sqlStore,
SettingsProvider: settingsProvider,
EncryptionService: encryptionService,
SecretsService: secretsService,
SecretsMigrator: secretsMigrator,
Features: features,
UserService: userService,
}
}

View File

@ -168,7 +168,6 @@ var wireBasicSet = wire.NewSet(
alerting.ProvideAlertStore,
alerting.ProvideAlertEngine,
wire.Bind(new(alerting.UsageStatsQuerier), new(*alerting.AlertEngine)),
setting.NewCfgFromArgs,
New,
api.ProvideHTTPServer,
query.ProvideService,
@ -338,6 +337,7 @@ var wireBasicSet = wire.NewSet(
grpcserver.ProvideHealthService,
grpcserver.ProvideReflectionService,
interceptors.ProvideAuthenticator,
setting.NewCfgFromArgs,
kind.ProvideService, // The registry of known kinds
sqlstash.ProvideSQLEntityServer,
resolver.ProvideEntityReferenceResolver,
@ -376,6 +376,20 @@ var wireSet = wire.NewSet(
wire.Bind(new(oauthtoken.OAuthTokenService), new(*oauthtoken.Service)),
)
var wireCLISet = wire.NewSet(
NewRunner,
wireBasicSet,
sqlstore.ProvideService,
ngmetrics.ProvideService,
wire.Bind(new(notifications.Service), new(*notifications.NotificationService)),
wire.Bind(new(notifications.WebhookSender), new(*notifications.NotificationService)),
wire.Bind(new(notifications.EmailSender), new(*notifications.NotificationService)),
wire.Bind(new(db.DB), new(*sqlstore.SQLStore)),
prefimpl.ProvideService,
oauthtoken.ProvideService,
wire.Bind(new(oauthtoken.OAuthTokenService), new(*oauthtoken.Service)),
)
var wireTestSet = wire.NewSet(
wireBasicSet,
ProvideTestEnv,
@ -402,3 +416,8 @@ func InitializeForTest(cla setting.CommandLineArgs, opts Options, apiOpts api.Se
wire.Build(wireExtsTestSet)
return &TestEnv{Server: &Server{}, SQLStore: &sqlstore.SQLStore{}}, nil
}
func InitializeForCLI(cla setting.CommandLineArgs) (Runner, error) {
wire.Build(wireExtsCLISet)
return Runner{}, nil
}

View File

@ -95,6 +95,11 @@ var wireExtsSet = wire.NewSet(
wireExtsBasicSet,
)
var wireExtsCLISet = wire.NewSet(
wireCLISet,
wireExtsBasicSet,
)
var wireExtsTestSet = wire.NewSet(
wireTestSet,
wireExtsBasicSet,