Skip to content

Commit

Permalink
Disallow users to implement configs directly, allows us to add more f…
Browse files Browse the repository at this point in the history
…uncs (#3690)

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Jul 22, 2021
1 parent f636458 commit 817a257
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
14 changes: 10 additions & 4 deletions config/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@

package config

// Exporter is the configuration of an exporter.
// Embedded validatable will force each exporter to implement Validate() function
// Exporter is the configuration of a component.Exporter. Specific extensions must implement
// this interface and must embed ExporterSettings struct or a struct that extends it.
type Exporter interface {
identifiable
validatable

privateConfigExporter()
}

// Exporters is a map of names to Exporters.
type Exporters map[ComponentID]Exporter

// ExporterSettings defines common settings for an exporter configuration.
// ExporterSettings defines common settings for a component.Exporter configuration.
// Specific exporters can embed this struct and extend it with more fields if needed.
//
// It is highly recommended to "override" the Validate() function.
//
// When embedded in the exporter config, it must be with `mapstructure:",squash"` tag.
type ExporterSettings struct {
id ComponentID `mapstructure:"-"`
Expand All @@ -48,7 +53,8 @@ func (rs *ExporterSettings) SetIDName(idName string) {
rs.id.nameVal = idName
}

// Validate validates the configuration and returns an error if invalid.
func (rs *ExporterSettings) Validate() error {
return nil
}

func (rs *ExporterSettings) privateConfigExporter() {}
15 changes: 10 additions & 5 deletions config/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@

package config

// Extension is the configuration of a service extension. Specific extensions
// must implement this interface and will typically embed ExtensionSettings
// struct or a struct that extends it.
// Embedded validatable will force each extension to implement Validate() function.
// Extension is the configuration of a component.Extension. Specific extensions must implement
// this interface and must embed ExtensionSettings struct or a struct that extends it.
type Extension interface {
identifiable
validatable

privateConfigExtension()
}

// Extensions is a map of names to extensions.
type Extensions map[ComponentID]Extension

// ExtensionSettings defines common settings for an extension configuration.
// ExtensionSettings defines common settings for a component.Extension configuration.
// Specific processors can embed this struct and extend it with more fields if needed.
//
// It is highly recommended to "override" the Validate() function.
//
// When embedded in the extension config, it must be with `mapstructure:",squash"` tag.
type ExtensionSettings struct {
id ComponentID `mapstructure:"-"`
Expand All @@ -54,3 +57,5 @@ func (rs *ExtensionSettings) SetIDName(idName string) {
func (rs *ExtensionSettings) Validate() error {
return nil
}

func (rs *ExtensionSettings) privateConfigExtension() {}
14 changes: 10 additions & 4 deletions config/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@

package config

// Processor is the configuration of a processor. Specific processors must implement this
// interface and will typically embed ProcessorSettings struct or a struct that extends it.
// Embedded validatable will force each processor to implement Validate() function.
// Processor is the configuration of a component.Processor. Specific extensions must implement
// this interface and must embed ProcessorSettings struct or a struct that extends it.
type Processor interface {
identifiable
validatable

privateConfigProcessor()
}

// Processors is a map of names to Processors.
type Processors map[ComponentID]Processor

// ProcessorSettings defines common settings for a processor configuration.
// ProcessorSettings defines common settings for a component.Processor configuration.
// Specific processors can embed this struct and extend it with more fields if needed.
//
// It is highly recommended to "override" the Validate() function.
//
// When embedded in the processor config it must be with `mapstructure:",squash"` tag.
type ProcessorSettings struct {
id ComponentID `mapstructure:"-"`
Expand All @@ -53,3 +57,5 @@ func (rs *ProcessorSettings) SetIDName(idName string) {
func (rs *ProcessorSettings) Validate() error {
return nil
}

func (rs *ProcessorSettings) privateConfigProcessor() {}
13 changes: 9 additions & 4 deletions config/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@

package config

// Receiver is the configuration of a receiver. Specific receivers must implement this
// interface and will typically embed ReceiverSettings struct or a struct that extends it.
// Embedded validatable will force each receiver to implement Validate() function.
// Receiver is the configuration of a component.Receiver. Specific extensions must implement
// this interface and must embed ReceiverSettings struct or a struct that extends it.
type Receiver interface {
identifiable
validatable

privateConfigReceiver()
}

// Receivers is a map of names to Receivers.
type Receivers map[ComponentID]Receiver

// ReceiverSettings defines common settings for a receiver configuration.
// ReceiverSettings defines common settings for a component.Receiver configuration.
// Specific receivers can embed this struct and extend it with more fields if needed.
//
// It is highly recommended to "override" the Validate() function.
//
// When embedded in the receiver config it must be with `mapstructure:",squash"` tag.
type ReceiverSettings struct {
id ComponentID `mapstructure:"-"`
Expand All @@ -54,3 +57,5 @@ func (rs *ReceiverSettings) SetIDName(idName string) {
func (rs *ReceiverSettings) Validate() error {
return nil
}

func (rs *ReceiverSettings) privateConfigReceiver() {}

0 comments on commit 817a257

Please sign in to comment.