Skip to content

[extension] Remove Settings.ModuleInfo and move to service.Host hidden method #12296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

"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 @@
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 @@
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 @@
return host.ServiceExtensions.GetExtensions()
}

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

Check warning on line 78 in service/internal/graph/host.go

View check run for this annotation

Codecov / codecov/patch

service/internal/graph/host.go#L77-L78

Added lines #L77 - L78 were not covered by tests
}

// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have version as well here in the future?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it would make sense to move this to have more structure, but I would rather do this in a separate PR (I would have to start parsing the builder ref and I am worried that this is not trivial)

}

// 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
Loading