feat: add ability to launch targeted dskit modules in the grafana server CLI command (#74188)

* feat: add ability to launch targeted dskit modules in the grafana server CLI command

This commit adds a ModuleServer and ModuleRunner suitable for launching dskit services and updates the server cli command to use this instead of the full Server. The default behavior is unchanged and will launch the full Grafana server. Individual services are targeted by setting target=comma,seperated,list in the config file.

* require dev mode to target dskit modules

* remove unused type

* replace setting.CommandLineArgs w/setting.Cfg; the caller can deal with calling setting.NewCfg

* Update pkg/server/module_server.go

Co-authored-by: Serge Zaitsev <serge.zaitsev@grafana.com>

---------

Co-authored-by: Serge Zaitsev <serge.zaitsev@grafana.com>
This commit is contained in:
Kristin Laemmert
2023-09-01 08:09:54 -04:00
committed by GitHub
co-authored by Serge Zaitsev
parent 94dd17a936
commit 0de2c9eb96
12 changed files with 321 additions and 50 deletions
+20 -4
View File
@@ -1,6 +1,9 @@
//go:build wireinject
// +build wireinject
// This file should contain wire sets used by both OSS and Enterprise builds.
// Use wireext_oss.go and wireext_enterprise.go for sets that are specific to
// the respective builds.
package server
import (
@@ -325,7 +328,6 @@ var wireBasicSet = wire.NewSet(
grpcserver.ProvideHealthService,
grpcserver.ProvideReflectionService,
interceptors.ProvideAuthenticator,
setting.NewCfgFromArgs,
kind.ProvideService, // The registry of known kinds
sqlstash.ProvideSQLEntityServer,
resolver.ProvideEntityReferenceResolver,
@@ -401,17 +403,31 @@ var wireTestSet = wire.NewSet(
wire.Bind(new(oauthtoken.OAuthTokenService), new(*oauthtokentest.Service)),
)
func Initialize(cla setting.CommandLineArgs, opts Options, apiOpts api.ServerOptions) (*Server, error) {
func Initialize(cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions) (*Server, error) {
wire.Build(wireExtsSet)
return &Server{}, nil
}
func InitializeForTest(cla setting.CommandLineArgs, opts Options, apiOpts api.ServerOptions) (*TestEnv, error) {
func InitializeForTest(cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions) (*TestEnv, error) {
wire.Build(wireExtsTestSet)
return &TestEnv{Server: &Server{}, SQLStore: &sqlstore.SQLStore{}}, nil
}
func InitializeForCLI(cla setting.CommandLineArgs) (Runner, error) {
func InitializeForCLI(cfg *setting.Cfg) (Runner, error) {
wire.Build(wireExtsCLISet)
return Runner{}, nil
}
// InitializeForCLITarget is a simplified set of dependencies for the CLI, used
// by the server target subcommand to launch specific dskit modules.
func InitializeForCLITarget(cfg *setting.Cfg) (ModuleRunner, error) {
wire.Build(wireExtsBaseCLISet)
return ModuleRunner{}, nil
}
// InitializeModuleServer is a simplified set of dependencies for the CLI,
// suitable for running background services and targeting dskit modules.
func InitializeModuleServer(cfg *setting.Cfg, opts Options, apiOpts api.ServerOptions) (*ModuleServer, error) {
wire.Build(wireExtsModuleServerSet)
return &ModuleServer{}, nil
}