Skip to content

Commit

Permalink
Add one more layer
Browse files Browse the repository at this point in the history
  • Loading branch information
mx-psi committed Feb 5, 2025
1 parent b45fd67 commit cd4045b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
20 changes: 14 additions & 6 deletions otelcol/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,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 @@ -198,12 +206,12 @@ func (col *Collector) setupConfigurationComponents(ctx context.Context) error {
ExtensionsConfigs: cfg.Extensions,
ExtensionsFactories: factories.Extensions,

ModuleInfo: service.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
14 changes: 7 additions & 7 deletions service/internal/graph/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ type getExporters interface {
}

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

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

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

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

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

func (host *Host) GetModuleInfo() moduleinfo.ModuleInfo {
return host.ModuleInfo
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.
Expand Down
17 changes: 11 additions & 6 deletions service/internal/moduleinfo/moduleinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ package moduleinfo // import "go.opentelemetry.io/collector/service/internal/mod

import "go.opentelemetry.io/collector/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
// 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
}
9 changes: 6 additions & 3 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +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 each component.
// 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 @@ -92,7 +95,7 @@ type Settings struct {
ExtensionsFactories map[component.Type]extension.Factory

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

// AsyncErrorChannel is the channel that is used to report fatal errors.
AsyncErrorChannel chan error
Expand Down Expand Up @@ -121,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

0 comments on commit cd4045b

Please sign in to comment.