Skip to content

Commit 8a9433d

Browse files
authored
Merge branch 'main' into rmwaitfor
2 parents b24b027 + b428785 commit 8a9433d

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Remove `configparser.DecodeTypeAndName`, use `config.IDFromString` (#2869)
88
- Remove `testutil.WaitFor`, use `testify.Eventually` helper if needed (#2920)
9+
- Remove `config.NewViper`, users should use `config.NewParser` (#2917)
910

1011
## 💡 Enhancements 💡
1112

config/config.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,17 @@ func (cfg *Config) Validate() error {
8383
}
8484
}
8585

86-
// Validate the processor configuration if there is any processor
87-
// configured in the pipeline
88-
if len(cfg.Processors) != 0 {
89-
for proc, procCfg := range cfg.Processors {
90-
if err := procCfg.Validate(); err != nil {
91-
return fmt.Errorf("processor \"%s\" has invalid configuration: %w", proc, err)
92-
}
86+
// Validate the processor configuration.
87+
for proc, procCfg := range cfg.Processors {
88+
if err := procCfg.Validate(); err != nil {
89+
return fmt.Errorf("processor \"%s\" has invalid configuration: %w", proc, err)
90+
}
91+
}
92+
93+
// Validate the extension configuration.
94+
for ext, extCfg := range cfg.Extensions {
95+
if err := extCfg.Validate(); err != nil {
96+
return fmt.Errorf("extension \"%s\" has invalid configuration: %w", ext, err)
9397
}
9498
}
9599

@@ -112,13 +116,6 @@ func (cfg *Config) validateServiceExtensions() error {
112116
}
113117
}
114118

115-
// Validate the extension configuration.
116-
for ext, extCfg := range cfg.Extensions {
117-
if err := extCfg.Validate(); err != nil {
118-
return fmt.Errorf("extension \"%s\" has invalid configuration: %w", ext, err)
119-
}
120-
}
121-
122119
return nil
123120
}
124121

config/parser.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@ const (
2929
KeyDelimiter = "::"
3030
)
3131

32-
// NewViper creates a new Viper instance with key delimiter KeyDelimiter instead of the
32+
// newViper creates a new Viper instance with key delimiter KeyDelimiter instead of the
3333
// default ".". This way configs can have keys that contain ".".
34-
func NewViper() *viper.Viper {
34+
func newViper() *viper.Viper {
3535
return viper.NewWithOptions(viper.KeyDelimiter(KeyDelimiter))
3636
}
3737

3838
// NewParser creates a new empty Parser instance.
3939
func NewParser() *Parser {
4040
return &Parser{
41-
v: NewViper(),
41+
v: newViper(),
4242
}
4343
}
4444

4545
// NewParserFromFile creates a new Parser by reading the given file.
4646
func NewParserFromFile(fileName string) (*Parser, error) {
4747
// Read yaml config from file
48-
v := NewViper()
48+
v := newViper()
4949
v.SetConfigFile(fileName)
5050
if err := v.ReadInConfig(); err != nil {
5151
return nil, fmt.Errorf("unable to read the file %v: %w", fileName, err)
@@ -55,7 +55,7 @@ func NewParserFromFile(fileName string) (*Parser, error) {
5555

5656
// NewParserFromBuffer creates a new Parser by reading the given yaml buffer.
5757
func NewParserFromBuffer(buf io.Reader) (*Parser, error) {
58-
v := NewViper()
58+
v := newViper()
5959
v.SetConfigType("yaml")
6060
if err := v.ReadConfig(buf); err != nil {
6161
return nil, err
@@ -65,7 +65,7 @@ func NewParserFromBuffer(buf io.Reader) (*Parser, error) {
6565

6666
// NewParserFromStringMap creates a parser from a map[string]interface{}.
6767
func NewParserFromStringMap(data map[string]interface{}) *Parser {
68-
v := NewViper()
68+
v := newViper()
6969
// Cannot return error because the subv is empty.
7070
_ = v.MergeConfigMap(data)
7171
return &Parser{v: v}
@@ -127,7 +127,7 @@ func (l *Parser) Sub(key string) (*Parser, error) {
127127
}
128128

129129
if reflect.TypeOf(data).Kind() == reflect.Map {
130-
subv := NewViper()
130+
subv := newViper()
131131
// Cannot return error because the subv is empty.
132132
_ = subv.MergeConfigMap(cast.ToStringMap(data))
133133
return &Parser{v: subv}, nil

service/parserprovider/setflag.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"fmt"
2020
"strings"
2121

22+
"github.com/spf13/viper"
23+
2224
"go.opentelemetry.io/collector/config"
2325
)
2426

@@ -52,7 +54,7 @@ func (sfl *setFlagProvider) Get() (*config.Parser, error) {
5254
return nil, err
5355
}
5456
}
55-
viperFlags := config.NewViper()
57+
viperFlags := viper.NewWithOptions(viper.KeyDelimiter(config.KeyDelimiter))
5658
viperFlags.SetConfigType(setFlagFileType)
5759
if err := viperFlags.ReadConfig(b); err != nil {
5860
return nil, fmt.Errorf("failed to read set flag config: %v", err)

0 commit comments

Comments
 (0)