Skip to content

Commit

Permalink
feat: adds support to modify the config after it is being parsed.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcchavezs authored and tim-mwangi committed Aug 23, 2021
1 parent 285b5f0 commit a256f74
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions service/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configcheck"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/config/configunmarshaler"
Expand Down Expand Up @@ -236,6 +237,13 @@ func (col *Collector) runAndWaitForShutdownEvent() {
col.stateChannel <- Closing
}

// ConfigPostProcessor allows to intercept the final config and do changes in the factories or
// pipelines. For further information refer to the issue:
// https://github.com/open-telemetry/opentelemetry-collector/issues/3023
type ConfigPostProcessor interface {
Process(c *config.Config)
}

// setupConfigurationComponents loads the config and starts the components. If all the steps succeeds it
// sets the col.service with the service currently running.
func (col *Collector) setupConfigurationComponents(ctx context.Context) error {
Expand All @@ -255,6 +263,11 @@ func (col *Collector) setupConfigurationComponents(ctx context.Context) error {
return fmt.Errorf("invalid configuration: %w", err)
}

if postProcessor, ok := col.parserProvider.(ConfigPostProcessor); ok {
// Here we modify the config to be able to manipulate processors and pipelines
postProcessor.Process(cfg)
}

col.logger.Info("Applying configuration...")

service, err := newService(&svcSettings{
Expand Down

0 comments on commit a256f74

Please sign in to comment.