Skip to content

Commit 792623a

Browse files
committed
remove component.Type cast for Providers and converters list. Update command with explicit yaml mapping instructions
1 parent 9aa4bb8 commit 792623a

File tree

10 files changed

+47
-53
lines changed

10 files changed

+47
-53
lines changed

.chloggen/jackgopack4-add-converters-component-command.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ issues: [11900, 12385]
1515
# (Optional) One or more lines of additional information to render under the primary note.
1616
# These lines will be padded with 2 spaces and then inserted directly into the document.
1717
# Use pipe (|) for multiline entries.
18-
subtext: Converters must now implement the "Type()" function to return type
18+
subtext: buildinfo in components command is now reported as "build_info" for ease of reading.
1919

2020
# Optional: The change log or logs in which this entry should be included.
2121
# e.g. '[user]' or '[user, api]'

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ func main() {
4545
DefaultScheme: "{{ .ConfResolver.DefaultURIScheme }}",
4646
{{- end }}
4747
},
48-
}, ProviderModules: map[component.Type]string{
48+
}, ProviderModules: map[string]string{
4949
{{- range .ConfmapProviders}}
50-
component.MustNewType({{.Name}}.NewFactory().Create(confmap.ProviderSettings{}).Scheme()): "{{.GoMod}}",
50+
{{.Name}}.NewFactory().Create(confmap.ProviderSettings{}).Scheme(): "{{.GoMod}}",
5151
{{- end}}
52-
}, ConverterModules: map[component.Type]string{
52+
}, ConverterModules: map[string]string{
5353
{{- range .ConfmapConverters}}
54-
component.MustNewType({{.Name}}.NewFactory().Create(confmap.ConverterSettings{}).Type()): "{{.GoMod}}",
54+
{{.Name}}: "{{.GoMod}}",
5555
{{- end}}
5656
},
5757

cmd/otelcorecol/main.go

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

confmap/converter.go

-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,4 @@ func NewConverterFactory(f CreateConverterFunc) ConverterFactory {
3535
type Converter interface {
3636
// Convert applies the conversion logic to the given "conf".
3737
Convert(ctx context.Context, conf *Conf) error
38-
// Type returns the type of the converter.
39-
Type() string
4038
}

confmap/resolver_test.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,13 @@ func (f *fakeProvider) Shutdown(context.Context) error {
106106
}
107107

108108
type mockConverter struct {
109-
err error
110-
mockConverterType string
109+
err error
111110
}
112111

113112
func (m *mockConverter) Convert(context.Context, *Conf) error {
114113
return errors.New("converter_err")
115114
}
116115

117-
func (m *mockConverter) Type() string {
118-
return m.mockConverterType
119-
}
120-
121116
func TestNewResolverInvalidSchemeInURI(t *testing.T) {
122117
_, err := NewResolver(ResolverSettings{URIs: []string{"s_3:has invalid char"}, ProviderFactories: []ProviderFactory{newMockProvider(&mockProvider{scheme: "s3"})}})
123118
assert.EqualError(t, err, `invalid uri: "s_3:has invalid char"`)
@@ -179,7 +174,7 @@ func TestResolverErrors(t *testing.T) {
179174
name: "converter error",
180175
locations: []string{"mock:"},
181176
providers: []Provider{&mockProvider{}},
182-
converters: []Converter{&mockConverter{err: errors.New("converter_err"), mockConverterType: "mock"}},
177+
converters: []Converter{&mockConverter{err: errors.New("converter_err")}},
183178
expectResolveErr: true,
184179
},
185180
{

otelcol/collector.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ type CollectorSettings struct {
7070
ConfigProviderSettings ConfigProviderSettings
7171

7272
// ProviderModules maps provider schemes to their respective go modules.
73-
ProviderModules map[component.Type]string
73+
ProviderModules map[string]string
7474

7575
// ConverterModules maps converter names to their respective go modules.
76-
ConverterModules map[component.Type]string
76+
ConverterModules map[string]string
7777

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

otelcol/collector_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -600,22 +600,22 @@ func TestProviderAndConverterModules(t *testing.T) {
600600
BuildInfo: component.NewDefaultBuildInfo(),
601601
Factories: nopFactories,
602602
ConfigProviderSettings: newDefaultConfigProviderSettings(t, []string{filepath.Join("testdata", "otelcol-nop.yaml")}),
603-
ProviderModules: map[component.Type]string{
604-
component.MustNewType("nop"): "go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3",
603+
ProviderModules: map[string]string{
604+
"nop": "go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3",
605605
},
606-
ConverterModules: map[component.Type]string{
607-
component.MustNewType("nopconverter"): "go.opentelemetry.io/collector/converter/testconverter v1.2.3",
606+
ConverterModules: map[string]string{
607+
"nopconverter": "go.opentelemetry.io/collector/converter/testconverter v1.2.3",
608608
},
609609
}
610610
col, err := NewCollector(set)
611611
require.NoError(t, err)
612612
wg := startCollector(context.Background(), t, col)
613613
require.NoError(t, err)
614-
providerModules := map[component.Type]string{
615-
component.MustNewType("nop"): "go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3",
614+
providerModules := map[string]string{
615+
"nop": "go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3",
616616
}
617-
converterModules := map[component.Type]string{
618-
component.MustNewType("nopconverter"): "go.opentelemetry.io/collector/converter/testconverter v1.2.3",
617+
converterModules := map[string]string{
618+
"nopconverter": "go.opentelemetry.io/collector/converter/testconverter v1.2.3",
619619
}
620620
assert.Equal(t, providerModules, col.set.ProviderModules)
621621
assert.Equal(t, converterModules, col.set.ConverterModules)

otelcol/command_components.go

+17-16
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,26 @@ import (
1919
)
2020

2121
type componentWithStability struct {
22-
Name component.Type
23-
Module string
24-
Stability map[string]string
22+
Name component.Type `yaml:"name"`
23+
Module string `yaml:"module"`
24+
Stability map[string]string `yaml:"stability"`
2525
}
2626

2727
type componentWithoutStability struct {
28-
Scheme string
29-
Module string
28+
Name string `yaml:"name,omitempty"`
29+
Scheme string `yaml:"scheme,omitempty"`
30+
Module string `yaml:"module"`
3031
}
3132

3233
type componentsOutput struct {
33-
BuildInfo component.BuildInfo
34-
Receivers []componentWithStability
35-
Processors []componentWithStability
36-
Exporters []componentWithStability
37-
Connectors []componentWithStability
38-
Extensions []componentWithStability
39-
Providers []componentWithoutStability
40-
Converters []componentWithoutStability
34+
BuildInfo component.BuildInfo `yaml:"build_info"`
35+
Receivers []componentWithStability `yaml:"receivers"`
36+
Processors []componentWithStability `yaml:"processors"`
37+
Exporters []componentWithStability `yaml:"exporters"`
38+
Connectors []componentWithStability `yaml:"connectors"`
39+
Extensions []componentWithStability `yaml:"extensions"`
40+
Providers []componentWithoutStability `yaml:"providers"`
41+
Converters []componentWithoutStability `yaml:"converters,omitempty"`
4142
}
4243

4344
// newComponentsCommand constructs a new components command using the given CollectorSettings.
@@ -119,14 +120,14 @@ func newComponentsCommand(set CollectorSettings) *cobra.Command {
119120

120121
for providerScheme, providerModuleModule := range set.ProviderModules {
121122
components.Providers = append(components.Providers, componentWithoutStability{
122-
Scheme: providerScheme.String(),
123+
Scheme: providerScheme,
123124
Module: providerModuleModule,
124125
})
125126
}
126127

127-
for converterType, converterModule := range set.ConverterModules {
128+
for converterName, converterModule := range set.ConverterModules {
128129
components.Converters = append(components.Converters, componentWithoutStability{
129-
Scheme: converterType.String(),
130+
Name: converterName,
130131
Module: converterModule,
131132
})
132133
}

otelcol/command_components_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ func TestNewBuildSubCommand(t *testing.T) {
2121
BuildInfo: component.NewDefaultBuildInfo(),
2222
Factories: nopFactories,
2323
ConfigProviderSettings: newDefaultConfigProviderSettings(t, []string{filepath.Join("testdata", "otelcol-nop.yaml")}),
24-
ProviderModules: map[component.Type]string{
25-
component.MustNewType("nop"): "go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3",
24+
ProviderModules: map[string]string{
25+
"nop": "go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3",
2626
},
27-
ConverterModules: map[component.Type]string{
28-
component.MustNewType("nopconverter"): "go.opentelemetry.io/collector/converter/testconverter v1.2.3",
27+
ConverterModules: map[string]string{
28+
"nopconverter": "go.opentelemetry.io/collector/converter/testconverter v1.2.3",
2929
},
3030
}
3131
cmd := NewCommand(set)

otelcol/testdata/components-output.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
buildinfo:
1+
build_info:
22
command: otelcol
33
description: OpenTelemetry Collector
44
version: latest
@@ -45,5 +45,5 @@ providers:
4545
- scheme: nop
4646
module: go.opentelemetry.io/collector/confmap/provider/testprovider v1.2.3
4747
converters:
48-
- scheme: nopconverter
48+
- name: nopconverter
4949
module: go.opentelemetry.io/collector/converter/testconverter v1.2.3

0 commit comments

Comments
 (0)