Skip to content

Commit

Permalink
[otelcol] add converters to components command (#12385)
Browse files Browse the repository at this point in the history
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Adds list of Converters to command `components`. Additionally, if this
is accepted, Converters must now implement `Type()` function as part of
interface. Given that there are no public converters in core or contrib
repos, I didn't feel like this would be a controversial change, and it
would be very easy for any private users of this interface to update
their code to support it.
<!-- Issue number if applicable -->
#### Link to tracking issue
Extends #11900

<!--Describe what testing was performed and which tests were added.-->
#### Testing
added test data to tests added in 11900, added test to collector_test.go

<!--Describe the documentation added.-->
#### Documentation
Changelog file
<!--Please delete paragraphs that you did not use before submitting.-->

---------

Co-authored-by: Pablo Baeyens <[email protected]>
  • Loading branch information
jackgopack4 and mx-psi authored Feb 26, 2025
1 parent 8099e51 commit 861fa20
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 3 deletions.
25 changes: 25 additions & 0 deletions .chloggen/jackgopack4-add-converters-component-command.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: Converters are now available in the `components` command.

# One or more tracking issues or pull requests related to the change
issues: [11900, 12385]

# (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, api]
7 changes: 6 additions & 1 deletion cmd/builder/internal/builder/templates/main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ func main() {
{{- range .ConfmapProviders}}
{{.Name}}.NewFactory().Create(confmap.ProviderSettings{}).Scheme(): "{{.GoMod}}",
{{- end}}
},
}, ConverterModules: []string{
{{- range .ConfmapConverters}}
"{{.GoMod}}",
{{- end}}
},

}

if err := run(set); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion 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 @@ -72,6 +72,9 @@ type CollectorSettings struct {
// ProviderModules maps provider schemes to their respective go modules.
ProviderModules map[string]string

// ConverterModules maps converter names to their respective go modules.
ConverterModules []string

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

Expand Down
28 changes: 28 additions & 0 deletions otelcol/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,31 @@ func newConfFromFile(tb testing.TB, fileName string) map[string]any {

return confmap.NewFromStringMap(data).ToStringMap()
}

func TestProviderAndConverterModules(t *testing.T) {
set := CollectorSettings{
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",
},
ConverterModules: []string{
"go.opentelemetry.io/collector/converter/testconverter v1.2.3",
},
}
col, err := NewCollector(set)
require.NoError(t, err)
wg := startCollector(context.Background(), t, col)
require.NoError(t, err)
providerModules := map[string]string{
"nop": "go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3",
}
converterModules := []string{
"go.opentelemetry.io/collector/converter/testconverter v1.2.3",
}
assert.Equal(t, providerModules, col.set.ProviderModules)
assert.Equal(t, converterModules, col.set.ConverterModules)
col.Shutdown()
wg.Wait()
}
9 changes: 8 additions & 1 deletion otelcol/command_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type componentWithStability struct {
}

type componentWithoutStability struct {
Scheme string
Scheme string `yaml:",omitempty"`
Module string
}

Expand All @@ -37,6 +37,7 @@ type componentsOutput struct {
Connectors []componentWithStability
Extensions []componentWithStability
Providers []componentWithoutStability
Converters []componentWithoutStability `yaml:",omitempty"`
}

// newComponentsCommand constructs a new components command using the given CollectorSettings.
Expand Down Expand Up @@ -123,6 +124,12 @@ func newComponentsCommand(set CollectorSettings) *cobra.Command {
})
}

for _, converterModule := range set.ConverterModules {
components.Converters = append(components.Converters, componentWithoutStability{
Module: converterModule,
})
}

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 @@ -24,6 +24,9 @@ func TestNewBuildSubCommand(t *testing.T) {
ProviderModules: map[string]string{
"nop": "go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3",
},
ConverterModules: []string{
"go.opentelemetry.io/collector/converter/testconverter v1.2.3",
},
}
cmd := NewCommand(set)
cmd.SetArgs([]string{"components"})
Expand Down
2 changes: 2 additions & 0 deletions otelcol/testdata/components-output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ extensions:
providers:
- scheme: nop
module: go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3
converters:
- module: go.opentelemetry.io/collector/converter/testconverter v1.2.3

0 comments on commit 861fa20

Please sign in to comment.