mirror of https://github.com/grafana/grafana
Plugins: Move config factory to pluginsintegration package (#65716)
* move config to pluginsintegration package * change to all plugin toggle * fixes * fixes * fix lerna * fix testpull/66019/head
parent
c9288868f4
commit
bff9f4c890
@ -1,38 +1,17 @@ |
||||
package config |
||||
|
||||
import ( |
||||
"fmt" |
||||
|
||||
"github.com/grafana/grafana/pkg/infra/tracing" |
||||
"github.com/grafana/grafana/pkg/setting" |
||||
) |
||||
|
||||
const otlpExporter string = "otlp" |
||||
type Tracing struct { |
||||
OpenTelemetry OpenTelemetryCfg |
||||
} |
||||
|
||||
// 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 != "" |
||||
} |
||||
|
@ -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 |
||||
} |
@ -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 |
||||
} |
Loading…
Reference in new issue