From 308be2eec0426d12461cb559c23cdd27c4f46d67 Mon Sep 17 00:00:00 2001 From: ChrsMark Date: Mon, 16 Dec 2024 11:43:22 +0200 Subject: [PATCH 1/7] Add support for providers Signed-off-by: ChrsMark --- otelcol/command_components.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/otelcol/command_components.go b/otelcol/command_components.go index 7b3f8e1a8b7..9243aeec576 100644 --- a/otelcol/command_components.go +++ b/otelcol/command_components.go @@ -31,6 +31,7 @@ type componentsOutput struct { Exporters []componentWithStability Connectors []componentWithStability Extensions []componentWithStability + Providers []string } // newComponentsCommand constructs a new components command using the given CollectorSettings. @@ -109,6 +110,14 @@ 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() + components.Providers = append(components.Providers, scheme) + } + yamlData, err := yaml.Marshal(components) if err != nil { return err From f344f700d61fccddefa4401211c49f15e5fb041e Mon Sep 17 00:00:00 2001 From: ChrsMark Date: Mon, 16 Dec 2024 11:43:40 +0200 Subject: [PATCH 2/7] Add support for listing providers' modules Signed-off-by: ChrsMark --- cmd/builder/internal/builder/templates/main.go.tmpl | 6 +++++- cmd/otelcorecol/main.go | 6 ++++++ confmap/resolver.go | 4 ++++ otelcol/command_components.go | 13 +++++++++++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/cmd/builder/internal/builder/templates/main.go.tmpl b/cmd/builder/internal/builder/templates/main.go.tmpl index 6fee9501ef1..3f828519317 100644 --- a/cmd/builder/internal/builder/templates/main.go.tmpl +++ b/cmd/builder/internal/builder/templates/main.go.tmpl @@ -33,7 +33,11 @@ func main() { {{- range .ConfmapProviders}} {{.Name}}.NewFactory(), {{- end}} - }, + }, ProviderModules: map[string]string{ + {{- range .ConfmapProviders}} + "{{.Name}}": "{{.GoMod}}", + {{- end}} + }, {{- if .ConfmapConverters }} ConverterFactories: []confmap.ConverterFactory{ {{- range .ConfmapConverters}} diff --git a/cmd/otelcorecol/main.go b/cmd/otelcorecol/main.go index 1014d3f2879..c1fe363c30f 100644 --- a/cmd/otelcorecol/main.go +++ b/cmd/otelcorecol/main.go @@ -34,6 +34,12 @@ func main() { httpprovider.NewFactory(), httpsprovider.NewFactory(), yamlprovider.NewFactory(), + }, ProviderModules: map[string]string{ + "envprovider": "go.opentelemetry.io/collector/confmap/provider/envprovider v0.115.0", + "fileprovider": "go.opentelemetry.io/collector/confmap/provider/fileprovider v0.115.0", + "httpprovider": "go.opentelemetry.io/collector/confmap/provider/httpprovider v0.115.0", + "httpsprovider": "go.opentelemetry.io/collector/confmap/provider/httpsprovider v0.115.0", + "yamlprovider": "go.opentelemetry.io/collector/confmap/provider/yamlprovider v0.115.0", }, }, }, diff --git a/confmap/resolver.go b/confmap/resolver.go index e635ea99564..6702874ea24 100644 --- a/confmap/resolver.go +++ b/confmap/resolver.go @@ -39,6 +39,10 @@ type ResolverSettings struct { // It is required to have at least one factory. ProviderFactories []ProviderFactory + // ProviderFactories is a slice of Provider factories. + // It is required to have at least one factory. + ProviderModules map[string]string + // DefaultScheme is the scheme that is used if ${} syntax is used but no schema is provided. // If no DefaultScheme is set, ${} with no schema will not be expanded. // It is strongly recommended to set "env" as the default scheme to align with the diff --git a/otelcol/command_components.go b/otelcol/command_components.go index 9243aeec576..f99fca3ff03 100644 --- a/otelcol/command_components.go +++ b/otelcol/command_components.go @@ -24,6 +24,11 @@ type componentWithStability struct { Stability map[string]string } +type componentWithOutStability struct { + Name string + Module string +} + type componentsOutput struct { BuildInfo component.BuildInfo Receivers []componentWithStability @@ -31,7 +36,7 @@ type componentsOutput struct { Exporters []componentWithStability Connectors []componentWithStability Extensions []componentWithStability - Providers []string + Providers []componentWithOutStability } // newComponentsCommand constructs a new components command using the given CollectorSettings. @@ -115,7 +120,11 @@ func newComponentsCommand(set CollectorSettings) *cobra.Command { for _, confmapProvider := range confmapProviderFactories { provider := confmapProvider.Create(set.ConfigProviderSettings.ResolverSettings.ProviderSettings) scheme := provider.Scheme() - components.Providers = append(components.Providers, scheme) + module := set.ConfigProviderSettings.ResolverSettings.ProviderModules[scheme+"provider"] + components.Providers = append(components.Providers, componentWithOutStability{ + Name: scheme, + Module: module, + }) } yamlData, err := yaml.Marshal(components) From 26a1cc1c648c0009ee1d6e3368c5dd7dd584020c Mon Sep 17 00:00:00 2001 From: ChrsMark Date: Mon, 16 Dec 2024 13:11:36 +0200 Subject: [PATCH 3/7] add changelog Signed-off-by: ChrsMark --- .chloggen/components_cmd_add_providers.yaml | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .chloggen/components_cmd_add_providers.yaml diff --git a/.chloggen/components_cmd_add_providers.yaml b/.chloggen/components_cmd_add_providers.yaml new file mode 100644 index 00000000000..8b05ab8f835 --- /dev/null +++ b/.chloggen/components_cmd_add_providers.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: otelcol + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Adds support for listing config providers in components command's output + +# One or more tracking issues or pull requests related to the change +issues: [11570] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] From 9fb6f080a11c417f07da4a5f3b321f4c574a7790 Mon Sep 17 00:00:00 2001 From: ChrsMark Date: Mon, 16 Dec 2024 13:14:25 +0200 Subject: [PATCH 4/7] fix docstring Signed-off-by: ChrsMark --- confmap/resolver.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/confmap/resolver.go b/confmap/resolver.go index 6702874ea24..bb360702984 100644 --- a/confmap/resolver.go +++ b/confmap/resolver.go @@ -39,8 +39,7 @@ type ResolverSettings struct { // It is required to have at least one factory. ProviderFactories []ProviderFactory - // ProviderFactories is a slice of Provider factories. - // It is required to have at least one factory. + // ProviderModules maps provider types to their respective go modules. ProviderModules map[string]string // DefaultScheme is the scheme that is used if ${} syntax is used but no schema is provided. From 41bdf4c206dbf8431cff816ba8cf862f6a1a0e9b Mon Sep 17 00:00:00 2001 From: ChrsMark Date: Mon, 16 Dec 2024 13:18:34 +0200 Subject: [PATCH 5/7] fix versions Signed-off-by: ChrsMark --- cmd/otelcorecol/main.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/otelcorecol/main.go b/cmd/otelcorecol/main.go index c1fe363c30f..339de2e189c 100644 --- a/cmd/otelcorecol/main.go +++ b/cmd/otelcorecol/main.go @@ -35,11 +35,11 @@ func main() { httpsprovider.NewFactory(), yamlprovider.NewFactory(), }, ProviderModules: map[string]string{ - "envprovider": "go.opentelemetry.io/collector/confmap/provider/envprovider v0.115.0", - "fileprovider": "go.opentelemetry.io/collector/confmap/provider/fileprovider v0.115.0", - "httpprovider": "go.opentelemetry.io/collector/confmap/provider/httpprovider v0.115.0", - "httpsprovider": "go.opentelemetry.io/collector/confmap/provider/httpsprovider v0.115.0", - "yamlprovider": "go.opentelemetry.io/collector/confmap/provider/yamlprovider v0.115.0", + "envprovider": "go.opentelemetry.io/collector/confmap/provider/envprovider v1.21.0", + "fileprovider": "go.opentelemetry.io/collector/confmap/provider/fileprovider v1.21.0", + "httpprovider": "go.opentelemetry.io/collector/confmap/provider/httpprovider v1.21.0", + "httpsprovider": "go.opentelemetry.io/collector/confmap/provider/httpsprovider v1.21.0", + "yamlprovider": "go.opentelemetry.io/collector/confmap/provider/yamlprovider v1.21.0", }, }, }, From 3411dd83cb7a9d4919b08b75af6f099bca2b9bb6 Mon Sep 17 00:00:00 2001 From: ChrsMark Date: Mon, 16 Dec 2024 13:27:43 +0200 Subject: [PATCH 6/7] re generate Signed-off-by: ChrsMark --- cmd/otelcorecol/main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/otelcorecol/main.go b/cmd/otelcorecol/main.go index 339de2e189c..25d510beb43 100644 --- a/cmd/otelcorecol/main.go +++ b/cmd/otelcorecol/main.go @@ -35,11 +35,11 @@ func main() { httpsprovider.NewFactory(), yamlprovider.NewFactory(), }, ProviderModules: map[string]string{ - "envprovider": "go.opentelemetry.io/collector/confmap/provider/envprovider v1.21.0", - "fileprovider": "go.opentelemetry.io/collector/confmap/provider/fileprovider v1.21.0", - "httpprovider": "go.opentelemetry.io/collector/confmap/provider/httpprovider v1.21.0", + "envprovider": "go.opentelemetry.io/collector/confmap/provider/envprovider v1.21.0", + "fileprovider": "go.opentelemetry.io/collector/confmap/provider/fileprovider v1.21.0", + "httpprovider": "go.opentelemetry.io/collector/confmap/provider/httpprovider v1.21.0", "httpsprovider": "go.opentelemetry.io/collector/confmap/provider/httpsprovider v1.21.0", - "yamlprovider": "go.opentelemetry.io/collector/confmap/provider/yamlprovider v1.21.0", + "yamlprovider": "go.opentelemetry.io/collector/confmap/provider/yamlprovider v1.21.0", }, }, }, From e93a333668bd932edd71c0d14857e902687fe5ac Mon Sep 17 00:00:00 2001 From: Christos Markou Date: Mon, 16 Dec 2024 20:02:12 +0200 Subject: [PATCH 7/7] Update cmd/builder/internal/builder/templates/main.go.tmpl Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com> --- cmd/builder/internal/builder/templates/main.go.tmpl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/builder/internal/builder/templates/main.go.tmpl b/cmd/builder/internal/builder/templates/main.go.tmpl index 3f828519317..a7326513088 100644 --- a/cmd/builder/internal/builder/templates/main.go.tmpl +++ b/cmd/builder/internal/builder/templates/main.go.tmpl @@ -34,10 +34,10 @@ func main() { {{.Name}}.NewFactory(), {{- end}} }, ProviderModules: map[string]string{ - {{- range .ConfmapProviders}} - "{{.Name}}": "{{.GoMod}}", - {{- end}} - }, + {{- range .ConfmapProviders}} + "{{.Name}}": "{{.GoMod}}", + {{- end}} + }, {{- if .ConfmapConverters }} ConverterFactories: []confmap.ConverterFactory{ {{- range .ConfmapConverters}}