Skip to content

Commit

Permalink
Move connector builder into internal service (#10784)
Browse files Browse the repository at this point in the history
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

This moves the connector builder out of the `connector` package, and
into `service/internal/builders`.
There's no real reason for this struct to be public (folks shouldn't
call it), and making it private will allow us to add profiling support
to it.

<!-- Issue number if applicable -->
#### Link to tracking issue

#10375 (review)
  • Loading branch information
dmathieu authored Aug 22, 2024
1 parent 343f449 commit cde1055
Show file tree
Hide file tree
Showing 17 changed files with 740 additions and 61 deletions.
25 changes: 25 additions & 0 deletions .chloggen/private-connector-builder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

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

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate connector.Builder, and move it into an internal package of the service module

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

# (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:

# 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]
9 changes: 9 additions & 0 deletions connector/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package connector // import "go.opentelemetry.io/collector/connector"

import (
"context"
"errors"
"fmt"

"go.uber.org/zap"
Expand All @@ -13,13 +14,21 @@ import (
"go.opentelemetry.io/collector/consumer"
)

var errNilNextConsumer = errors.New("nil next Consumer")

// Builder is a helper struct that given a set of Configs and Factories helps with creating connectors.
//
// Deprecated: [v0.108.0] this builder is being internalized within the service module,
// and will be removed soon.
type Builder struct {
cfgs map[component.ID]component.Config
factories map[component.Type]Factory
}

// NewBuilder creates a new connector.Builder to help with creating components form a set of configs and factories.
//
// Deprecated: [v0.108.0] this builder is being internalized within the service module,
// and will be removed soon.
func NewBuilder(cfgs map[component.ID]component.Config, factories map[component.Type]Factory) *Builder {
return &Builder{cfgs: cfgs, factories: factories}
}
Expand Down
5 changes: 0 additions & 5 deletions connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@
package connector // import "go.opentelemetry.io/collector/connector"

import (
"errors"
"fmt"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/connector/internal"
)

var (
errNilNextConsumer = errors.New("nil next Consumer")
)

// A Traces connector acts as an exporter from a traces pipeline and a receiver
// to one or more traces, metrics, or logs pipelines.
// Traces feeds a consumer.Traces, consumer.Metrics, or consumer.Logs with data.
Expand Down
3 changes: 3 additions & 0 deletions connector/connectortest/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ type nopConnector struct {
}

// NewNopBuilder returns a connector.Builder that constructs nop receivers.
//
// Deprecated: [v0.108.0] this builder is being internalized within the service module,
// and will be removed soon.
func NewNopBuilder() *connector.Builder {
nopFactory := NewNopFactory()
// Use a different ID than receivertest and exportertest to avoid ambiguous
Expand Down
13 changes: 12 additions & 1 deletion internal/e2e/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"go.opentelemetry.io/collector/component/componentstatus"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/connector"
"go.opentelemetry.io/collector/connector/connectortest"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/exporter/exportertest"
Expand All @@ -34,6 +35,11 @@ var nopType = component.MustNewType("nop")

func Test_ComponentStatusReporting_SharedInstance(t *testing.T) {
eventsReceived := make(map[*componentstatus.InstanceID][]*componentstatus.Event)
connectorFactory := connectortest.NewNopFactory()
// Use a different ID than receivertest and exportertest to avoid ambiguous
// configuration scenarios. Ambiguous IDs are detected in the 'otelcol' package,
// but lower level packages such as 'service' assume that IDs are disambiguated.
connID := component.NewIDWithName(nopType, "conn")

set := service.Settings{
BuildInfo: component.NewDefaultBuildInfo(),
Expand All @@ -46,7 +52,12 @@ func Test_ComponentStatusReporting_SharedInstance(t *testing.T) {
},
Processors: processortest.NewNopBuilder(),
Exporters: exportertest.NewNopBuilder(),
Connectors: connectortest.NewNopBuilder(),
ConnectorsConfigs: map[component.ID]component.Config{
connID: connectorFactory.CreateDefaultConfig(),
},
ConnectorsFactories: map[component.Type]connector.Factory{
nopType: connectorFactory,
},
Extensions: extension.NewBuilder(
map[component.ID]component.Config{
component.NewID(component.MustNewType("watcher")): &extensionConfig{eventsReceived},
Expand Down
20 changes: 9 additions & 11 deletions otelcol/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/connector"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/extension"
"go.opentelemetry.io/collector/otelcol/internal/grpclog"
Expand Down Expand Up @@ -184,16 +183,15 @@ func (col *Collector) setupConfigurationComponents(ctx context.Context) error {
}

col.service, err = service.New(ctx, service.Settings{
BuildInfo: col.set.BuildInfo,
CollectorConf: conf,

ReceiversConfigs: cfg.Receivers,
ReceiversFactories: factories.Receivers,

Processors: processor.NewBuilder(cfg.Processors, factories.Processors),
Exporters: exporter.NewBuilder(cfg.Exporters, factories.Exporters),
Connectors: connector.NewBuilder(cfg.Connectors, factories.Connectors),
Extensions: extension.NewBuilder(cfg.Extensions, factories.Extensions),
BuildInfo: col.set.BuildInfo,
CollectorConf: conf,
ReceiversConfigs: cfg.Receivers,
ReceiversFactories: factories.Receivers,
Processors: processor.NewBuilder(cfg.Processors, factories.Processors),
Exporters: exporter.NewBuilder(cfg.Exporters, factories.Exporters),
ConnectorsConfigs: cfg.Connectors,
ConnectorsFactories: factories.Connectors,
Extensions: extension.NewBuilder(cfg.Extensions, factories.Extensions),
ModuleInfo: extension.ModuleInfo{
Receiver: factories.ReceiverModules,
Processor: factories.ProcessorModules,
Expand Down
28 changes: 28 additions & 0 deletions service/internal/builders/builders.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

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

import (
"errors"

"go.uber.org/zap"

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

var (
errNilNextConsumer = errors.New("nil next Consumer")
nopType = component.MustNewType("nop")
)

// logStabilityLevel logs the stability level of a component. The log level is set to info for
// undefined, unmaintained, deprecated and development. The log level is set to debug
// for alpha, beta and stable.
func logStabilityLevel(logger *zap.Logger, sl component.StabilityLevel) {
if sl >= component.StabilityLevelAlpha {
logger.Debug(sl.LogMessage())
} else {
logger.Info(sl.LogMessage())
}
}
Loading

0 comments on commit cde1055

Please sign in to comment.