From 7bb33f3d38ee5283dc09b651ae856d1a2d6c6b4b Mon Sep 17 00:00:00 2001 From: ChrsMark Date: Thu, 16 Jan 2025 10:30:07 +0200 Subject: [PATCH] use scheme directly in providerModules map keys Signed-off-by: ChrsMark --- cmd/builder/internal/builder/templates/main.go.tmpl | 2 +- cmd/otelcorecol/main.go | 10 +++++----- otelcol/collector.go | 2 +- otelcol/command_components.go | 10 +++------- otelcol/command_components_test.go | 4 ++-- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/cmd/builder/internal/builder/templates/main.go.tmpl b/cmd/builder/internal/builder/templates/main.go.tmpl index 41929554529..ff619f7d0fc 100644 --- a/cmd/builder/internal/builder/templates/main.go.tmpl +++ b/cmd/builder/internal/builder/templates/main.go.tmpl @@ -47,7 +47,7 @@ func main() { }, }, ProviderModules: map[string]string{ {{- range .ConfmapProviders}} - "{{.Name}}": "{{.GoMod}}", + {{.Name}}.NewFactory().Create(confmap.ProviderSettings{}).Scheme(): "{{.GoMod}}", {{- end}} }, } diff --git a/cmd/otelcorecol/main.go b/cmd/otelcorecol/main.go index f5fc4688dc3..3b2e9088a5c 100644 --- a/cmd/otelcorecol/main.go +++ b/cmd/otelcorecol/main.go @@ -37,11 +37,11 @@ func main() { }, }, }, ProviderModules: map[string]string{ - "envprovider": "go.opentelemetry.io/collector/confmap/provider/envprovider v1.22.0", - "fileprovider": "go.opentelemetry.io/collector/confmap/provider/fileprovider v1.22.0", - "httpprovider": "go.opentelemetry.io/collector/confmap/provider/httpprovider v1.22.0", - "httpsprovider": "go.opentelemetry.io/collector/confmap/provider/httpsprovider v1.22.0", - "yamlprovider": "go.opentelemetry.io/collector/confmap/provider/yamlprovider v1.22.0", + envprovider.NewFactory().Create(confmap.ProviderSettings{}).Scheme(): "go.opentelemetry.io/collector/confmap/provider/envprovider v1.22.0", + fileprovider.NewFactory().Create(confmap.ProviderSettings{}).Scheme(): "go.opentelemetry.io/collector/confmap/provider/fileprovider v1.22.0", + httpprovider.NewFactory().Create(confmap.ProviderSettings{}).Scheme(): "go.opentelemetry.io/collector/confmap/provider/httpprovider v1.22.0", + httpsprovider.NewFactory().Create(confmap.ProviderSettings{}).Scheme(): "go.opentelemetry.io/collector/confmap/provider/httpsprovider v1.22.0", + yamlprovider.NewFactory().Create(confmap.ProviderSettings{}).Scheme(): "go.opentelemetry.io/collector/confmap/provider/yamlprovider v1.22.0", }, } diff --git a/otelcol/collector.go b/otelcol/collector.go index aea4c8df6b1..cbad6f56e47 100644 --- a/otelcol/collector.go +++ b/otelcol/collector.go @@ -69,7 +69,7 @@ type CollectorSettings struct { // confmap.Providers watch for configuration changes. ConfigProviderSettings ConfigProviderSettings - // ProviderModules maps provider types to their respective go modules. + // ProviderModules maps provider schemes to their respective go modules. ProviderModules map[string]string // LoggingOptions provides a way to change behavior of zap logging. diff --git a/otelcol/command_components.go b/otelcol/command_components.go index fd6a041776e..c2a512e8e40 100644 --- a/otelcol/command_components.go +++ b/otelcol/command_components.go @@ -116,14 +116,10 @@ func newComponentsCommand(set CollectorSettings) *cobra.Command { } components.BuildInfo = set.BuildInfo - confmapProviderFactories := set.ConfigProviderSettings.ResolverSettings.ProviderFactories - for _, confmapProvider := range confmapProviderFactories { - provider := confmapProvider.Create(set.ConfigProviderSettings.ResolverSettings.ProviderSettings) - scheme := provider.Scheme() - module := set.ProviderModules[scheme+"provider"] + for providerScheme, providerModuleModule := range set.ProviderModules { components.Providers = append(components.Providers, componentWithoutStability{ - Name: scheme, - Module: module, + Name: providerScheme, + Module: providerModuleModule, }) } diff --git a/otelcol/command_components_test.go b/otelcol/command_components_test.go index 63f10fb202d..13269d5cccf 100644 --- a/otelcol/command_components_test.go +++ b/otelcol/command_components_test.go @@ -22,8 +22,8 @@ func TestNewBuildSubCommand(t *testing.T) { Factories: nopFactories, ConfigProviderSettings: newDefaultConfigProviderSettings(t, []string{filepath.Join("testdata", "otelcol-nop.yaml")}), ProviderModules: map[string]string{ - "envprovider": "go.opentelemetry.io/collector/confmap/provider/envprovider v1.2.3", - "fileprovider": "go.opentelemetry.io/collector/confmap/provider/fileprovider v1.2.3", + "env": "go.opentelemetry.io/collector/confmap/provider/envprovider v1.2.3", + "file": "go.opentelemetry.io/collector/confmap/provider/fileprovider v1.2.3", }, } cmd := NewCommand(set)