diff --git a/CHANGELOG.md b/CHANGELOG.md index e6ef2e62feb..a71d3e69bea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,13 @@ ### 🛑 Breaking changes 🛑 -- Remove `configunmarshaler.Unmarshaler` interface, per deprecation comment )#5348) +- Remove `configunmarshaler.Unmarshaler` interface, per deprecation comment (#5348) - Remove deprecated pdata funcs/structs from v0.50.0 (#5345) ### 🚩 Deprecations 🚩 +- Deprecate `config.Config` and `config.Service`, use `service.Config*` (#4608) + ### 💡 Enhancements 💡 ### 🧰 Bug fixes 🧰 diff --git a/config/common.go b/config/common.go index b2e582356c4..408fda6a1f1 100644 --- a/config/common.go +++ b/config/common.go @@ -14,6 +14,39 @@ package config // import "go.opentelemetry.io/collector/config" +// Type is the component type as it is used in the config. +type Type string + +// validatable defines the interface for the configuration validation. +type validatable interface { + // Validate validates the configuration and returns an error if invalid. + Validate() error +} + +// Unmarshallable defines an optional interface for custom configuration unmarshaling. +// A configuration struct can implement this interface to override the default unmarshaling. +type Unmarshallable interface { + // Unmarshal is a function that unmarshals a config.Map into the unmarshable struct in a custom way. + // The config.Map for this specific component may be nil or empty if no config available. + Unmarshal(component *Map) error +} + +// DataType is a special Type that represents the data types supported by the collector. We currently support +// collecting metrics, traces and logs, this can expand in the future. +type DataType = Type + +// Currently supported data types. Add new data types here when new types are supported in the future. +const ( + // TracesDataType is the data type tag for traces. + TracesDataType DataType = "traces" + + // MetricsDataType is the data type tag for metrics. + MetricsDataType DataType = "metrics" + + // LogsDataType is the data type tag for logs. + LogsDataType DataType = "logs" +) + func unmarshal(componentSection *Map, intoCfg interface{}) error { if cu, ok := intoCfg.(Unmarshallable); ok { return cu.Unmarshal(componentSection) diff --git a/config/config.go b/config/moved_config.go similarity index 87% rename from config/config.go rename to config/moved_config.go index eace63ab25f..cb441f23bcf 100644 --- a/config/config.go +++ b/config/moved_config.go @@ -26,6 +26,7 @@ var ( ) // Config defines the configuration for the various elements of collector or agent. +// Deprecated: [v0.52.0] Use service.Config type Config struct { // Receivers is a map of ComponentID to Receivers. Receivers map[ComponentID]Receiver @@ -146,20 +147,3 @@ func (cfg *Config) validateService() error { } return nil } - -// Type is the component type as it is used in the config. -type Type string - -// validatable defines the interface for the configuration validation. -type validatable interface { - // Validate validates the configuration and returns an error if invalid. - Validate() error -} - -// Unmarshallable defines an optional interface for custom configuration unmarshalling. -// A configuration struct can implement this interface to override the default unmarshalling. -type Unmarshallable interface { - // Unmarshal is a function that unmarshals a config.Map into the struct in a custom way. - // The config.Map for this specific component may be nil or empty if no config available. - Unmarshal(component *Map) error -} diff --git a/config/config_test.go b/config/moved_config_test.go similarity index 100% rename from config/config_test.go rename to config/moved_config_test.go diff --git a/config/service.go b/config/moved_service.go similarity index 87% rename from config/service.go rename to config/moved_service.go index d53fcf7b14d..5355a7c9b5c 100644 --- a/config/service.go +++ b/config/moved_service.go @@ -21,6 +21,7 @@ import ( ) // Service defines the configurable components of the service. +// Deprecated: [v0.52.0] Use service.ConfigService type Service struct { // Telemetry is the configuration for collector's own telemetry. Telemetry ServiceTelemetry `mapstructure:"telemetry"` @@ -29,10 +30,11 @@ type Service struct { Extensions []ComponentID `mapstructure:"extensions"` // Pipelines are the set of data pipelines configured for the service. - Pipelines Pipelines `mapstructure:"pipelines"` + Pipelines map[ComponentID]*Pipeline `mapstructure:"pipelines"` } // ServiceTelemetry defines the configurable settings for service telemetry. +// Deprecated: [v0.52.0] Use service.ConfigServiceTelemetry type ServiceTelemetry struct { Logs ServiceTelemetryLogs `mapstructure:"logs"` Metrics ServiceTelemetryMetrics `mapstructure:"metrics"` @@ -41,6 +43,7 @@ type ServiceTelemetry struct { // ServiceTelemetryLogs defines the configurable settings for service telemetry logs. // This MUST be compatible with zap.Config. Cannot use directly zap.Config because // the collector uses mapstructure and not yaml tags. +// Deprecated: [v0.52.0] Use service.ConfigServiceTelemetryLogs type ServiceTelemetryLogs struct { // Level is the minimum enabled logging level. // (default = "INFO") @@ -98,6 +101,7 @@ type ServiceTelemetryLogs struct { // ServiceTelemetryMetrics exposes the common Telemetry configuration for one component. // Experimental: *NOTE* this structure is subject to change or removal in the future. +// Deprecated: [v0.52.0] Use service.ConfigServiceTelemetryMetrics type ServiceTelemetryMetrics struct { // Level is the level of telemetry metrics, the possible values are: // - "none" indicates that no telemetry data should be collected; @@ -110,28 +114,13 @@ type ServiceTelemetryMetrics struct { Address string `mapstructure:"address"` } -// DataType is a special Type that represents the data types supported by the collector. We currently support -// collecting metrics, traces and logs, this can expand in the future. -type DataType = Type - -// Currently supported data types. Add new data types here when new types are supported in the future. -const ( - // TracesDataType is the data type tag for traces. - TracesDataType DataType = "traces" - - // MetricsDataType is the data type tag for metrics. - MetricsDataType DataType = "metrics" - - // LogsDataType is the data type tag for logs. - LogsDataType DataType = "logs" -) - // Pipeline defines a single pipeline. +// Deprecated: [v0.52.0] Use service.ConfigServicePipeline type Pipeline struct { Receivers []ComponentID `mapstructure:"receivers"` Processors []ComponentID `mapstructure:"processors"` Exporters []ComponentID `mapstructure:"exporters"` } -// Pipelines is a map of names to Pipelines. -type Pipelines map[ComponentID]*Pipeline +// Deprecated: will be removed soon. +type Pipelines = map[ComponentID]*Pipeline diff --git a/service/config.go b/service/config.go new file mode 100644 index 00000000000..8b659c8ff26 --- /dev/null +++ b/service/config.go @@ -0,0 +1,31 @@ +// 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/config" +) + +type Config = config.Config + +type ConfigService = config.Service + +type ConfigServiceTelemetry = config.ServiceTelemetry + +type ConfigServiceTelemetryLogs = config.ServiceTelemetryLogs + +type ConfigServiceTelemetryMetrics = config.ServiceTelemetryMetrics + +type ConfigServicePipeline = config.Pipeline diff --git a/service/config_provider.go b/service/config_provider.go index 1e2b6e27858..712d2efb978 100644 --- a/service/config_provider.go +++ b/service/config_provider.go @@ -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.Config, error) + Get(ctx context.Context, factories component.Factories) (*Config, error) // Watch blocks until any configuration change was detected or an unrecoverable error // happened during monitoring the configuration changes. @@ -103,13 +103,13 @@ func NewConfigProvider(set ConfigProviderSettings) (ConfigProvider, error) { }, nil } -func (cm *configProvider) Get(ctx context.Context, factories component.Factories) (*config.Config, error) { +func (cm *configProvider) Get(ctx context.Context, factories component.Factories) (*Config, error) { retMap, err := cm.mapResolver.Resolve(ctx) if err != nil { return nil, fmt.Errorf("cannot resolve the configuration: %w", err) } - var cfg *config.Config + var cfg *Config if cfg, err = configunmarshaler.New().Unmarshal(retMap, factories); err != nil { return nil, fmt.Errorf("cannot unmarshal the configuration: %w", err) } diff --git a/service/service.go b/service/service.go index 9df7477674d..1f2bac4b9e3 100644 --- a/service/service.go +++ b/service/service.go @@ -21,7 +21,6 @@ import ( "go.uber.org/multierr" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/service/internal/builder" "go.opentelemetry.io/collector/service/internal/extensions" ) @@ -29,7 +28,7 @@ import ( // service represents the implementation of a component.Host. type service struct { buildInfo component.BuildInfo - config *config.Config + config *Config telemetry component.TelemetrySettings host *serviceHost } diff --git a/service/servicetest/configprovider.go b/service/servicetest/configprovider.go index 1d7196bf59b..5577ac2781d 100644 --- a/service/servicetest/configprovider.go +++ b/service/servicetest/configprovider.go @@ -16,13 +16,13 @@ package servicetest // import "go.opentelemetry.io/collector/service/servicetest import ( "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configtest" + "go.opentelemetry.io/collector/service" "go.opentelemetry.io/collector/service/internal/configunmarshaler" ) // LoadConfig loads a config.Config from file, and does NOT validate the configuration. -func LoadConfig(fileName string, factories component.Factories) (*config.Config, error) { +func LoadConfig(fileName string, factories component.Factories) (*service.Config, error) { // Read yaml config from file cfgMap, err := configtest.LoadConfigMap(fileName) if err != nil { @@ -32,7 +32,7 @@ func LoadConfig(fileName string, factories component.Factories) (*config.Config, } // LoadConfigAndValidate loads a config from the file, and validates the configuration. -func LoadConfigAndValidate(fileName string, factories component.Factories) (*config.Config, error) { +func LoadConfigAndValidate(fileName string, factories component.Factories) (*service.Config, error) { cfg, err := LoadConfig(fileName, factories) if err != nil { return nil, err diff --git a/service/settings.go b/service/settings.go index 9b70ac53c2e..749397e730a 100644 --- a/service/settings.go +++ b/service/settings.go @@ -18,7 +18,6 @@ import ( "go.uber.org/zap" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/config" ) // svcSettings holds configuration for building a new service. @@ -30,7 +29,7 @@ type svcSettings struct { BuildInfo component.BuildInfo // Config represents the configuration of the service. - Config *config.Config + Config *Config // Telemetry represents the service configured telemetry for all the components. Telemetry component.TelemetrySettings