@@ -28,7 +28,7 @@ import (
28
28
"github.com/spf13/viper"
29
29
30
30
"go.opentelemetry.io/collector/component"
31
- "go.opentelemetry.io/collector/config/configload "
31
+ "go.opentelemetry.io/collector/config"
32
32
"go.opentelemetry.io/collector/config/configmodels"
33
33
)
34
34
@@ -38,7 +38,6 @@ type configErrorCode int
38
38
39
39
const (
40
40
_ configErrorCode = iota // skip 0, start errors codes from 1.
41
- errInvalidSubConfig
42
41
errInvalidTypeAndNameKey
43
42
errUnknownType
44
43
errDuplicateName
@@ -94,12 +93,9 @@ type pipelineSettings struct {
94
93
// typeAndNameSeparator is the separator that is used between type and name in type/name composite keys.
95
94
const typeAndNameSeparator = "/"
96
95
97
- // Load loads a Config from Viper .
96
+ // Load loads a Config from Parser .
98
97
// After loading the config, need to check if it is valid by calling `ValidateConfig`.
99
- func Load (
100
- v * viper.Viper ,
101
- factories component.Factories ,
102
- ) (* configmodels.Config , error ) {
98
+ func Load (v * config.Parser , factories component.Factories ) (* configmodels.Config , error ) {
103
99
104
100
var config configmodels.Config
105
101
@@ -120,27 +116,27 @@ func Load(
120
116
121
117
// Start with the service extensions.
122
118
123
- extensions , err := loadExtensions (v . GetStringMap (extensionsKeyName ), factories .Extensions )
119
+ extensions , err := loadExtensions (cast . ToStringMap ( v . Get (extensionsKeyName ) ), factories .Extensions )
124
120
if err != nil {
125
121
return nil , err
126
122
}
127
123
config .Extensions = extensions
128
124
129
125
// Load data components (receivers, exporters, and processors).
130
126
131
- receivers , err := loadReceivers (v . GetStringMap (receiversKeyName ), factories .Receivers )
127
+ receivers , err := loadReceivers (cast . ToStringMap ( v . Get (receiversKeyName ) ), factories .Receivers )
132
128
if err != nil {
133
129
return nil , err
134
130
}
135
131
config .Receivers = receivers
136
132
137
- exporters , err := loadExporters (v . GetStringMap (exportersKeyName ), factories .Exporters )
133
+ exporters , err := loadExporters (cast . ToStringMap ( v . Get (exportersKeyName ) ), factories .Exporters )
138
134
if err != nil {
139
135
return nil , err
140
136
}
141
137
config .Exporters = exporters
142
138
143
- processors , err := loadProcessors (v . GetStringMap (processorsKeyName ), factories .Processors )
139
+ processors , err := loadProcessors (cast . ToStringMap ( v . Get (processorsKeyName ) ), factories .Processors )
144
140
if err != nil {
145
141
return nil , err
146
142
}
@@ -550,29 +546,8 @@ func defaultUnmarshaler(componentViperSection *viper.Viper, intoCfg interface{})
550
546
return componentViperSection .UnmarshalExact (intoCfg )
551
547
}
552
548
553
- // Copied from the Viper but changed to use the same delimiter
554
- // and return error if the sub is not a map.
555
- // See https://github.com/spf13/viper/issues/871
556
- func ViperSubExact (v * viper.Viper , key string ) (* viper.Viper , error ) {
557
- data := v .Get (key )
558
- if data == nil {
559
- return configload .NewViper (), nil
560
- }
561
-
562
- if reflect .TypeOf (data ).Kind () == reflect .Map {
563
- subv := configload .NewViper ()
564
- // Cannot return error because the subv is empty.
565
- _ = subv .MergeConfigMap (cast .ToStringMap (data ))
566
- return subv , nil
567
- }
568
- return nil , & configError {
569
- code : errInvalidSubConfig ,
570
- msg : fmt .Sprintf ("unexpected sub-config value kind for key:%s value:%v kind:%v)" , key , data , reflect .TypeOf (data ).Kind ()),
571
- }
572
- }
573
-
574
549
func viperFromStringMap (data map [string ]interface {}) * viper.Viper {
575
- v := configload .NewViper ()
550
+ v := config .NewViper ()
576
551
// Cannot return error because the subv is empty.
577
552
_ = v .MergeConfigMap (cast .ToStringMap (data ))
578
553
return v
0 commit comments