mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugins: Move config factory to pluginsintegration package (#65716)
* move config to pluginsintegration package * change to all plugin toggle * fixes * fixes * fix lerna * fix test
This commit is contained in:
@@ -18,7 +18,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/coreplugin"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/provider"
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
pluginClient "github.com/grafana/grafana/pkg/plugins/manager/client"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/fakes"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/loader"
|
||||
@@ -34,6 +33,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/oauthtoken/oauthtokentest"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/config"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginaccesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext"
|
||||
pluginSettings "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginsettings/service"
|
||||
@@ -59,8 +59,7 @@ func TestCallResource(t *testing.T) {
|
||||
|
||||
coreRegistry := coreplugin.ProvideCoreRegistry(nil, &cloudwatch.CloudWatchService{}, nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, testdatasource.ProvideService(cfg, featuremgmt.WithFeatures()), nil, nil, nil, nil, nil, nil)
|
||||
var pCfg *config.Cfg
|
||||
pCfg, err = config.ProvideConfig(setting.ProvideProvider(cfg), cfg)
|
||||
pCfg, err := config.ProvideConfig(setting.ProvideProvider(cfg), cfg)
|
||||
require.NoError(t, err)
|
||||
reg := registry.ProvideService()
|
||||
l := loader.ProvideService(pCfg, fakes.NewFakeLicensingService(), signature.NewUnsignedAuthorizer(pCfg),
|
||||
|
||||
@@ -105,6 +105,10 @@ func (ots *Opentelemetry) parseSettingsOpentelemetry() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ots *Opentelemetry) OTelExporterEnabled() bool {
|
||||
return ots.Enabled == otlpExporter
|
||||
}
|
||||
|
||||
func splitCustomAttribs(s string) ([]attribute.KeyValue, error) {
|
||||
res := []attribute.KeyValue{}
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana-azure-sdk-go/azsettings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins/log"
|
||||
@@ -33,63 +30,24 @@ type Cfg struct {
|
||||
|
||||
PluginsCDNURLTemplate string
|
||||
|
||||
Opentelemetry OpentelemetryCfg
|
||||
Tracing Tracing
|
||||
}
|
||||
|
||||
func ProvideConfig(settingProvider setting.Provider, grafanaCfg *setting.Cfg) (*Cfg, error) {
|
||||
return NewCfg(settingProvider, grafanaCfg)
|
||||
}
|
||||
|
||||
func NewCfg(settingProvider setting.Provider, grafanaCfg *setting.Cfg) (*Cfg, error) {
|
||||
logger := log.New("plugin.cfg")
|
||||
|
||||
aws := settingProvider.Section("aws")
|
||||
plugins := settingProvider.Section("plugins")
|
||||
|
||||
allowedUnsigned := grafanaCfg.PluginsAllowUnsigned
|
||||
if len(plugins.KeyValue("allow_loading_unsigned_plugins").Value()) > 0 {
|
||||
allowedUnsigned = strings.Split(plugins.KeyValue("allow_loading_unsigned_plugins").Value(), ",")
|
||||
}
|
||||
|
||||
allowedAuth := grafanaCfg.AWSAllowedAuthProviders
|
||||
if len(aws.KeyValue("allowed_auth_providers").Value()) > 0 {
|
||||
allowedUnsigned = strings.Split(settingProvider.KeyValue("plugins", "allow_loading_unsigned_plugins").Value(), ",")
|
||||
}
|
||||
|
||||
otelCfg, err := NewOpentelemetryCfg(grafanaCfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("new opentelemetry cfg: %w", err)
|
||||
}
|
||||
func NewCfg(devMode bool, pluginsPath string, pluginSettings setting.PluginSettings, pluginsAllowUnsigned []string,
|
||||
awsAllowedAuthProviders []string, awsAssumeRoleEnabled bool, azure *azsettings.AzureSettings, grafanaVersion string,
|
||||
logDatasourceRequests bool, pluginsCDNURLTemplate string, tracing Tracing) *Cfg {
|
||||
return &Cfg{
|
||||
log: logger,
|
||||
PluginsPath: grafanaCfg.PluginsPath,
|
||||
BuildVersion: grafanaCfg.BuildVersion,
|
||||
DevMode: settingProvider.KeyValue("", "app_mode").MustBool(grafanaCfg.Env == setting.Dev),
|
||||
PluginSettings: extractPluginSettings(settingProvider),
|
||||
PluginsAllowUnsigned: allowedUnsigned,
|
||||
AWSAllowedAuthProviders: allowedAuth,
|
||||
AWSAssumeRoleEnabled: aws.KeyValue("assume_role_enabled").MustBool(grafanaCfg.AWSAssumeRoleEnabled),
|
||||
Azure: grafanaCfg.Azure,
|
||||
LogDatasourceRequests: grafanaCfg.PluginLogBackendRequests,
|
||||
PluginsCDNURLTemplate: grafanaCfg.PluginsCDNURLTemplate,
|
||||
Opentelemetry: otelCfg,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func extractPluginSettings(settingProvider setting.Provider) setting.PluginSettings {
|
||||
ps := setting.PluginSettings{}
|
||||
for sectionName, sectionCopy := range settingProvider.Current() {
|
||||
if !strings.HasPrefix(sectionName, "plugin.") {
|
||||
continue
|
||||
}
|
||||
// Calling Current() returns a redacted version of section. We need to replace the map values with the unredacted values.
|
||||
section := settingProvider.Section(sectionName)
|
||||
for k := range sectionCopy {
|
||||
sectionCopy[k] = section.KeyValue(k).MustString("")
|
||||
}
|
||||
pluginID := strings.Replace(sectionName, "plugin.", "", 1)
|
||||
ps[pluginID] = sectionCopy
|
||||
log: log.New("plugin.cfg"),
|
||||
PluginsPath: pluginsPath,
|
||||
BuildVersion: grafanaVersion,
|
||||
DevMode: devMode,
|
||||
PluginSettings: pluginSettings,
|
||||
PluginsAllowUnsigned: pluginsAllowUnsigned,
|
||||
AWSAllowedAuthProviders: awsAllowedAuthProviders,
|
||||
AWSAssumeRoleEnabled: awsAssumeRoleEnabled,
|
||||
Azure: azure,
|
||||
LogDatasourceRequests: logDatasourceRequests,
|
||||
PluginsCDNURLTemplate: pluginsCDNURLTemplate,
|
||||
Tracing: tracing,
|
||||
}
|
||||
|
||||
return ps
|
||||
}
|
||||
|
||||
@@ -1,38 +1,17 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
type Tracing struct {
|
||||
OpenTelemetry OpenTelemetryCfg
|
||||
}
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
const otlpExporter string = "otlp"
|
||||
|
||||
// OpentelemetryCfg contains the Opentelemetry address and propagation config values.
|
||||
// This is used to export the Opentelemetry (OTLP) config without exposing the whole *setting.Cfg.
|
||||
type OpentelemetryCfg struct {
|
||||
// OpenTelemetryCfg contains the OpenTelemetry address and propagation config values.
|
||||
// This is used to export the OpenTelemetry (OTLP) config without exposing the whole *setting.Cfg.
|
||||
type OpenTelemetryCfg struct {
|
||||
Address string
|
||||
Propagation string
|
||||
}
|
||||
|
||||
// IsEnabled returns true if OTLP tracing is enabled (address set)
|
||||
func (c OpentelemetryCfg) IsEnabled() bool {
|
||||
return c.Address != ""
|
||||
}
|
||||
|
||||
// NewOpentelemetryCfg creates a new OpentelemetryCfg based on the provided Grafana config.
|
||||
// If Opentelemetry (OTLP) is disabled, a zero-value OpentelemetryCfg is returned.
|
||||
func NewOpentelemetryCfg(grafanaCfg *setting.Cfg) (OpentelemetryCfg, error) {
|
||||
ots, err := tracing.ParseSettingsOpentelemetry(grafanaCfg)
|
||||
if err != nil {
|
||||
return OpentelemetryCfg{}, fmt.Errorf("parse settings: %w", err)
|
||||
}
|
||||
if ots.Enabled != otlpExporter {
|
||||
return OpentelemetryCfg{}, nil
|
||||
}
|
||||
return OpentelemetryCfg{
|
||||
Address: ots.Address,
|
||||
Propagation: ots.Propagation,
|
||||
}, nil
|
||||
func (t Tracing) IsEnabled() bool {
|
||||
return t.OpenTelemetry.Address != ""
|
||||
}
|
||||
|
||||
@@ -70,14 +70,14 @@ func (i *Initializer) envVars(plugin *plugins.Plugin) []string {
|
||||
if v, exists := i.cfg.PluginSettings[plugin.ID]["tracing"]; exists {
|
||||
pluginTracingEnabled = v == "true"
|
||||
}
|
||||
if i.cfg.Opentelemetry.IsEnabled() && pluginTracingEnabled {
|
||||
if i.cfg.Tracing.IsEnabled() && pluginTracingEnabled {
|
||||
if plugin.Info.Version != "" {
|
||||
hostEnv = append(hostEnv, fmt.Sprintf("GF_PLUGIN_VERSION=%s", plugin.Info.Version))
|
||||
}
|
||||
hostEnv = append(
|
||||
hostEnv,
|
||||
fmt.Sprintf("GF_INSTANCE_OTLP_ADDRESS=%s", i.cfg.Opentelemetry.Address),
|
||||
fmt.Sprintf("GF_INSTANCE_OTLP_PROPAGATION=%s", i.cfg.Opentelemetry.Propagation),
|
||||
fmt.Sprintf("GF_INSTANCE_OTLP_ADDRESS=%s", i.cfg.Tracing.OpenTelemetry.Address),
|
||||
fmt.Sprintf("GF_INSTANCE_OTLP_PROPAGATION=%s", i.cfg.Tracing.OpenTelemetry.Propagation),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ func TestInitializer_tracingEnvironmentVariables(t *testing.T) {
|
||||
JSONData: plugins.JSONData{ID: pluginID},
|
||||
}
|
||||
|
||||
defaultOtelCfg := config.OpentelemetryCfg{
|
||||
defaultOTelCfg := config.OpenTelemetryCfg{
|
||||
Address: "127.0.0.1:4317",
|
||||
Propagation: "",
|
||||
}
|
||||
@@ -250,7 +250,7 @@ func TestInitializer_tracingEnvironmentVariables(t *testing.T) {
|
||||
{
|
||||
name: "otel not configured",
|
||||
cfg: &config.Cfg{
|
||||
Opentelemetry: config.OpentelemetryCfg{},
|
||||
Tracing: config.Tracing{},
|
||||
},
|
||||
plugin: defaultPlugin,
|
||||
exp: expNoTracing,
|
||||
@@ -258,7 +258,7 @@ func TestInitializer_tracingEnvironmentVariables(t *testing.T) {
|
||||
{
|
||||
name: "otel not configured but plugin-tracing enabled",
|
||||
cfg: &config.Cfg{
|
||||
Opentelemetry: config.OpentelemetryCfg{},
|
||||
Tracing: config.Tracing{},
|
||||
PluginSettings: map[string]map[string]string{pluginID: {"tracing": "true"}},
|
||||
},
|
||||
plugin: defaultPlugin,
|
||||
@@ -267,7 +267,9 @@ func TestInitializer_tracingEnvironmentVariables(t *testing.T) {
|
||||
{
|
||||
name: "otlp no propagation plugin enabled",
|
||||
cfg: &config.Cfg{
|
||||
Opentelemetry: defaultOtelCfg,
|
||||
Tracing: config.Tracing{
|
||||
OpenTelemetry: defaultOTelCfg,
|
||||
},
|
||||
PluginSettings: map[string]map[string]string{
|
||||
pluginID: {"tracing": "true"},
|
||||
},
|
||||
@@ -278,7 +280,9 @@ func TestInitializer_tracingEnvironmentVariables(t *testing.T) {
|
||||
{
|
||||
name: "otlp no propagation disabled by default",
|
||||
cfg: &config.Cfg{
|
||||
Opentelemetry: defaultOtelCfg,
|
||||
Tracing: config.Tracing{
|
||||
OpenTelemetry: defaultOTelCfg,
|
||||
},
|
||||
},
|
||||
plugin: defaultPlugin,
|
||||
exp: expNoTracing,
|
||||
@@ -286,9 +290,11 @@ func TestInitializer_tracingEnvironmentVariables(t *testing.T) {
|
||||
{
|
||||
name: "otlp propagation plugin enabled",
|
||||
cfg: &config.Cfg{
|
||||
Opentelemetry: config.OpentelemetryCfg{
|
||||
Address: "127.0.0.1:4317",
|
||||
Propagation: "w3c",
|
||||
Tracing: config.Tracing{
|
||||
OpenTelemetry: config.OpenTelemetryCfg{
|
||||
Address: "127.0.0.1:4317",
|
||||
Propagation: "w3c",
|
||||
},
|
||||
},
|
||||
PluginSettings: map[string]map[string]string{
|
||||
pluginID: {"tracing": "true"},
|
||||
@@ -307,9 +313,11 @@ func TestInitializer_tracingEnvironmentVariables(t *testing.T) {
|
||||
{
|
||||
name: "otlp enabled composite propagation",
|
||||
cfg: &config.Cfg{
|
||||
Opentelemetry: config.OpentelemetryCfg{
|
||||
Address: "127.0.0.1:4317",
|
||||
Propagation: "w3c,jaeger",
|
||||
Tracing: config.Tracing{
|
||||
OpenTelemetry: config.OpenTelemetryCfg{
|
||||
Address: "127.0.0.1:4317",
|
||||
Propagation: "w3c,jaeger",
|
||||
},
|
||||
},
|
||||
PluginSettings: map[string]map[string]string{
|
||||
pluginID: {"tracing": "true"},
|
||||
@@ -328,9 +336,11 @@ func TestInitializer_tracingEnvironmentVariables(t *testing.T) {
|
||||
{
|
||||
name: "otlp no propagation disabled by default",
|
||||
cfg: &config.Cfg{
|
||||
Opentelemetry: config.OpentelemetryCfg{
|
||||
Address: "127.0.0.1:4317",
|
||||
Propagation: "w3c",
|
||||
Tracing: config.Tracing{
|
||||
OpenTelemetry: config.OpenTelemetryCfg{
|
||||
Address: "127.0.0.1:4317",
|
||||
Propagation: "w3c",
|
||||
},
|
||||
},
|
||||
},
|
||||
plugin: defaultPlugin,
|
||||
@@ -339,7 +349,9 @@ func TestInitializer_tracingEnvironmentVariables(t *testing.T) {
|
||||
{
|
||||
name: "disabled on plugin",
|
||||
cfg: &config.Cfg{
|
||||
Opentelemetry: defaultOtelCfg,
|
||||
Tracing: config.Tracing{
|
||||
OpenTelemetry: defaultOTelCfg,
|
||||
},
|
||||
PluginSettings: setting.PluginSettings{
|
||||
pluginID: map[string]string{"tracing": "false"},
|
||||
},
|
||||
@@ -350,7 +362,9 @@ func TestInitializer_tracingEnvironmentVariables(t *testing.T) {
|
||||
{
|
||||
name: "disabled on plugin with other plugin settings",
|
||||
cfg: &config.Cfg{
|
||||
Opentelemetry: defaultOtelCfg,
|
||||
Tracing: config.Tracing{
|
||||
OpenTelemetry: defaultOTelCfg,
|
||||
},
|
||||
PluginSettings: map[string]map[string]string{
|
||||
pluginID: {"some_other_option": "true"},
|
||||
},
|
||||
@@ -361,7 +375,9 @@ func TestInitializer_tracingEnvironmentVariables(t *testing.T) {
|
||||
{
|
||||
name: "enabled on plugin with other plugin settings",
|
||||
cfg: &config.Cfg{
|
||||
Opentelemetry: defaultOtelCfg,
|
||||
Tracing: config.Tracing{
|
||||
OpenTelemetry: defaultOTelCfg,
|
||||
},
|
||||
PluginSettings: map[string]map[string]string{
|
||||
pluginID: {"some_other_option": "true", "tracing": "true"},
|
||||
},
|
||||
@@ -372,7 +388,9 @@ func TestInitializer_tracingEnvironmentVariables(t *testing.T) {
|
||||
{
|
||||
name: "GF_PLUGIN_VERSION is not present if tracing is disabled",
|
||||
cfg: &config.Cfg{
|
||||
Opentelemetry: config.OpentelemetryCfg{}, // no OTEL config
|
||||
Tracing: config.Tracing{
|
||||
OpenTelemetry: config.OpenTelemetryCfg{},
|
||||
},
|
||||
PluginSettings: map[string]map[string]string{pluginID: {"tracing": "true"}},
|
||||
},
|
||||
plugin: defaultPlugin,
|
||||
@@ -381,7 +399,9 @@ func TestInitializer_tracingEnvironmentVariables(t *testing.T) {
|
||||
{
|
||||
name: "GF_PLUGIN_VERSION is present if tracing is enabled and plugin has version",
|
||||
cfg: &config.Cfg{
|
||||
Opentelemetry: defaultOtelCfg,
|
||||
Tracing: config.Tracing{
|
||||
OpenTelemetry: defaultOTelCfg,
|
||||
},
|
||||
PluginSettings: map[string]map[string]string{pluginID: {"tracing": "true"}},
|
||||
},
|
||||
plugin: defaultPlugin,
|
||||
@@ -390,7 +410,9 @@ func TestInitializer_tracingEnvironmentVariables(t *testing.T) {
|
||||
{
|
||||
name: "GF_PLUGIN_VERSION is not present if tracing is enabled but plugin doesn't have a version",
|
||||
cfg: &config.Cfg{
|
||||
Opentelemetry: config.OpentelemetryCfg{},
|
||||
Tracing: config.Tracing{
|
||||
OpenTelemetry: config.OpenTelemetryCfg{},
|
||||
},
|
||||
PluginSettings: map[string]map[string]string{pluginID: {"tracing": "true"}},
|
||||
},
|
||||
plugin: pluginWithoutVersion,
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/coreplugin"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/provider"
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/client"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/fakes"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/loader"
|
||||
@@ -31,6 +30,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins/pluginscdn"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/licensing"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/config"
|
||||
plicensing "github.com/grafana/grafana/pkg/services/pluginsintegration/licensing"
|
||||
"github.com/grafana/grafana/pkg/services/searchV2"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
|
||||
59
pkg/services/pluginsintegration/config/config.go
Normal file
59
pkg/services/pluginsintegration/config/config.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
pCfg "github.com/grafana/grafana/pkg/plugins/config"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
func ProvideConfig(settingProvider setting.Provider, grafanaCfg *setting.Cfg) (*pCfg.Cfg, error) {
|
||||
plugins := settingProvider.Section("plugins")
|
||||
allowedUnsigned := grafanaCfg.PluginsAllowUnsigned
|
||||
if len(plugins.KeyValue("allow_loading_unsigned_plugins").Value()) > 0 {
|
||||
allowedUnsigned = strings.Split(plugins.KeyValue("allow_loading_unsigned_plugins").Value(), ",")
|
||||
}
|
||||
|
||||
aws := settingProvider.Section("aws")
|
||||
allowedAuth := grafanaCfg.AWSAllowedAuthProviders
|
||||
if len(aws.KeyValue("allowed_auth_providers").Value()) > 0 {
|
||||
allowedUnsigned = strings.Split(settingProvider.KeyValue("plugins", "allow_loading_unsigned_plugins").Value(), ",")
|
||||
}
|
||||
|
||||
tracingCfg, err := newTracingCfg(grafanaCfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("new opentelemetry cfg: %w", err)
|
||||
}
|
||||
return pCfg.NewCfg(
|
||||
settingProvider.KeyValue("", "app_mode").MustBool(grafanaCfg.Env == setting.Dev),
|
||||
grafanaCfg.PluginsPath,
|
||||
extractPluginSettings(settingProvider),
|
||||
allowedUnsigned,
|
||||
allowedAuth,
|
||||
aws.KeyValue("assume_role_enabled").MustBool(grafanaCfg.AWSAssumeRoleEnabled),
|
||||
grafanaCfg.Azure,
|
||||
grafanaCfg.BuildVersion,
|
||||
grafanaCfg.PluginLogBackendRequests,
|
||||
grafanaCfg.PluginsCDNURLTemplate,
|
||||
tracingCfg,
|
||||
), nil
|
||||
}
|
||||
|
||||
func extractPluginSettings(settingProvider setting.Provider) setting.PluginSettings {
|
||||
ps := setting.PluginSettings{}
|
||||
for sectionName, sectionCopy := range settingProvider.Current() {
|
||||
if !strings.HasPrefix(sectionName, "plugin.") {
|
||||
continue
|
||||
}
|
||||
// Calling Current() returns a redacted version of section. We need to replace the map values with the unredacted values.
|
||||
section := settingProvider.Section(sectionName)
|
||||
for k := range sectionCopy {
|
||||
sectionCopy[k] = section.KeyValue(k).MustString("")
|
||||
}
|
||||
pluginID := strings.Replace(sectionName, "plugin.", "", 1)
|
||||
ps[pluginID] = sectionCopy
|
||||
}
|
||||
|
||||
return ps
|
||||
}
|
||||
27
pkg/services/pluginsintegration/config/tracing.go
Normal file
27
pkg/services/pluginsintegration/config/tracing.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
pCfg "github.com/grafana/grafana/pkg/plugins/config"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
// newTracingCfg creates a plugins tracing configuration based on the provided Grafana tracing config.
|
||||
// If OpenTelemetry (OTLP) is disabled, a zero-value OpenTelemetryCfg is returned.
|
||||
func newTracingCfg(grafanaCfg *setting.Cfg) (pCfg.Tracing, error) {
|
||||
ots, err := tracing.ParseSettingsOpentelemetry(grafanaCfg)
|
||||
if err != nil {
|
||||
return pCfg.Tracing{}, fmt.Errorf("parse settings: %w", err)
|
||||
}
|
||||
if !ots.OTelExporterEnabled() {
|
||||
return pCfg.Tracing{}, nil
|
||||
}
|
||||
return pCfg.Tracing{
|
||||
OpenTelemetry: pCfg.OpenTelemetryCfg{
|
||||
Address: ots.Address,
|
||||
Propagation: ots.Propagation,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -8,15 +8,15 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNewOpentelemetryCfg(t *testing.T) {
|
||||
func TestNewTracingCfg(t *testing.T) {
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
cfg := setting.NewCfg()
|
||||
|
||||
otelCfg, err := NewOpentelemetryCfg(cfg)
|
||||
tracingCfg, err := newTracingCfg(cfg)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, otelCfg.IsEnabled(), "otel should be disabled")
|
||||
assert.Empty(t, otelCfg.Address)
|
||||
assert.Empty(t, otelCfg.Propagation)
|
||||
assert.False(t, tracingCfg.IsEnabled(), "tracing should be disabled")
|
||||
assert.Empty(t, tracingCfg.OpenTelemetry.Address)
|
||||
assert.Empty(t, tracingCfg.OpenTelemetry.Propagation)
|
||||
})
|
||||
|
||||
t.Run("enabled", func(t *testing.T) {
|
||||
@@ -39,11 +39,11 @@ func TestNewOpentelemetryCfg(t *testing.T) {
|
||||
otlpSect.Key("propagation").SetValue(tc.propagation)
|
||||
}
|
||||
|
||||
otelCfg, err := NewOpentelemetryCfg(cfg)
|
||||
tracingCfg, err := newTracingCfg(cfg)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, otelCfg.IsEnabled(), "otel should be enabled")
|
||||
assert.Equal(t, address, otelCfg.Address)
|
||||
assert.Equal(t, tc.propagation, otelCfg.Propagation)
|
||||
assert.True(t, tracingCfg.IsEnabled(), "tracing should be enabled")
|
||||
assert.Equal(t, address, tracingCfg.OpenTelemetry.Address)
|
||||
assert.Equal(t, tc.propagation, tracingCfg.OpenTelemetry.Propagation)
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/coreplugin"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin/provider"
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
pCfg "github.com/grafana/grafana/pkg/plugins/config"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/client"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/filestore"
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins/repo"
|
||||
"github.com/grafana/grafana/pkg/services/oauthtoken"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/clientmiddleware"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/config"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/licensing"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginsettings"
|
||||
@@ -76,14 +77,14 @@ var WireExtensionSet = wire.NewSet(
|
||||
finder.NewLocalFinder,
|
||||
)
|
||||
|
||||
func ProvideClientDecorator(cfg *setting.Cfg, pCfg *config.Cfg,
|
||||
func ProvideClientDecorator(cfg *setting.Cfg, pCfg *pCfg.Cfg,
|
||||
pluginRegistry registry.Service,
|
||||
oAuthTokenService oauthtoken.OAuthTokenService,
|
||||
tracer tracing.Tracer) (*client.Decorator, error) {
|
||||
return NewClientDecorator(cfg, pCfg, pluginRegistry, oAuthTokenService, tracer)
|
||||
}
|
||||
|
||||
func NewClientDecorator(cfg *setting.Cfg, pCfg *config.Cfg,
|
||||
func NewClientDecorator(cfg *setting.Cfg, pCfg *pCfg.Cfg,
|
||||
pluginRegistry registry.Service,
|
||||
oAuthTokenService oauthtoken.OAuthTokenService,
|
||||
tracer tracing.Tracer) (*client.Decorator, error) {
|
||||
|
||||
Reference in New Issue
Block a user