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] diff --git a/cmd/builder/internal/builder/templates/main.go.tmpl b/cmd/builder/internal/builder/templates/main.go.tmpl index 6fee9501ef1..a7326513088 100644 --- a/cmd/builder/internal/builder/templates/main.go.tmpl +++ b/cmd/builder/internal/builder/templates/main.go.tmpl @@ -33,6 +33,10 @@ func main() { {{- range .ConfmapProviders}} {{.Name}}.NewFactory(), {{- end}} + }, ProviderModules: map[string]string{ + {{- range .ConfmapProviders}} + "{{.Name}}": "{{.GoMod}}", + {{- end}} }, {{- if .ConfmapConverters }} ConverterFactories: []confmap.ConverterFactory{ diff --git a/cmd/otelcorecol/main.go b/cmd/otelcorecol/main.go index 4317ca11925..aa91458670d 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 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", }, }, }, diff --git a/confmap/resolver.go b/confmap/resolver.go index e635ea99564..bb360702984 100644 --- a/confmap/resolver.go +++ b/confmap/resolver.go @@ -39,6 +39,9 @@ type ResolverSettings struct { // It is required to have at least one factory. ProviderFactories []ProviderFactory + // 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. // 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 7b3f8e1a8b7..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,6 +36,7 @@ type componentsOutput struct { Exporters []componentWithStability Connectors []componentWithStability Extensions []componentWithStability + Providers []componentWithOutStability } // newComponentsCommand constructs a new components command using the given CollectorSettings. @@ -109,6 +115,18 @@ 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.ConfigProviderSettings.ResolverSettings.ProviderModules[scheme+"provider"] + components.Providers = append(components.Providers, componentWithOutStability{ + Name: scheme, + Module: module, + }) + } + yamlData, err := yaml.Marshal(components) if err != nil { return err