Remove SetType from configmodels, ensure all registered factories set the type (#1798)

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This commit is contained in:
Bogdan Drutu 2020-09-16 15:06:16 -07:00 committed by GitHub
parent 40229324c9
commit 3796e60d69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 27 deletions

View File

@ -263,7 +263,6 @@ func loadExtensions(v *viper.Viper, factories map[configmodels.Type]component.Ex
// Create the default config for this extension
extensionCfg := factory.CreateDefaultConfig()
extensionCfg.SetType(typeStr)
extensionCfg.SetName(fullName)
// Unmarshal only the subconfig for this exporter.
@ -323,7 +322,6 @@ func loadService(v *viper.Viper) (configmodels.Service, error) {
func LoadReceiver(componentConfig *viper.Viper, typeStr configmodels.Type, fullName string, factory component.ReceiverFactory) (configmodels.Receiver, error) {
// Create the default config for this receiver.
receiverCfg := factory.CreateDefaultConfig()
receiverCfg.SetType(typeStr)
receiverCfg.SetName(fullName)
// Now that the default config struct is created we can Unmarshal into it
@ -416,7 +414,6 @@ func loadExporters(v *viper.Viper, factories map[configmodels.Type]component.Exp
// Create the default config for this exporter
exporterCfg := factory.CreateDefaultConfig()
exporterCfg.SetType(typeStr)
exporterCfg.SetName(fullName)
// Unmarshal only the subconfig for this exporter.
@ -472,7 +469,6 @@ func loadProcessors(v *viper.Viper, factories map[configmodels.Type]component.Pr
// Create the default config for this processors
processorCfg := factory.CreateDefaultConfig()
processorCfg.SetType(typeStr)
processorCfg.SetName(fullName)
// Unmarshal only the subconfig for this processor.

View File

@ -46,7 +46,6 @@ type Type string
// NamedEntity is a configuration entity that has a type and a name.
type NamedEntity interface {
Type() Type
SetType(typeStr Type)
Name() string
SetName(name string)
}
@ -151,11 +150,6 @@ func (rs *ReceiverSettings) Type() Type {
return rs.TypeVal
}
// SetType sets the receiver type.
func (rs *ReceiverSettings) SetType(typeStr Type) {
rs.TypeVal = typeStr
}
// ExporterSettings defines common settings for an exporter configuration.
// Specific exporters can embed this struct and extend it with more fields if needed.
type ExporterSettings struct {
@ -180,11 +174,6 @@ func (es *ExporterSettings) Type() Type {
return es.TypeVal
}
// SetType sets the exporter type.
func (es *ExporterSettings) SetType(typeStr Type) {
es.TypeVal = typeStr
}
// ProcessorSettings defines common settings for a processor configuration.
// Specific processors can embed this struct and extend it with more fields if needed.
type ProcessorSettings struct {
@ -207,11 +196,6 @@ func (proc *ProcessorSettings) Type() Type {
return proc.TypeVal
}
// SetType sets the processor type.
func (proc *ProcessorSettings) SetType(typeStr Type) {
proc.TypeVal = typeStr
}
var _ Processor = (*ProcessorSettings)(nil)
// ExtensionSettings defines common settings for a service extension configuration.
@ -236,9 +220,4 @@ func (ext *ExtensionSettings) Type() Type {
return ext.TypeVal
}
// SetType sets the extension type.
func (ext *ExtensionSettings) SetType(typeStr Type) {
ext.TypeVal = typeStr
}
var _ Extension = (*ExtensionSettings)(nil)

View File

@ -39,6 +39,10 @@ func NewFactory() component.ProcessorFactory {
func createDefaultConfig() configmodels.Processor {
return &Config{
ProcessorSettings: configmodels.ProcessorSettings{
TypeVal: typeStr,
NameVal: typeStr,
},
DecisionWait: 30 * time.Second,
NumTraces: 50000,
}

View File

@ -301,6 +301,9 @@ func TestProcessorsBuilder_ErrorOnUnsupportedProcessor(t *testing.T) {
func newBadProcessorFactory() component.ProcessorFactory {
return processorhelper.NewFactory("bf", func() configmodels.Processor {
return &configmodels.ProcessorSettings{}
return &configmodels.ProcessorSettings{
TypeVal: "bf",
NameVal: "bf",
}
})
}

View File

@ -388,6 +388,9 @@ func TestReceiversBuilder_Unused(t *testing.T) {
func newBadReceiverFactory() component.ReceiverFactory {
return receiverhelper.NewFactory("bf", func() configmodels.Receiver {
return &configmodels.ReceiverSettings{}
return &configmodels.ReceiverSettings{
TypeVal: "bf",
NameVal: "bf",
}
})
}

View File

@ -83,6 +83,7 @@ func TestDefaultComponents(t *testing.T) {
v, ok := recvs[k]
require.True(t, ok)
assert.Equal(t, k, v.Type())
assert.Equal(t, k, v.CreateDefaultConfig().Type())
}
procs := factories.Processors
@ -91,6 +92,7 @@ func TestDefaultComponents(t *testing.T) {
v, ok := procs[k]
require.True(t, ok)
assert.Equal(t, k, v.Type())
assert.Equal(t, k, v.CreateDefaultConfig().Type())
}
exps := factories.Exporters
@ -99,5 +101,6 @@ func TestDefaultComponents(t *testing.T) {
v, ok := exps[k]
require.True(t, ok)
assert.Equal(t, k, v.Type())
assert.Equal(t, k, v.CreateDefaultConfig().Type())
}
}