Skip to content

Remove deprecated service.Config #6774

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

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
11 changes: 11 additions & 0 deletions .chloggen/rmservicecfg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: service

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove deprecated `service.Config`.

# One or more tracking issues or pull requests related to the change
issues: [6774]
20 changes: 13 additions & 7 deletions otelcol/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,19 @@ func (col *Collector) setupConfigurationComponents(ctx context.Context) error {
return fmt.Errorf("invalid configuration: %w", err)
}

col.service, err = service.New(service.Settings{
BuildInfo: col.set.BuildInfo,
Factories: col.set.Factories,
Config: cfg,
AsyncErrorChannel: col.asyncErrorChannel,
LoggingOptions: col.set.LoggingOptions,
})
col.service, err = service.New(ctx, service.Settings{
BuildInfo: col.set.BuildInfo,
ReceiverFactories: col.set.Factories.Receivers,
ReceiverConfigs: cfg.Receivers,
ProcessorFactories: col.set.Factories.Processors,
ProcessorConfigs: cfg.Processors,
ExporterFactories: col.set.Factories.Exporters,
ExporterConfigs: cfg.Exporters,
ExtensionFactories: col.set.Factories.Extensions,
ExtensionConfigs: cfg.Extensions,
AsyncErrorChannel: col.asyncErrorChannel,
LoggingOptions: col.set.LoggingOptions,
}, cfg.Service)
if err != nil {
return err
}
Expand Down
133 changes: 133 additions & 0 deletions otelcol/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// 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 otelcol // import "go.opentelemetry.io/collector/otelcol"

import (
"errors"
"fmt"

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

var (
errMissingExporters = errors.New("no exporter configuration specified in config")
errMissingReceivers = errors.New("no receiver configuration specified in config")
)

// Config defines the configuration for the various elements of collector or agent.
type Config struct {
// Receivers is a map of ComponentID to Receivers.
Receivers map[component.ID]component.Config

// Exporters is a map of ComponentID to Exporters.
Exporters map[component.ID]component.Config

// Processors is a map of ComponentID to Processors.
Processors map[component.ID]component.Config

// Extensions is a map of ComponentID to extensions.
Extensions map[component.ID]component.Config

Service service.ConfigService
}

// Validate returns an error if the config is invalid.
//
// This function performs basic validation of configuration. There may be more subtle
// invalid cases that we currently don't check for but which we may want to add in
// the future (e.g. disallowing receiving and exporting on the same endpoint).
func (cfg *Config) Validate() error {
// Currently, there is no default receiver enabled.
// The configuration must specify at least one receiver to be valid.
if len(cfg.Receivers) == 0 {
return errMissingReceivers
}

// Validate the receiver configuration.
for recvID, recvCfg := range cfg.Receivers {
if err := component.ValidateConfig(recvCfg); err != nil {
return fmt.Errorf("receivers::%s: %w", recvID, err)
}
}

// Currently, there is no default exporter enabled.
// The configuration must specify at least one exporter to be valid.
if len(cfg.Exporters) == 0 {
return errMissingExporters
}

// Validate the exporter configuration.
for expID, expCfg := range cfg.Exporters {
if err := component.ValidateConfig(expCfg); err != nil {
return fmt.Errorf("exporters::%s: %w", expID, err)
}
}

// Validate the processor configuration.
for procID, procCfg := range cfg.Processors {
if err := component.ValidateConfig(procCfg); err != nil {
return fmt.Errorf("processors::%s: %w", procID, err)
}
}

// Validate the extension configuration.
for extID, extCfg := range cfg.Extensions {
if err := component.ValidateConfig(extCfg); err != nil {
return fmt.Errorf("extensions::%s: %w", extID, err)
}
}

if err := cfg.Service.Validate(); err != nil {
return err
}

// Check that all enabled extensions in the service are configured.
for _, ref := range cfg.Service.Extensions {
// Check that the name referenced in the Service extensions exists in the top-level extensions.
if cfg.Extensions[ref] == nil {
return fmt.Errorf("service::extensions: references extension %q which is not configured", ref)
}
}

// Check that all pipelines reference only configured components.
for pipelineID, pipeline := range cfg.Service.Pipelines {
// Validate pipeline receiver name references.
for _, ref := range pipeline.Receivers {
// Check that the name referenced in the pipeline's receivers exists in the top-level receivers.
if cfg.Receivers[ref] == nil {
return fmt.Errorf("service::pipeline::%s: references receiver %q which is not configured", pipelineID, ref)
}
}

// Validate pipeline processor name references.
for _, ref := range pipeline.Processors {
// Check that the name referenced in the pipeline's processors exists in the top-level processors.
if cfg.Processors[ref] == nil {
return fmt.Errorf("service::pipeline::%s: references processor %q which is not configured", pipelineID, ref)
}
}

// Validate pipeline exporter name references.
for _, ref := range pipeline.Exporters {
// Check that the name referenced in the pipeline's Exporters exists in the top-level Exporters.
if cfg.Exporters[ref] == nil {
return fmt.Errorf("service::pipeline::%s: references exporter %q which is not configured", pipelineID, ref)
}
}
}

return nil
}
Loading