Skip to content

Commit

Permalink
Deprecate component.Factories in favor of service.Factories
Browse files Browse the repository at this point in the history
  • Loading branch information
djaglowski committed Dec 12, 2022
1 parent 28cd749 commit 6eb6bdd
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 51 deletions.
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_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/config_provider_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
26 changes: 13 additions & 13 deletions service/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ import (
"go.uber.org/zap/zapcore"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/extension/zpagesextension"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/internal/obsreportconfig"
"go.opentelemetry.io/collector/internal/testutil"
"go.opentelemetry.io/collector/service/servicetest"
)

func TestStateString(t *testing.T) {
Expand All @@ -51,7 +51,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 Down Expand Up @@ -79,7 +79,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 @@ -116,7 +116,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 @@ -150,7 +150,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 @@ -177,7 +177,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 @@ -211,7 +211,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 @@ -243,7 +243,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 Down Expand Up @@ -361,7 +361,7 @@ func ownMetricsTestCases(version string) []ownMetricsTestCase {
}

func testCollectorStartHelper(t *testing.T, telemetry *telemetryInitializer, tc ownMetricsTestCase) {
factories, err := componenttest.NopFactories()
factories, err := servicetest.NopFactories()
zpagesExt := zpagesextension.NewFactory()
factories.Extensions[zpagesExt.Type()] = zpagesExt
require.NoError(t, err)
Expand Down Expand Up @@ -455,7 +455,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 @@ -494,7 +494,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 @@ -519,7 +519,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 @@ -545,7 +545,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
5 changes: 2 additions & 3 deletions service/config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ 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"
Expand All @@ -43,7 +42,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 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 @@ -102,7 +101,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 Factories) (*Config, error) {
conf, err := cm.mapResolver.Resolve(ctx)
if err != nil {
return nil, fmt.Errorf("cannot resolve the configuration: %w", err)
Expand Down
23 changes: 23 additions & 0 deletions service/factories.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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

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

// Factories struct holds in a single type all component factories that
// can be handled by the Config.
type Factories = component.Factories // nolint:staticcheck
2 changes: 1 addition & 1 deletion service/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var _ component.Host = (*serviceHost)(nil)

type serviceHost struct {
asyncErrorChannel chan error
factories component.Factories
factories Factories
buildInfo component.BuildInfo

pipelines *builtPipelines
Expand Down
Loading

0 comments on commit 6eb6bdd

Please sign in to comment.