Skip to content

Commit

Permalink
Deprecate config.Config and config.Service, use service.Config*
Browse files Browse the repository at this point in the history
Fixes open-telemetry#4605

Followup PRs:
* Move service/internal/configunmarshaler as private struct into service/ to avoid circular dependency (no public API change)
* Change service/internal/builders to private structs in service/ or don't pass config, instead only pass the components and pipeline from the config.

While doing this, I realize that the "service" section in our config is a bit useless, we can think of promoting everything under "service::" one level up.

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed May 12, 2022
1 parent 85c26ea commit ea2e23b
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 47 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 🧰
Expand Down
33 changes: 33 additions & 0 deletions config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 1 addition & 17 deletions config/config.go → config/moved_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
File renamed without changes.
27 changes: 8 additions & 19 deletions config/service.go → config/moved_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Expand All @@ -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")
Expand Down Expand Up @@ -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;
Expand All @@ -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
31 changes: 31 additions & 0 deletions service/config.go
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions service/config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ 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"
)

// service represents the implementation of a component.Host.
type service struct {
buildInfo component.BuildInfo
config *config.Config
config *Config
telemetry component.TelemetrySettings
host *serviceHost
}
Expand Down
6 changes: 3 additions & 3 deletions service/servicetest/configprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions service/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit ea2e23b

Please sign in to comment.