Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for providers in components command #11900

Merged
merged 12 commits into from
Jan 22, 2025
25 changes: 25 additions & 0 deletions .chloggen/components_cmd_add_providers.yaml
Original file line number Diff line number Diff line change
@@ -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]
6 changes: 5 additions & 1 deletion cmd/builder/internal/builder/templates/main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ func main() {
DefaultScheme: "{{ .ConfResolver.DefaultURIScheme }}",
{{- end }}
},
},
}, ProviderModules: map[string]string{
{{- range .ConfmapProviders}}
{{.Name}}.NewFactory().Create(confmap.ProviderSettings{}).Scheme(): "{{.GoMod}}",
{{- end}}
},
}

if err := run(set); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions cmd/otelcorecol/main.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions otelcol/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ type CollectorSettings struct {
// confmap.Providers watch for configuration changes.
ConfigProviderSettings ConfigProviderSettings

// ProviderModules maps provider schemes to their respective go modules.
ProviderModules map[string]string

// LoggingOptions provides a way to change behavior of zap logging.
LoggingOptions []zap.Option

Expand Down
14 changes: 14 additions & 0 deletions otelcol/command_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ type componentWithStability struct {
Stability map[string]string
}

type componentWithoutStability struct {
Scheme string
Module string
}

type componentsOutput struct {
BuildInfo component.BuildInfo
Receivers []componentWithStability
Processors []componentWithStability
Exporters []componentWithStability
Connectors []componentWithStability
Extensions []componentWithStability
Providers []componentWithoutStability
}

// newComponentsCommand constructs a new components command using the given CollectorSettings.
Expand Down Expand Up @@ -109,6 +115,14 @@ func newComponentsCommand(set CollectorSettings) *cobra.Command {
})
}
components.BuildInfo = set.BuildInfo

for providerScheme, providerModuleModule := range set.ProviderModules {
components.Providers = append(components.Providers, componentWithoutStability{
Scheme: providerScheme,
Module: providerModuleModule,
})
}

yamlData, err := yaml.Marshal(components)
if err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions otelcol/command_components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ func TestNewBuildSubCommand(t *testing.T) {
BuildInfo: component.NewDefaultBuildInfo(),
Factories: nopFactories,
ConfigProviderSettings: newDefaultConfigProviderSettings(t, []string{filepath.Join("testdata", "otelcol-nop.yaml")}),
ProviderModules: map[string]string{
"nop": "go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3",
},
}
cmd := NewCommand(set)
cmd.SetArgs([]string{"components"})
Expand Down
3 changes: 3 additions & 0 deletions otelcol/testdata/components-output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ extensions:
module: go.opentelemetry.io/collector/extension/extensiontest v1.2.3
stability:
extension: Stable
providers:
- scheme: nop
module: go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3
Loading