Skip to content

Commit

Permalink
[extension] Remove Settings.ModuleInfo and move to service.Host hidde…
Browse files Browse the repository at this point in the history
…n 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
  • Loading branch information
mx-psi authored Feb 5, 2025
1 parent 94eb3df commit 1f0365c
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 29 deletions.
26 changes: 26 additions & 0 deletions .chloggen/mx-psi_move-moduleinfo-to-method.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: extension

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove `extension.Settings.ModuleInfo`

# One or more tracking issues or pull requests related to the change
issues: [12296]

# (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: |
- The functionality is now available as an optional, hidden interface on `service`'s implementation of the `Host`
# 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: [api]
12 changes: 0 additions & 12 deletions extension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ type Extension interface {
component.Component
}

// ModuleInfo describes the go module for each component.
type ModuleInfo struct {
Receiver map[component.Type]string
Processor map[component.Type]string
Exporter map[component.Type]string
Extension map[component.Type]string
Connector map[component.Type]string
}

// Settings is passed to Factory.Create(...) function.
type Settings struct {
// ID returns the ID of the component that will be created.
Expand All @@ -35,9 +26,6 @@ type Settings struct {

// BuildInfo can be used by components for informational purposes
BuildInfo component.BuildInfo

// ModuleInfo describes the go module for each component.
ModuleInfo ModuleInfo
}

// CreateFunc is the equivalent of Factory.Create(...) function.
Expand Down
21 changes: 14 additions & 7 deletions otelcol/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/xconfmap"
"go.opentelemetry.io/collector/extension"
"go.opentelemetry.io/collector/otelcol/internal/grpclog"
"go.opentelemetry.io/collector/service"
)
Expand Down Expand Up @@ -158,6 +157,14 @@ func (col *Collector) Shutdown() {
}
}

func buildModuleInfo(m map[component.Type]string) map[component.Type]service.ModuleInfo {
moduleInfo := make(map[component.Type]service.ModuleInfo)
for k, v := range m {
moduleInfo[k] = service.ModuleInfo{BuilderRef: v}
}
return moduleInfo
}

// setupConfigurationComponents loads the config, creates the graph, and starts the components. If all the steps succeeds it
// sets the col.service with the service currently running.
func (col *Collector) setupConfigurationComponents(ctx context.Context) error {
Expand Down Expand Up @@ -199,12 +206,12 @@ func (col *Collector) setupConfigurationComponents(ctx context.Context) error {
ExtensionsConfigs: cfg.Extensions,
ExtensionsFactories: factories.Extensions,

ModuleInfo: extension.ModuleInfo{
Receiver: factories.ReceiverModules,
Processor: factories.ProcessorModules,
Exporter: factories.ExporterModules,
Extension: factories.ExtensionModules,
Connector: factories.ConnectorModules,
ModuleInfos: service.ModuleInfos{
Receiver: buildModuleInfo(factories.ReceiverModules),
Processor: buildModuleInfo(factories.ProcessorModules),
Exporter: buildModuleInfo(factories.ExporterModules),
Extension: buildModuleInfo(factories.ExtensionModules),
Connector: buildModuleInfo(factories.ConnectorModules),
},
AsyncErrorChannel: col.asyncErrorChannel,
LoggingOptions: col.set.LoggingOptions,
Expand Down
6 changes: 2 additions & 4 deletions service/extensions/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@ func (bes *Extensions) HandleZPages(w http.ResponseWriter, r *http.Request) {

// Settings holds configuration for building Extensions.
type Settings struct {
Telemetry component.TelemetrySettings
BuildInfo component.BuildInfo
ModuleInfo extension.ModuleInfo
Telemetry component.TelemetrySettings
BuildInfo component.BuildInfo

// Extensions builder for extensions.
Extensions builders.Extension
Expand Down Expand Up @@ -214,7 +213,6 @@ func New(ctx context.Context, set Settings, cfg Config, options ...Option) (*Ext
ID: extID,
TelemetrySettings: set.Telemetry,
BuildInfo: set.BuildInfo,
ModuleInfo: set.ModuleInfo,
}
extSet.TelemetrySettings.Logger = components.ExtensionLogger(set.Telemetry.Logger, extID)

Expand Down
17 changes: 14 additions & 3 deletions service/internal/graph/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componentstatus"
"go.opentelemetry.io/collector/extension"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/pipeline"
"go.opentelemetry.io/collector/service/extensions"
"go.opentelemetry.io/collector/service/internal/builders"
"go.opentelemetry.io/collector/service/internal/moduleinfo"
"go.opentelemetry.io/collector/service/internal/status"
"go.opentelemetry.io/collector/service/internal/zpages"
)
Expand All @@ -25,9 +25,16 @@ type getExporters interface {
GetExporters() map[pipeline.Signal]map[component.ID]component.Component
}

// TODO: expose GetModuleInfo as part of a service/hostcapabilities package.
type getModuleInfos interface {
// GetModuleInfo returns the module information for the host.
GetModuleInfos() moduleinfo.ModuleInfos
}

var (
_ getExporters = (*Host)(nil)
_ component.Host = (*Host)(nil)
_ getModuleInfos = (*Host)(nil)
)

type Host struct {
Expand All @@ -38,8 +45,8 @@ type Host struct {
Connectors *builders.ConnectorBuilder
Extensions *builders.ExtensionBuilder

ModuleInfo extension.ModuleInfo
BuildInfo component.BuildInfo
ModuleInfos moduleinfo.ModuleInfos
BuildInfo component.BuildInfo

Pipelines *Graph
ServiceExtensions *extensions.Extensions
Expand Down Expand Up @@ -67,6 +74,10 @@ func (host *Host) GetExtensions() map[component.ID]component.Component {
return host.ServiceExtensions.GetExtensions()
}

func (host *Host) GetModuleInfos() moduleinfo.ModuleInfos {
return host.ModuleInfos
}

// Deprecated: [0.79.0] This function will be removed in the future.
// Several components in the contrib repository use this function so it cannot be removed
// before those cases are removed. In most cases, use of this function can be replaced by a
Expand Down
20 changes: 20 additions & 0 deletions service/internal/moduleinfo/moduleinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package moduleinfo // import "go.opentelemetry.io/collector/service/internal/moduleinfo"

import "go.opentelemetry.io/collector/component"

type ModuleInfo struct {
// BuilderRef is the raw string passed in the builder configuration used to build this service.
BuilderRef string
}

// ModuleInfos describes the go module for each component.
type ModuleInfos struct {
Receiver map[component.Type]ModuleInfo
Processor map[component.Type]ModuleInfo
Exporter map[component.Type]ModuleInfo
Extension map[component.Type]ModuleInfo
Connector map[component.Type]ModuleInfo
}
12 changes: 9 additions & 3 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"go.opentelemetry.io/collector/service/extensions"
"go.opentelemetry.io/collector/service/internal/builders"
"go.opentelemetry.io/collector/service/internal/graph"
"go.opentelemetry.io/collector/service/internal/moduleinfo"
"go.opentelemetry.io/collector/service/internal/proctelemetry"
"go.opentelemetry.io/collector/service/internal/resource"
"go.opentelemetry.io/collector/service/internal/status"
Expand All @@ -56,6 +57,12 @@ var disableHighCardinalityMetricsFeatureGate = featuregate.GlobalRegistry().Must
featuregate.WithRegisterDescription("controls whether the collector should enable potentially high"+
"cardinality metrics. The gate will be removed when the collector allows for view configuration."))

// ModuleInfo describes the Go module for a particular component.
type ModuleInfo = moduleinfo.ModuleInfo

// ModuleInfo describes the go module for all components.
type ModuleInfos = moduleinfo.ModuleInfos

// Settings holds configuration for building a new Service.
type Settings struct {
// BuildInfo provides collector start information.
Expand Down Expand Up @@ -88,7 +95,7 @@ type Settings struct {
ExtensionsFactories map[component.Type]extension.Factory

// ModuleInfo describes the go module for each component.
ModuleInfo extension.ModuleInfo
ModuleInfos ModuleInfos

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

ModuleInfo: set.ModuleInfo,
ModuleInfos: set.ModuleInfos,
BuildInfo: set.BuildInfo,
AsyncErrorChannel: set.AsyncErrorChannel,
},
Expand Down Expand Up @@ -341,7 +348,6 @@ func (srv *Service) initExtensions(ctx context.Context, cfg extensions.Config) e
Telemetry: srv.telemetrySettings,
BuildInfo: srv.buildInfo,
Extensions: srv.host.Extensions,
ModuleInfo: srv.host.ModuleInfo,
}
if srv.host.ServiceExtensions, err = extensions.New(ctx, extensionsSettings, cfg, extensions.WithReporter(srv.host.Reporter)); err != nil {
return fmt.Errorf("failed to build extensions: %w", err)
Expand Down

0 comments on commit 1f0365c

Please sign in to comment.