Skip to content

Commit f2c56a3

Browse files
authored
Enhance builder to capture go module for each component type (#10599)
Resolves #10570 Alternative to #10598 This implementation is more reliable that #10598 because it gets information directly from the builder manifest. It relies on additional structure in the `component.go` file, ultimately encoded in `otelcol.Factories`. An alternative would be to push the enhancements deeper, into the `<kind>.Factories` implementations, so that the module information is available directly alongside the Factory.
1 parent 2d7dea6 commit f2c56a3

File tree

8 files changed

+145
-10
lines changed

8 files changed

+145
-10
lines changed

.chloggen/module-info-builder.yaml

Lines changed: 25 additions & 0 deletions
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: cmd/builder
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add go module info the builder generated code.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [10570]
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: []

.chloggen/module-info-components.yaml

Lines changed: 25 additions & 0 deletions
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: Add go module to components subcommand.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [10570]
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: []

cmd/builder/internal/builder/config.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type Distribution struct {
6464
OtelColVersion string `mapstructure:"otelcol_version"`
6565
RequireOtelColModule bool `mapstructure:"-"` // required for backwards-compatibility with builds older than 0.86.0
6666
SupportsConfmapFactories bool `mapstructure:"-"` // Required for backwards-compatibility with builds older than 0.99.0
67+
SupportsComponentModules bool `mapstructure:"-"` // Required for backwards-compatibility with builds older than 0.105.0
6768
OutputPath string `mapstructure:"output_path"`
6869
Version string `mapstructure:"version"`
6970
BuildTags string `mapstructure:"build_tags"`
@@ -144,13 +145,14 @@ func (c *Config) SetGoPath() error {
144145
}
145146

146147
func (c *Config) SetBackwardsCompatibility() error {
147-
// check whether we need to adjust the core API module import
148-
constraint, err := version.NewConstraint(">= 0.86.0")
148+
// Get the version of the collector
149+
otelColVersion, err := version.NewVersion(c.Distribution.OtelColVersion)
149150
if err != nil {
150151
return err
151152
}
152153

153-
otelColVersion, err := version.NewVersion(c.Distribution.OtelColVersion)
154+
// check whether we need to adjust the core API module import
155+
constraint, err := version.NewConstraint(">= 0.86.0")
154156
if err != nil {
155157
return err
156158
}
@@ -163,12 +165,15 @@ func (c *Config) SetBackwardsCompatibility() error {
163165
return err
164166
}
165167

166-
otelColVersion, err = version.NewVersion(c.Distribution.OtelColVersion)
168+
c.Distribution.SupportsConfmapFactories = constraint.Check(otelColVersion)
169+
170+
// check whether go modules are recorded for components
171+
constraint, err = version.NewConstraint(">= 0.105.0")
167172
if err != nil {
168173
return err
169174
}
170175

171-
c.Distribution.SupportsConfmapFactories = constraint.Check(otelColVersion)
176+
c.Distribution.SupportsComponentModules = constraint.Check(otelColVersion)
172177

173178
return nil
174179
}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
package main
44

55
import (
6+
{{- if .Distribution.SupportsComponentModules}}
7+
"go.opentelemetry.io/collector/component"
8+
{{- end}}
69
"go.opentelemetry.io/collector/connector"
710
"go.opentelemetry.io/collector/exporter"
811
"go.opentelemetry.io/collector/extension"
@@ -38,6 +41,12 @@ func components() (otelcol.Factories, error) {
3841
if err != nil {
3942
return otelcol.Factories{}, err
4043
}
44+
{{- if .Distribution.SupportsComponentModules}}
45+
factories.ExtensionModules = make(map[component.Type]string, len(factories.Extensions))
46+
{{- range .Extensions}}
47+
factories.ExtensionModules[{{.Name}}.NewFactory().Type()] = "{{.GoMod}}"
48+
{{- end}}
49+
{{- end}}
4150

4251
factories.Receivers, err = receiver.MakeFactoryMap(
4352
{{- range .Receivers}}
@@ -47,6 +56,12 @@ func components() (otelcol.Factories, error) {
4756
if err != nil {
4857
return otelcol.Factories{}, err
4958
}
59+
{{- if .Distribution.SupportsComponentModules}}
60+
factories.ReceiverModules = make(map[component.Type]string, len(factories.Receivers))
61+
{{- range .Receivers}}
62+
factories.ReceiverModules[{{.Name}}.NewFactory().Type()] = "{{.GoMod}}"
63+
{{- end}}
64+
{{- end}}
5065

5166
factories.Exporters, err = exporter.MakeFactoryMap(
5267
{{- range .Exporters}}
@@ -56,6 +71,12 @@ func components() (otelcol.Factories, error) {
5671
if err != nil {
5772
return otelcol.Factories{}, err
5873
}
74+
{{- if .Distribution.SupportsComponentModules}}
75+
factories.ExporterModules = make(map[component.Type]string, len(factories.Exporters))
76+
{{- range .Exporters}}
77+
factories.ExporterModules[{{.Name}}.NewFactory().Type()] = "{{.GoMod}}"
78+
{{- end}}
79+
{{- end}}
5980

6081
factories.Processors, err = processor.MakeFactoryMap(
6182
{{- range .Processors}}
@@ -65,6 +86,12 @@ func components() (otelcol.Factories, error) {
6586
if err != nil {
6687
return otelcol.Factories{}, err
6788
}
89+
{{- if .Distribution.SupportsComponentModules}}
90+
factories.ProcessorModules = make(map[component.Type]string, len(factories.Processors))
91+
{{- range .Processors}}
92+
factories.ProcessorModules[{{.Name}}.NewFactory().Type()] = "{{.GoMod}}"
93+
{{- end}}
94+
{{- end}}
6895

6996
factories.Connectors, err = connector.MakeFactoryMap(
7097
{{- range .Connectors}}
@@ -74,6 +101,12 @@ func components() (otelcol.Factories, error) {
74101
if err != nil {
75102
return otelcol.Factories{}, err
76103
}
104+
{{- if .Distribution.SupportsComponentModules}}
105+
factories.ConnectorModules = make(map[component.Type]string, len(factories.Connectors))
106+
{{- range .Connectors}}
107+
factories.ConnectorModules[{{.Name}}.NewFactory().Type()] = "{{.GoMod}}"
108+
{{- end}}
109+
{{- end}}
77110

78111
return factories, nil
79112
}

otelcol/command_components.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
type componentWithStability struct {
2222
Name component.Type
23+
Module string
2324
Stability map[string]string
2425
}
2526

@@ -49,7 +50,8 @@ func newComponentsCommand(set CollectorSettings) *cobra.Command {
4950
components := componentsOutput{}
5051
for _, con := range sortFactoriesByType[connector.Factory](factories.Connectors) {
5152
components.Connectors = append(components.Connectors, componentWithStability{
52-
Name: con.Type(),
53+
Name: con.Type(),
54+
Module: factories.ConnectorModules[con.Type()],
5355
Stability: map[string]string{
5456
"logs-to-logs": con.LogsToLogsStability().String(),
5557
"logs-to-metrics": con.LogsToMetricsStability().String(),
@@ -67,15 +69,17 @@ func newComponentsCommand(set CollectorSettings) *cobra.Command {
6769
}
6870
for _, ext := range sortFactoriesByType[extension.Factory](factories.Extensions) {
6971
components.Extensions = append(components.Extensions, componentWithStability{
70-
Name: ext.Type(),
72+
Name: ext.Type(),
73+
Module: factories.ExtensionModules[ext.Type()],
7174
Stability: map[string]string{
7275
"extension": ext.ExtensionStability().String(),
7376
},
7477
})
7578
}
7679
for _, prs := range sortFactoriesByType[processor.Factory](factories.Processors) {
7780
components.Processors = append(components.Processors, componentWithStability{
78-
Name: prs.Type(),
81+
Name: prs.Type(),
82+
Module: factories.ProcessorModules[prs.Type()],
7983
Stability: map[string]string{
8084
"logs": prs.LogsProcessorStability().String(),
8185
"metrics": prs.MetricsProcessorStability().String(),
@@ -85,7 +89,8 @@ func newComponentsCommand(set CollectorSettings) *cobra.Command {
8589
}
8690
for _, rcv := range sortFactoriesByType[receiver.Factory](factories.Receivers) {
8791
components.Receivers = append(components.Receivers, componentWithStability{
88-
Name: rcv.Type(),
92+
Name: rcv.Type(),
93+
Module: factories.ReceiverModules[rcv.Type()],
8994
Stability: map[string]string{
9095
"logs": rcv.LogsReceiverStability().String(),
9196
"metrics": rcv.MetricsReceiverStability().String(),
@@ -95,7 +100,8 @@ func newComponentsCommand(set CollectorSettings) *cobra.Command {
95100
}
96101
for _, exp := range sortFactoriesByType[exporter.Factory](factories.Exporters) {
97102
components.Exporters = append(components.Exporters, componentWithStability{
98-
Name: exp.Type(),
103+
Name: exp.Type(),
104+
Module: factories.ExporterModules[exp.Type()],
99105
Stability: map[string]string{
100106
"logs": exp.LogsExporterStability().String(),
101107
"metrics": exp.MetricsExporterStability().String(),

otelcol/factories.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,19 @@ type Factories struct {
2929

3030
// Connectors maps connector type names in the config to the respective factory.
3131
Connectors map[component.Type]connector.Factory
32+
33+
// ReceiverModules maps receiver types to their respective go modules.
34+
ReceiverModules map[component.Type]string
35+
36+
// ProcessorModules maps processor types to their respective go modules.
37+
ProcessorModules map[component.Type]string
38+
39+
// ExporterModules maps exporter types to their respective go modules.
40+
ExporterModules map[component.Type]string
41+
42+
// ExtensionModules maps extension types to their respective go modules.
43+
ExtensionModules map[component.Type]string
44+
45+
// ConnectorModules maps connector types to their respective go modules.
46+
ConnectorModules map[component.Type]string
3247
}

otelcol/factories_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,42 @@ func nopFactories() (Factories, error) {
2424
if factories.Connectors, err = connector.MakeFactoryMap(connectortest.NewNopFactory()); err != nil {
2525
return Factories{}, err
2626
}
27+
factories.ConnectorModules = make(map[component.Type]string, len(factories.Connectors))
28+
for _, con := range factories.Connectors {
29+
factories.ConnectorModules[con.Type()] = "go.opentelemetry.io/collector/connector/connectortest v1.2.3"
30+
}
2731

2832
if factories.Extensions, err = extension.MakeFactoryMap(extensiontest.NewNopFactory()); err != nil {
2933
return Factories{}, err
3034
}
35+
factories.ExtensionModules = make(map[component.Type]string, len(factories.Extensions))
36+
for _, ext := range factories.Extensions {
37+
factories.ExtensionModules[ext.Type()] = "go.opentelemetry.io/collector/extension/extensiontest v1.2.3"
38+
}
3139

3240
if factories.Receivers, err = receiver.MakeFactoryMap(receivertest.NewNopFactory(), receivertest.NewNopFactoryForType(component.DataTypeLogs)); err != nil {
3341
return Factories{}, err
3442
}
43+
factories.ReceiverModules = make(map[component.Type]string, len(factories.Receivers))
44+
for _, rec := range factories.Receivers {
45+
factories.ReceiverModules[rec.Type()] = "go.opentelemetry.io/collector/receiver/receivertest v1.2.3"
46+
}
3547

3648
if factories.Exporters, err = exporter.MakeFactoryMap(exportertest.NewNopFactory()); err != nil {
3749
return Factories{}, err
3850
}
51+
factories.ExporterModules = make(map[component.Type]string, len(factories.Exporters))
52+
for _, exp := range factories.Exporters {
53+
factories.ExporterModules[exp.Type()] = "go.opentelemetry.io/collector/exporter/exportertest v1.2.3"
54+
}
3955

4056
if factories.Processors, err = processor.MakeFactoryMap(processortest.NewNopFactory()); err != nil {
4157
return Factories{}, err
4258
}
59+
factories.ProcessorModules = make(map[component.Type]string, len(factories.Processors))
60+
for _, proc := range factories.Processors {
61+
factories.ProcessorModules[proc.Type()] = "go.opentelemetry.io/collector/processor/processortest v1.2.3"
62+
}
4363

4464
return factories, err
4565
}

otelcol/testdata/components-output.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,34 @@ buildinfo:
44
version: latest
55
receivers:
66
- name: nop
7+
module: go.opentelemetry.io/collector/receiver/receivertest v1.2.3
78
stability:
89
logs: Stable
910
metrics: Stable
1011
traces: Stable
1112
- name: nop_logs
13+
module: go.opentelemetry.io/collector/receiver/receivertest v1.2.3
1214
stability:
1315
logs: Stable
1416
metrics: Undefined
1517
traces: Undefined
1618
processors:
1719
- name: nop
20+
module: go.opentelemetry.io/collector/processor/processortest v1.2.3
1821
stability:
1922
logs: Stable
2023
metrics: Stable
2124
traces: Stable
2225
exporters:
2326
- name: nop
27+
module: go.opentelemetry.io/collector/exporter/exportertest v1.2.3
2428
stability:
2529
logs: Stable
2630
metrics: Stable
2731
traces: Stable
2832
connectors:
2933
- name: nop
34+
module: go.opentelemetry.io/collector/connector/connectortest v1.2.3
3035
stability:
3136
logs-to-logs: Development
3237
logs-to-metrics: Development
@@ -39,5 +44,6 @@ connectors:
3944
traces-to-traces: Development
4045
extensions:
4146
- name: nop
47+
module: go.opentelemetry.io/collector/extension/extensiontest v1.2.3
4248
stability:
4349
extension: Stable

0 commit comments

Comments
 (0)