Skip to content

Commit

Permalink
[chore] remove duplicate code in config (open-telemetry#6602)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored and jaronoff97 committed Dec 14, 2022
1 parent cc53ecd commit f8574d8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 52 deletions.
16 changes: 3 additions & 13 deletions config/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

package config // import "go.opentelemetry.io/collector/config"

import (
"go.opentelemetry.io/collector/component"
)
Expand All @@ -24,23 +25,12 @@ import (
//
// When embedded in the exporter config, it must be with `mapstructure:",squash"` tag.
type ExporterSettings struct {
id component.ID `mapstructure:"-"`
component.ExporterConfig
settings
}

// NewExporterSettings return a new ExporterSettings with the given ComponentID.
func NewExporterSettings(id component.ID) ExporterSettings {
return ExporterSettings{id: id}
return ExporterSettings{settings: newSettings(id)}
}

var _ component.ExporterConfig = (*ExporterSettings)(nil)

// ID returns the receiver component.ID.
func (es *ExporterSettings) ID() component.ID {
return es.id
}

// SetIDName sets the receiver name.
func (es *ExporterSettings) SetIDName(idName string) {
es.id = component.NewIDWithName(es.id.Type(), idName)
}
15 changes: 2 additions & 13 deletions config/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,12 @@ import (
//
// When embedded in the extension config, it must be with `mapstructure:",squash"` tag.
type ExtensionSettings struct {
id component.ID `mapstructure:"-"`
component.ExtensionConfig
settings
}

// NewExtensionSettings return a new ExtensionSettings with the given ID.
func NewExtensionSettings(id component.ID) ExtensionSettings {
return ExtensionSettings{id: id}
return ExtensionSettings{settings: newSettings(id)}
}

var _ component.ExtensionConfig = (*ExtensionSettings)(nil)

// ID returns the receiver ID.
func (es *ExtensionSettings) ID() component.ID {
return es.id
}

// SetIDName sets the receiver name.
func (es *ExtensionSettings) SetIDName(idName string) {
es.id = component.NewIDWithName(es.id.Type(), idName)
}
15 changes: 2 additions & 13 deletions config/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,12 @@ import (
//
// When embedded in the processor config it must be with `mapstructure:",squash"` tag.
type ProcessorSettings struct {
id component.ID `mapstructure:"-"`
component.ProcessorConfig
settings
}

// NewProcessorSettings return a new ProcessorSettings with the given ComponentID.
func NewProcessorSettings(id component.ID) ProcessorSettings {
return ProcessorSettings{id: id}
return ProcessorSettings{settings: newSettings(id)}
}

var _ component.ProcessorConfig = (*ProcessorSettings)(nil)

// ID returns the receiver ComponentID.
func (ps *ProcessorSettings) ID() component.ID {
return ps.id
}

// SetIDName sets the receiver name.
func (ps *ProcessorSettings) SetIDName(idName string) {
ps.id = component.NewIDWithName(ps.id.Type(), idName)
}
15 changes: 2 additions & 13 deletions config/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,12 @@ import (
//
// When embedded in the receiver config it must be with `mapstructure:",squash"` tag.
type ReceiverSettings struct {
id component.ID `mapstructure:"-"`
component.ReceiverConfig
settings
}

// NewReceiverSettings return a new ReceiverSettings with the given ID.
func NewReceiverSettings(id component.ID) ReceiverSettings {
return ReceiverSettings{id: id}
return ReceiverSettings{settings: newSettings(id)}
}

var _ component.ReceiverConfig = (*ReceiverSettings)(nil)

// ID returns the receiver ID.
func (rs *ReceiverSettings) ID() component.ID {
return rs.id
}

// SetIDName sets the receiver name.
func (rs *ReceiverSettings) SetIDName(idName string) {
rs.id = component.NewIDWithName(rs.id.Type(), idName)
}
40 changes: 40 additions & 0 deletions config/settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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 config // import "go.opentelemetry.io/collector/config"

import (
"go.opentelemetry.io/collector/component"
)

type settings struct {
id component.ID `mapstructure:"-"`
component.Config
}

func newSettings(id component.ID) settings {
return settings{id: id}
}

var _ component.Config = (*settings)(nil)

// ID returns the receiver component.ID.
func (es *settings) ID() component.ID {
return es.id
}

// SetIDName sets the receiver name.
func (es *settings) SetIDName(idName string) {
es.id = component.NewIDWithName(es.id.Type(), idName)
}

0 comments on commit f8574d8

Please sign in to comment.