Skip to content
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

Deprecate component.Factories in favor of service.Factories #6723

Merged
merged 1 commit into from
Dec 13, 2022
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
16 changes: 16 additions & 0 deletions .chloggen/refactories.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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: component

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate component.Factories in favor of service.Factories

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

# (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:
2 changes: 1 addition & 1 deletion component/componenttest/nop_factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"go.opentelemetry.io/collector/receiver"
)

// NopFactories returns a component.Factories with all nop factories.
// Deprecated: [v0.68.0] use servicetest.NopFactories.
func NopFactories() (component.Factories, error) {
var factories component.Factories
var err error
Expand Down
3 changes: 1 addition & 2 deletions component/factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import (
"fmt"
)

// Factories struct holds in a single type all component factories that
// can be handled by the Config.
// Deprecated: [v0.68.0] use service.Factories.
type Factories struct {
// Receivers maps receiver type names in the config to the respective factory.
Receivers map[Type]ReceiverFactory
Expand Down
4 changes: 2 additions & 2 deletions otelcol/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func (s State) String() string {

// CollectorSettings holds configuration for creating a new Collector.
type CollectorSettings struct {
// Factories component factories.
Factories component.Factories
// Factories service factories.
Factories service.Factories

// BuildInfo provides collector start information.
BuildInfo component.BuildInfo
Expand Down
24 changes: 12 additions & 12 deletions otelcol/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/service/servicetest"
)

func TestStateString(t *testing.T) {
Expand All @@ -40,7 +40,7 @@ func TestStateString(t *testing.T) {
}

func TestCollectorStartAsGoRoutine(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

cfgProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")}))
Expand All @@ -67,7 +67,7 @@ func TestCollectorStartAsGoRoutine(t *testing.T) {
}

func TestCollectorCancelContext(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

cfgProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")}))
Expand Down Expand Up @@ -103,7 +103,7 @@ func (p mockCfgProvider) Watch() <-chan error {
}

func TestCollectorStateAfterConfigChange(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

provider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")}))
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestCollectorStateAfterConfigChange(t *testing.T) {
}

func TestCollectorReportError(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

cfgProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")}))
Expand All @@ -162,7 +162,7 @@ func TestCollectorReportError(t *testing.T) {
}

func TestCollectorSendSignal(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

cfgProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")}))
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestCollectorSendSignal(t *testing.T) {

func TestCollectorFailedShutdown(t *testing.T) {
t.Skip("This test was using telemetry shutdown failure, switch to use a component that errors on shutdown.")
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

cfgProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")}))
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestCollectorFailedShutdown(t *testing.T) {
}

func TestCollectorStartInvalidConfig(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

cfgProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-invalid.yaml")}))
Expand All @@ -253,7 +253,7 @@ func TestCollectorStartWithTraceContextPropagation(t *testing.T) {

for _, tt := range tests {
t.Run(tt.file, func(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

cfgProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", tt.file)}))
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestCollectorRun(t *testing.T) {

for _, tt := range tests {
t.Run(tt.file, func(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

cfgProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", tt.file)}))
Expand All @@ -315,7 +315,7 @@ func TestCollectorRun(t *testing.T) {
}

func TestCollectorShutdownBeforeRun(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

cfgProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")}))
Expand All @@ -340,7 +340,7 @@ func TestCollectorShutdownBeforeRun(t *testing.T) {
}

func TestCollectorClosedStateOnStartUpError(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

cfgProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-invalid.yaml")}))
Expand Down
4 changes: 2 additions & 2 deletions otelcol/collector_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ import (
"golang.org/x/sys/windows/svc"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/service/servicetest"
)

func TestNewSvcHandler(t *testing.T) {
oldArgs := os.Args
defer func() { os.Args = oldArgs }()
os.Args = []string{"otelcol", "--config", filepath.Join("testdata", "otelcol-nop.yaml")}

factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

s := NewSvcHandler(CollectorSettings{BuildInfo: component.NewDefaultBuildInfo(), Factories: factories})
Expand Down
4 changes: 2 additions & 2 deletions otelcol/command_components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
"gopkg.in/yaml.v3"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/service/servicetest"
)

func TestNewBuildSubCommand(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

cfgProvider, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")}))
Expand Down
6 changes: 3 additions & 3 deletions otelcol/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/converter/expandconverter"
"go.opentelemetry.io/collector/confmap/provider/fileprovider"
"go.opentelemetry.io/collector/service/servicetest"
)

func TestNewCommandVersion(t *testing.T) {
Expand All @@ -34,15 +34,15 @@ func TestNewCommandVersion(t *testing.T) {
}

func TestNewCommandNoConfigURI(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

cmd := NewCommand(CollectorSettings{Factories: factories})
require.Error(t, cmd.Execute())
}

func TestNewCommandInvalidComponent(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

cfgProvider, err := NewConfigProvider(
Expand Down
6 changes: 3 additions & 3 deletions otelcol/configprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (
"context"
"fmt"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/converter/expandconverter"
"go.opentelemetry.io/collector/confmap/provider/envprovider"
"go.opentelemetry.io/collector/confmap/provider/fileprovider"
"go.opentelemetry.io/collector/confmap/provider/httpprovider"
"go.opentelemetry.io/collector/confmap/provider/yamlprovider"
"go.opentelemetry.io/collector/service"
)

// ConfigProvider provides the service configuration.
Expand All @@ -41,7 +41,7 @@ type ConfigProvider interface {
// Get returns the service configuration, or error otherwise.
//
// Should never be called concurrently with itself, Watch or Shutdown.
Get(ctx context.Context, factories component.Factories) (*Config, error)
Get(ctx context.Context, factories service.Factories) (*Config, error)

// Watch blocks until any configuration change was detected or an unrecoverable error
// happened during monitoring the configuration changes.
Expand Down Expand Up @@ -88,7 +88,7 @@ func NewConfigProvider(set ConfigProviderSettings) (ConfigProvider, error) {
}, nil
}

func (cm *configProvider) Get(ctx context.Context, factories component.Factories) (*Config, error) {
func (cm *configProvider) Get(ctx context.Context, factories service.Factories) (*Config, error) {
conf, err := cm.mapResolver.Resolve(ctx)
if err != nil {
return nil, fmt.Errorf("cannot resolve the configuration: %w", err)
Expand Down
6 changes: 3 additions & 3 deletions otelcol/configprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"go.uber.org/zap/zapcore"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/provider/fileprovider"
Expand All @@ -35,6 +34,7 @@ import (
"go.opentelemetry.io/collector/processor/processortest"
"go.opentelemetry.io/collector/receiver/receivertest"
"go.opentelemetry.io/collector/service"
"go.opentelemetry.io/collector/service/servicetest"
"go.opentelemetry.io/collector/service/telemetry"
)

Expand Down Expand Up @@ -101,7 +101,7 @@ func TestConfigProviderYaml(t *testing.T) {
cp, err := NewConfigProvider(set)
require.NoError(t, err)

factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

cfg, err := cp.Get(context.Background(), factories)
Expand All @@ -122,7 +122,7 @@ func TestConfigProviderFile(t *testing.T) {
cp, err := NewConfigProvider(set)
require.NoError(t, err)

factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
require.NoError(t, err)

cfg, err := cp.Get(context.Background(), factories)
Expand Down
6 changes: 3 additions & 3 deletions otelcol/otelcoltest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ package otelcoltest // import "go.opentelemetry.io/collector/otelcol/otelcoltest
import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/converter/expandconverter"
"go.opentelemetry.io/collector/confmap/provider/envprovider"
"go.opentelemetry.io/collector/confmap/provider/fileprovider"
"go.opentelemetry.io/collector/confmap/provider/httpprovider"
"go.opentelemetry.io/collector/confmap/provider/yamlprovider"
"go.opentelemetry.io/collector/otelcol"
"go.opentelemetry.io/collector/service"
)

// LoadConfig loads a config.Config from file, and does NOT validate the configuration.
func LoadConfig(fileName string, factories component.Factories) (*otelcol.Config, error) {
func LoadConfig(fileName string, factories service.Factories) (*otelcol.Config, error) {
// Read yaml config from file
provider, err := otelcol.NewConfigProvider(otelcol.ConfigProviderSettings{
ResolverSettings: confmap.ResolverSettings{
Expand All @@ -44,7 +44,7 @@ func LoadConfig(fileName string, factories component.Factories) (*otelcol.Config
}

// LoadConfigAndValidate loads a config from the file, and validates the configuration.
func LoadConfigAndValidate(fileName string, factories component.Factories) (*otelcol.Config, error) {
func LoadConfigAndValidate(fileName string, factories service.Factories) (*otelcol.Config, error) {
cfg, err := LoadConfig(fileName, factories)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions otelcol/otelcoltest/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/service"
"go.opentelemetry.io/collector/service/servicetest"
)

func TestLoadConfig(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
assert.NoError(t, err)

cfg, err := LoadConfig(filepath.Join("testdata", "config.yaml"), factories)
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestLoadConfig(t *testing.T) {
}

func TestLoadConfigAndValidate(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
assert.NoError(t, err)

cfgValidate, errValidate := LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories)
Expand Down
3 changes: 1 addition & 2 deletions otelcol/unmarshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package otelcol // import "go.opentelemetry.io/collector/otelcol"
import (
"go.uber.org/zap/zapcore"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/otelcol/internal/configunmarshaler"
Expand All @@ -35,7 +34,7 @@ type configSettings struct {

// unmarshal the configSettings from a confmap.Conf.
// After the config is unmarshalled, `Validate()` must be called to validate.
func unmarshal(v *confmap.Conf, factories component.Factories) (*configSettings, error) {
func unmarshal(v *confmap.Conf, factories service.Factories) (*configSettings, error) {
// Unmarshal top level sections and validate.
cfg := &configSettings{
Receivers: configunmarshaler.NewReceivers(factories.Receivers),
Expand Down
8 changes: 4 additions & 4 deletions otelcol/unmarshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ import (
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/service"
"go.opentelemetry.io/collector/service/servicetest"
"go.opentelemetry.io/collector/service/telemetry"
)

func TestUnmarshalEmpty(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
assert.NoError(t, err)

_, err = unmarshal(confmap.New(), factories)
assert.NoError(t, err)
}

func TestUnmarshalEmptyAllSections(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
assert.NoError(t, err)

conf := confmap.NewFromStringMap(map[string]interface{}{
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestUnmarshalEmptyAllSections(t *testing.T) {
}

func TestUnmarshalUnknownTopLevel(t *testing.T) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
assert.NoError(t, err)

conf := confmap.NewFromStringMap(map[string]interface{}{
Expand Down
Loading