Skip to content

Commit 861fa20

Browse files
jackgopack4mx-psi
andauthored
[otelcol] add converters to components command (#12385)
<!--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]>
1 parent 8099e51 commit 861fa20

File tree

8 files changed

+76
-3
lines changed

8 files changed

+76
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: otelcol
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Converters are now available in the `components` command.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [11900, 12385]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [user, api]

cmd/builder/internal/builder/templates/main.go.tmpl

+6-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ func main() {
4949
{{- range .ConfmapProviders}}
5050
{{.Name}}.NewFactory().Create(confmap.ProviderSettings{}).Scheme(): "{{.GoMod}}",
5151
{{- end}}
52-
},
52+
}, ConverterModules: []string{
53+
{{- range .ConfmapConverters}}
54+
"{{.GoMod}}",
55+
{{- end}}
56+
},
57+
5358
}
5459

5560
if err := run(set); err != nil {

cmd/otelcorecol/main.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

otelcol/collector.go

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ type CollectorSettings struct {
7272
// ProviderModules maps provider schemes to their respective go modules.
7373
ProviderModules map[string]string
7474

75+
// ConverterModules maps converter names to their respective go modules.
76+
ConverterModules []string
77+
7578
// LoggingOptions provides a way to change behavior of zap logging.
7679
LoggingOptions []zap.Option
7780

otelcol/collector_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -595,3 +595,31 @@ func newConfFromFile(tb testing.TB, fileName string) map[string]any {
595595

596596
return confmap.NewFromStringMap(data).ToStringMap()
597597
}
598+
599+
func TestProviderAndConverterModules(t *testing.T) {
600+
set := CollectorSettings{
601+
BuildInfo: component.NewDefaultBuildInfo(),
602+
Factories: nopFactories,
603+
ConfigProviderSettings: newDefaultConfigProviderSettings(t, []string{filepath.Join("testdata", "otelcol-nop.yaml")}),
604+
ProviderModules: map[string]string{
605+
"nop": "go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3",
606+
},
607+
ConverterModules: []string{
608+
"go.opentelemetry.io/collector/converter/testconverter v1.2.3",
609+
},
610+
}
611+
col, err := NewCollector(set)
612+
require.NoError(t, err)
613+
wg := startCollector(context.Background(), t, col)
614+
require.NoError(t, err)
615+
providerModules := map[string]string{
616+
"nop": "go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3",
617+
}
618+
converterModules := []string{
619+
"go.opentelemetry.io/collector/converter/testconverter v1.2.3",
620+
}
621+
assert.Equal(t, providerModules, col.set.ProviderModules)
622+
assert.Equal(t, converterModules, col.set.ConverterModules)
623+
col.Shutdown()
624+
wg.Wait()
625+
}

otelcol/command_components.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type componentWithStability struct {
2525
}
2626

2727
type componentWithoutStability struct {
28-
Scheme string
28+
Scheme string `yaml:",omitempty"`
2929
Module string
3030
}
3131

@@ -37,6 +37,7 @@ type componentsOutput struct {
3737
Connectors []componentWithStability
3838
Extensions []componentWithStability
3939
Providers []componentWithoutStability
40+
Converters []componentWithoutStability `yaml:",omitempty"`
4041
}
4142

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

127+
for _, converterModule := range set.ConverterModules {
128+
components.Converters = append(components.Converters, componentWithoutStability{
129+
Module: converterModule,
130+
})
131+
}
132+
126133
yamlData, err := yaml.Marshal(components)
127134
if err != nil {
128135
return err

otelcol/command_components_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ func TestNewBuildSubCommand(t *testing.T) {
2424
ProviderModules: map[string]string{
2525
"nop": "go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3",
2626
},
27+
ConverterModules: []string{
28+
"go.opentelemetry.io/collector/converter/testconverter v1.2.3",
29+
},
2730
}
2831
cmd := NewCommand(set)
2932
cmd.SetArgs([]string{"components"})

otelcol/testdata/components-output.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ extensions:
4444
providers:
4545
- scheme: nop
4646
module: go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3
47+
converters:
48+
- module: go.opentelemetry.io/collector/converter/testconverter v1.2.3

0 commit comments

Comments
 (0)