Skip to content

Commit 1f0365c

Browse files
authored
[extension] Remove Settings.ModuleInfo and move to service.Host hidden method (#12296)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description <!-- Issue number if applicable --> Moves `extension.Settings.ModuleInfo` to a `service.Host.GetModuleInfo` method. This field probably fits better on `extension.Settings` or even in `component.BuildInfo`, but since its contents are a bit in flux per discussions like #12283, I would like to move it here to not stabilize it alongside the rest of `extension`. The field is not used in any public code on Github, so I think it won't have a huge impact to remove it in one go, happy to do this in two steps if preferred. One relevant difference is that this information is no longer available at extension build time, but rather after the `Start` method is called. Another relevant difference is that this is now available for all component kinds, not just extensions. This could be worked around (we could pass a different host depending on the component kind) but I don't see the use right now. #### Link to tracking issue Updates #12283
1 parent 94eb3df commit 1f0365c

File tree

7 files changed

+85
-29
lines changed

7 files changed

+85
-29
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: extension
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Remove `extension.Settings.ModuleInfo`
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12296]
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+
- The functionality is now available as an optional, hidden interface on `service`'s implementation of the `Host`
20+
21+
# Optional: The change log or logs in which this entry should be included.
22+
# e.g. '[user]' or '[user, api]'
23+
# Include 'user' if the change is relevant to end users.
24+
# Include 'api' if there is a change to a library API.
25+
# Default: '[user]'
26+
change_logs: [api]

extension/extension.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ type Extension interface {
1717
component.Component
1818
}
1919

20-
// ModuleInfo describes the go module for each component.
21-
type ModuleInfo struct {
22-
Receiver map[component.Type]string
23-
Processor map[component.Type]string
24-
Exporter map[component.Type]string
25-
Extension map[component.Type]string
26-
Connector map[component.Type]string
27-
}
28-
2920
// Settings is passed to Factory.Create(...) function.
3021
type Settings struct {
3122
// ID returns the ID of the component that will be created.
@@ -35,9 +26,6 @@ type Settings struct {
3526

3627
// BuildInfo can be used by components for informational purposes
3728
BuildInfo component.BuildInfo
38-
39-
// ModuleInfo describes the go module for each component.
40-
ModuleInfo ModuleInfo
4129
}
4230

4331
// CreateFunc is the equivalent of Factory.Create(...) function.

otelcol/collector.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"go.opentelemetry.io/collector/component"
2323
"go.opentelemetry.io/collector/confmap"
2424
"go.opentelemetry.io/collector/confmap/xconfmap"
25-
"go.opentelemetry.io/collector/extension"
2625
"go.opentelemetry.io/collector/otelcol/internal/grpclog"
2726
"go.opentelemetry.io/collector/service"
2827
)
@@ -158,6 +157,14 @@ func (col *Collector) Shutdown() {
158157
}
159158
}
160159

160+
func buildModuleInfo(m map[component.Type]string) map[component.Type]service.ModuleInfo {
161+
moduleInfo := make(map[component.Type]service.ModuleInfo)
162+
for k, v := range m {
163+
moduleInfo[k] = service.ModuleInfo{BuilderRef: v}
164+
}
165+
return moduleInfo
166+
}
167+
161168
// setupConfigurationComponents loads the config, creates the graph, and starts the components. If all the steps succeeds it
162169
// sets the col.service with the service currently running.
163170
func (col *Collector) setupConfigurationComponents(ctx context.Context) error {
@@ -199,12 +206,12 @@ func (col *Collector) setupConfigurationComponents(ctx context.Context) error {
199206
ExtensionsConfigs: cfg.Extensions,
200207
ExtensionsFactories: factories.Extensions,
201208

202-
ModuleInfo: extension.ModuleInfo{
203-
Receiver: factories.ReceiverModules,
204-
Processor: factories.ProcessorModules,
205-
Exporter: factories.ExporterModules,
206-
Extension: factories.ExtensionModules,
207-
Connector: factories.ConnectorModules,
209+
ModuleInfos: service.ModuleInfos{
210+
Receiver: buildModuleInfo(factories.ReceiverModules),
211+
Processor: buildModuleInfo(factories.ProcessorModules),
212+
Exporter: buildModuleInfo(factories.ExporterModules),
213+
Extension: buildModuleInfo(factories.ExtensionModules),
214+
Connector: buildModuleInfo(factories.ConnectorModules),
208215
},
209216
AsyncErrorChannel: col.asyncErrorChannel,
210217
LoggingOptions: col.set.LoggingOptions,

service/extensions/extensions.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,8 @@ func (bes *Extensions) HandleZPages(w http.ResponseWriter, r *http.Request) {
170170

171171
// Settings holds configuration for building Extensions.
172172
type Settings struct {
173-
Telemetry component.TelemetrySettings
174-
BuildInfo component.BuildInfo
175-
ModuleInfo extension.ModuleInfo
173+
Telemetry component.TelemetrySettings
174+
BuildInfo component.BuildInfo
176175

177176
// Extensions builder for extensions.
178177
Extensions builders.Extension
@@ -214,7 +213,6 @@ func New(ctx context.Context, set Settings, cfg Config, options ...Option) (*Ext
214213
ID: extID,
215214
TelemetrySettings: set.Telemetry,
216215
BuildInfo: set.BuildInfo,
217-
ModuleInfo: set.ModuleInfo,
218216
}
219217
extSet.TelemetrySettings.Logger = components.ExtensionLogger(set.Telemetry.Logger, extID)
220218

service/internal/graph/host.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111

1212
"go.opentelemetry.io/collector/component"
1313
"go.opentelemetry.io/collector/component/componentstatus"
14-
"go.opentelemetry.io/collector/extension"
1514
"go.opentelemetry.io/collector/featuregate"
1615
"go.opentelemetry.io/collector/pipeline"
1716
"go.opentelemetry.io/collector/service/extensions"
1817
"go.opentelemetry.io/collector/service/internal/builders"
18+
"go.opentelemetry.io/collector/service/internal/moduleinfo"
1919
"go.opentelemetry.io/collector/service/internal/status"
2020
"go.opentelemetry.io/collector/service/internal/zpages"
2121
)
@@ -25,9 +25,16 @@ type getExporters interface {
2525
GetExporters() map[pipeline.Signal]map[component.ID]component.Component
2626
}
2727

28+
// TODO: expose GetModuleInfo as part of a service/hostcapabilities package.
29+
type getModuleInfos interface {
30+
// GetModuleInfo returns the module information for the host.
31+
GetModuleInfos() moduleinfo.ModuleInfos
32+
}
33+
2834
var (
2935
_ getExporters = (*Host)(nil)
3036
_ component.Host = (*Host)(nil)
37+
_ getModuleInfos = (*Host)(nil)
3138
)
3239

3340
type Host struct {
@@ -38,8 +45,8 @@ type Host struct {
3845
Connectors *builders.ConnectorBuilder
3946
Extensions *builders.ExtensionBuilder
4047

41-
ModuleInfo extension.ModuleInfo
42-
BuildInfo component.BuildInfo
48+
ModuleInfos moduleinfo.ModuleInfos
49+
BuildInfo component.BuildInfo
4350

4451
Pipelines *Graph
4552
ServiceExtensions *extensions.Extensions
@@ -67,6 +74,10 @@ func (host *Host) GetExtensions() map[component.ID]component.Component {
6774
return host.ServiceExtensions.GetExtensions()
6875
}
6976

77+
func (host *Host) GetModuleInfos() moduleinfo.ModuleInfos {
78+
return host.ModuleInfos
79+
}
80+
7081
// Deprecated: [0.79.0] This function will be removed in the future.
7182
// Several components in the contrib repository use this function so it cannot be removed
7283
// before those cases are removed. In most cases, use of this function can be replaced by a
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package moduleinfo // import "go.opentelemetry.io/collector/service/internal/moduleinfo"
5+
6+
import "go.opentelemetry.io/collector/component"
7+
8+
type ModuleInfo struct {
9+
// BuilderRef is the raw string passed in the builder configuration used to build this service.
10+
BuilderRef string
11+
}
12+
13+
// ModuleInfos describes the go module for each component.
14+
type ModuleInfos struct {
15+
Receiver map[component.Type]ModuleInfo
16+
Processor map[component.Type]ModuleInfo
17+
Exporter map[component.Type]ModuleInfo
18+
Extension map[component.Type]ModuleInfo
19+
Connector map[component.Type]ModuleInfo
20+
}

service/service.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"go.opentelemetry.io/collector/service/extensions"
3434
"go.opentelemetry.io/collector/service/internal/builders"
3535
"go.opentelemetry.io/collector/service/internal/graph"
36+
"go.opentelemetry.io/collector/service/internal/moduleinfo"
3637
"go.opentelemetry.io/collector/service/internal/proctelemetry"
3738
"go.opentelemetry.io/collector/service/internal/resource"
3839
"go.opentelemetry.io/collector/service/internal/status"
@@ -56,6 +57,12 @@ var disableHighCardinalityMetricsFeatureGate = featuregate.GlobalRegistry().Must
5657
featuregate.WithRegisterDescription("controls whether the collector should enable potentially high"+
5758
"cardinality metrics. The gate will be removed when the collector allows for view configuration."))
5859

60+
// ModuleInfo describes the Go module for a particular component.
61+
type ModuleInfo = moduleinfo.ModuleInfo
62+
63+
// ModuleInfo describes the go module for all components.
64+
type ModuleInfos = moduleinfo.ModuleInfos
65+
5966
// Settings holds configuration for building a new Service.
6067
type Settings struct {
6168
// BuildInfo provides collector start information.
@@ -88,7 +95,7 @@ type Settings struct {
8895
ExtensionsFactories map[component.Type]extension.Factory
8996

9097
// ModuleInfo describes the go module for each component.
91-
ModuleInfo extension.ModuleInfo
98+
ModuleInfos ModuleInfos
9299

93100
// AsyncErrorChannel is the channel that is used to report fatal errors.
94101
AsyncErrorChannel chan error
@@ -117,7 +124,7 @@ func New(ctx context.Context, set Settings, cfg Config) (*Service, error) {
117124
Connectors: builders.NewConnector(set.ConnectorsConfigs, set.ConnectorsFactories),
118125
Extensions: builders.NewExtension(set.ExtensionsConfigs, set.ExtensionsFactories),
119126

120-
ModuleInfo: set.ModuleInfo,
127+
ModuleInfos: set.ModuleInfos,
121128
BuildInfo: set.BuildInfo,
122129
AsyncErrorChannel: set.AsyncErrorChannel,
123130
},
@@ -341,7 +348,6 @@ func (srv *Service) initExtensions(ctx context.Context, cfg extensions.Config) e
341348
Telemetry: srv.telemetrySettings,
342349
BuildInfo: srv.buildInfo,
343350
Extensions: srv.host.Extensions,
344-
ModuleInfo: srv.host.ModuleInfo,
345351
}
346352
if srv.host.ServiceExtensions, err = extensions.New(ctx, extensionsSettings, cfg, extensions.WithReporter(srv.host.Reporter)); err != nil {
347353
return fmt.Errorf("failed to build extensions: %w", err)

0 commit comments

Comments
 (0)