diff --git a/.chloggen/refactories.yaml b/.chloggen/refactories.yaml new file mode 100755 index 00000000000..aa2ce74b5a8 --- /dev/null +++ b/.chloggen/refactories.yaml @@ -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: diff --git a/component/componenttest/nop_factories.go b/component/componenttest/nop_factories.go index 0ab139dd3d9..bdc40b5d8bb 100644 --- a/component/componenttest/nop_factories.go +++ b/component/componenttest/nop_factories.go @@ -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 diff --git a/component/factories.go b/component/factories.go index 1732003b4b0..0085d519286 100644 --- a/component/factories.go +++ b/component/factories.go @@ -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 diff --git a/otelcol/collector_windows_test.go b/otelcol/collector_windows_test.go index c5fc19749b2..c2bd9573779 100644 --- a/otelcol/collector_windows_test.go +++ b/otelcol/collector_windows_test.go @@ -27,7 +27,7 @@ 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) { @@ -35,7 +35,7 @@ func TestNewSvcHandler(t *testing.T) { 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}) diff --git a/otelcol/command_components_test.go b/otelcol/command_components_test.go index 892825b0d45..8df15dcf95b 100644 --- a/otelcol/command_components_test.go +++ b/otelcol/command_components_test.go @@ -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")})) diff --git a/otelcol/command_test.go b/otelcol/command_test.go index 1448df09b08..1e2f2c011db 100644 --- a/otelcol/command_test.go +++ b/otelcol/command_test.go @@ -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) { @@ -34,7 +34,7 @@ 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}) @@ -42,7 +42,7 @@ func TestNewCommandNoConfigURI(t *testing.T) { } func TestNewCommandInvalidComponent(t *testing.T) { - factories, err := componenttest.NopFactories() + factories, err := servicetest.NopFactories() require.NoError(t, err) cfgProvider, err := NewConfigProvider( diff --git a/otelcol/config_provider_test.go b/otelcol/config_provider_test.go index babaa294c12..ee085843d3d 100644 --- a/otelcol/config_provider_test.go +++ b/otelcol/config_provider_test.go @@ -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" @@ -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" ) @@ -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) @@ -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) diff --git a/otelcol/otelcoltest/config.go b/otelcol/otelcoltest/config.go index ceb314afc4d..0fc5a6224f3 100644 --- a/otelcol/otelcoltest/config.go +++ b/otelcol/otelcoltest/config.go @@ -17,7 +17,6 @@ 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" @@ -25,10 +24,11 @@ import ( "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{ @@ -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 diff --git a/otelcol/otelcoltest/config_test.go b/otelcol/otelcoltest/config_test.go index 0accfc07084..b91a5a06033 100644 --- a/otelcol/otelcoltest/config_test.go +++ b/otelcol/otelcoltest/config_test.go @@ -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) @@ -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) diff --git a/service/collector_test.go b/service/collector_test.go index 36e9dce4b6a..5c562d10052 100644 --- a/service/collector_test.go +++ b/service/collector_test.go @@ -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) { @@ -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")})) @@ -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")})) @@ -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")})) @@ -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")})) @@ -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")})) @@ -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")})) @@ -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")})) @@ -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) @@ -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)})) @@ -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)})) @@ -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")})) @@ -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")})) diff --git a/service/config_provider.go b/service/config_provider.go index ea9670acd17..d1d1457a7f2 100644 --- a/service/config_provider.go +++ b/service/config_provider.go @@ -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" @@ -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. @@ -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) diff --git a/service/factories.go b/service/factories.go new file mode 100644 index 00000000000..84e72cb2f3b --- /dev/null +++ b/service/factories.go @@ -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 diff --git a/service/host.go b/service/host.go index 9e7d4b0e5d9..9cddf33cf8d 100644 --- a/service/host.go +++ b/service/host.go @@ -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 diff --git a/service/service_test.go b/service/service_test.go index c65d322a80b..141c0e82283 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -25,12 +25,12 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/featuregate" + "go.opentelemetry.io/collector/service/servicetest" ) func TestService_GetFactory(t *testing.T) { - factories, err := componenttest.NopFactories() + factories, err := servicetest.NopFactories() require.NoError(t, err) srv := createExampleService(t, factories) @@ -56,7 +56,7 @@ func TestService_GetFactory(t *testing.T) { } func TestServiceGetExtensions(t *testing.T) { - factories, err := componenttest.NopFactories() + factories, err := servicetest.NopFactories() require.NoError(t, err) srv := createExampleService(t, factories) @@ -72,7 +72,7 @@ func TestServiceGetExtensions(t *testing.T) { } func TestServiceGetExporters(t *testing.T) { - factories, err := componenttest.NopFactories() + factories, err := servicetest.NopFactories() require.NoError(t, err) srv := createExampleService(t, factories) @@ -94,7 +94,7 @@ func TestServiceGetExporters(t *testing.T) { // TestServiceTelemetryCleanupOnError tests that if newService errors due to an invalid config telemetry is cleaned up // and another service with a valid config can be started right after. func TestServiceTelemetryCleanupOnError(t *testing.T) { - factories, err := componenttest.NopFactories() + factories, err := servicetest.NopFactories() require.NoError(t, err) // Read invalid yaml config from file @@ -140,7 +140,7 @@ func TestServiceTelemetryCleanupOnError(t *testing.T) { // TestServiceTelemetryReusable tests that a single telemetryInitializer can be reused in multiple services func TestServiceTelemetryReusable(t *testing.T) { - factories, err := componenttest.NopFactories() + factories, err := servicetest.NopFactories() require.NoError(t, err) // Read valid yaml config from file @@ -203,7 +203,7 @@ func TestServiceTelemetryReusable(t *testing.T) { require.NoError(t, srvTwo.Shutdown(context.Background())) } -func createExampleService(t *testing.T, factories component.Factories) *service { +func createExampleService(t *testing.T, factories Factories) *service { // Read yaml config from file prov, err := NewConfigProvider(newDefaultConfigProviderSettings([]string{filepath.Join("testdata", "otelcol-nop.yaml")})) require.NoError(t, err) diff --git a/service/servicetest/nop_factories.go b/service/servicetest/nop_factories.go new file mode 100644 index 00000000000..0d6072c8cc0 --- /dev/null +++ b/service/servicetest/nop_factories.go @@ -0,0 +1,20 @@ +// 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 servicetest // import "go.opentelemetry.io/collector/service/servicetest" + +import "go.opentelemetry.io/collector/component/componenttest" + +// NopFactories returns a service.Factories with all nop factories. +var NopFactories = componenttest.NopFactories // nolint:staticcheck diff --git a/service/settings.go b/service/settings.go index 0301a4cb056..08d1807bb42 100644 --- a/service/settings.go +++ b/service/settings.go @@ -23,7 +23,7 @@ import ( // settings holds configuration for building a new service. type settings struct { // Factories component factories. - Factories component.Factories + Factories Factories // BuildInfo provides collector start information. BuildInfo component.BuildInfo @@ -45,7 +45,7 @@ type settings struct { // Deprecated: [v0.66.0] use otelcol.CollectorSettings. type CollectorSettings struct { // Factories component factories. - Factories component.Factories + Factories Factories // BuildInfo provides collector start information. BuildInfo component.BuildInfo diff --git a/service/unmarshaler.go b/service/unmarshaler.go index c1c78d19a04..9a08b17f697 100644 --- a/service/unmarshaler.go +++ b/service/unmarshaler.go @@ -17,7 +17,6 @@ package service // import "go.opentelemetry.io/collector/service" 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/service/internal/configunmarshaler" @@ -34,7 +33,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 Factories) (*configSettings, error) { // Unmarshal top level sections and validate. cfg := &configSettings{ Receivers: configunmarshaler.NewReceivers(factories.Receivers), diff --git a/service/unmarshaler_test.go b/service/unmarshaler_test.go index e6ea1179c42..bc62c5fdb0d 100644 --- a/service/unmarshaler_test.go +++ b/service/unmarshaler_test.go @@ -22,13 +22,13 @@ 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/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) @@ -36,7 +36,7 @@ func TestUnmarshalEmpty(t *testing.T) { } func TestUnmarshalEmptyAllSections(t *testing.T) { - factories, err := componenttest.NopFactories() + factories, err := servicetest.NopFactories() assert.NoError(t, err) conf := confmap.NewFromStringMap(map[string]interface{}{ @@ -67,7 +67,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{}{