Skip to content

Commit e0e5774

Browse files
authored
Rename configparser.Parser as config.Map (#4075)
* Rename configparser package to configmap Signed-off-by: Bogdan Drutu <[email protected]> * Rename configparser.Parser as config.Map Signed-off-by: Bogdan Drutu <[email protected]>
1 parent ee74217 commit e0e5774

27 files changed

+122
-127
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
## 🛑 Breaking changes 🛑
66

77
- Move configcheck.ValidateConfigFromFactories as internal function in service package (#3876).
8+
- Rename `configparser.Parser` as `config.Map` (#4075)
9+
10+
## 💡 Enhancements 💡
11+
812
- Add Gen dependabot into CI (#4083)
913

1014
## v0.36.0 Beta

config/config.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
"fmt"
2020

2121
"go.uber.org/zap/zapcore"
22-
23-
"go.opentelemetry.io/collector/config/configparser"
2422
)
2523

2624
var (
@@ -203,10 +201,9 @@ type validatable interface {
203201
// Unmarshallable defines an optional interface for custom configuration unmarshaling.
204202
// A configuration struct can implement this interface to override the default unmarshaling.
205203
type Unmarshallable interface {
206-
// Unmarshal is a function that un-marshals a Parser into the unmarshable struct in a custom way.
207-
// componentSection *Parser
208-
// The config for this specific component. May be nil or empty if no config available.
209-
Unmarshal(componentSection *configparser.ConfigMap) error
204+
// Unmarshal is a function that unmarshals a config.Map into the unmarshable struct in a custom way.
205+
// The config.Map for this specific component may be nil or empty if no config available.
206+
Unmarshal(component *Map) error
210207
}
211208

212209
// DataType is the data type that is supported for collection. We currently support

config/configparser/parser.go renamed to config/configmap.go

+27-26
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package configparser
15+
package config
1616

1717
import (
1818
"fmt"
@@ -35,58 +35,59 @@ const (
3535
KeyDelimiter = "::"
3636
)
3737

38-
// NewConfigMap creates a new empty ConfigMap instance.
39-
func NewConfigMap() *ConfigMap {
40-
return &ConfigMap{k: koanf.New(KeyDelimiter)}
38+
// NewMap creates a new empty config.Map instance.
39+
func NewMap() *Map {
40+
return &Map{k: koanf.New(KeyDelimiter)}
4141
}
4242

43-
// NewConfigMapFromFile creates a new ConfigMap by reading the given file.
44-
func NewConfigMapFromFile(fileName string) (*ConfigMap, error) {
43+
// NewMapFromFile creates a new config.Map by reading the given file.
44+
func NewMapFromFile(fileName string) (*Map, error) {
4545
// Read yaml config from file.
46-
p := NewConfigMap()
46+
p := NewMap()
4747
if err := p.k.Load(file.Provider(fileName), yaml.Parser()); err != nil {
4848
return nil, fmt.Errorf("unable to read the file %v: %w", fileName, err)
4949
}
5050
return p, nil
5151
}
5252

53-
// NewConfigMapFromBuffer creates a new ConfigMap by reading the given yaml buffer.
54-
func NewConfigMapFromBuffer(buf io.Reader) (*ConfigMap, error) {
53+
// NewMapFromBuffer creates a new config.Map by reading the given yaml buffer.
54+
func NewMapFromBuffer(buf io.Reader) (*Map, error) {
5555
content, err := ioutil.ReadAll(buf)
5656
if err != nil {
5757
return nil, err
5858
}
5959

60-
p := NewConfigMap()
60+
p := NewMap()
6161
if err := p.k.Load(rawbytes.Provider(content), yaml.Parser()); err != nil {
6262
return nil, err
6363
}
6464

6565
return p, nil
6666
}
6767

68-
// NewConfigMapFromStringMap creates a ConfigMap from a map[string]interface{}.
69-
func NewConfigMapFromStringMap(data map[string]interface{}) *ConfigMap {
70-
p := NewConfigMap()
68+
// NewMapFromStringMap creates a config.Map from a map[string]interface{}.
69+
func NewMapFromStringMap(data map[string]interface{}) *Map {
70+
p := NewMap()
7171
// Cannot return error because the koanf instance is empty.
7272
_ = p.k.Load(confmap.Provider(data, KeyDelimiter), nil)
7373
return p
7474
}
7575

76-
// ConfigMap loads configuration.
77-
type ConfigMap struct {
76+
// Map represents the raw configuration map for the OpenTelemetry Collector.
77+
// The config.Map can be unmarshalled into the Collector's config using the "configunmarshaler" package.
78+
type Map struct {
7879
k *koanf.Koanf
7980
}
8081

8182
// AllKeys returns all keys holding a value, regardless of where they are set.
8283
// Nested keys are returned with a KeyDelimiter separator.
83-
func (l *ConfigMap) AllKeys() []string {
84+
func (l *Map) AllKeys() []string {
8485
return l.k.Keys()
8586
}
8687

8788
// Unmarshal unmarshalls the config into a struct.
8889
// Tags on the fields of the structure must be properly set.
89-
func (l *ConfigMap) Unmarshal(rawVal interface{}) error {
90+
func (l *Map) Unmarshal(rawVal interface{}) error {
9091
decoder, err := mapstructure.NewDecoder(decoderConfig(rawVal))
9192
if err != nil {
9293
return err
@@ -95,7 +96,7 @@ func (l *ConfigMap) Unmarshal(rawVal interface{}) error {
9596
}
9697

9798
// UnmarshalExact unmarshalls the config into a struct, erroring if a field is nonexistent.
98-
func (l *ConfigMap) UnmarshalExact(intoCfg interface{}) error {
99+
func (l *Map) UnmarshalExact(intoCfg interface{}) error {
99100
dc := decoderConfig(intoCfg)
100101
dc.ErrorUnused = true
101102
decoder, err := mapstructure.NewDecoder(dc)
@@ -106,12 +107,12 @@ func (l *ConfigMap) UnmarshalExact(intoCfg interface{}) error {
106107
}
107108

108109
// Get can retrieve any value given the key to use.
109-
func (l *ConfigMap) Get(key string) interface{} {
110+
func (l *Map) Get(key string) interface{} {
110111
return l.k.Get(key)
111112
}
112113

113114
// Set sets the value for the key.
114-
func (l *ConfigMap) Set(key string, value interface{}) {
115+
func (l *Map) Set(key string, value interface{}) {
115116
// koanf doesn't offer a direct setting mechanism so merging is required.
116117
merged := koanf.New(KeyDelimiter)
117118
_ = merged.Load(confmap.Provider(map[string]interface{}{key: value}, KeyDelimiter), nil)
@@ -120,34 +121,34 @@ func (l *ConfigMap) Set(key string, value interface{}) {
120121

121122
// IsSet checks to see if the key has been set in any of the data locations.
122123
// IsSet is case-insensitive for a key.
123-
func (l *ConfigMap) IsSet(key string) bool {
124+
func (l *Map) IsSet(key string) bool {
124125
return l.k.Exists(key)
125126
}
126127

127128
// Merge merges the input given configuration into the existing config.
128129
// Note that the given map may be modified.
129-
func (l *ConfigMap) Merge(in *ConfigMap) error {
130+
func (l *Map) Merge(in *Map) error {
130131
return l.k.Merge(in.k)
131132
}
132133

133134
// Sub returns new Parser instance representing a sub-config of this instance.
134135
// It returns an error is the sub-config is not a map (use Get()) and an empty Parser if
135136
// none exists.
136-
func (l *ConfigMap) Sub(key string) (*ConfigMap, error) {
137+
func (l *Map) Sub(key string) (*Map, error) {
137138
data := l.Get(key)
138139
if data == nil {
139-
return NewConfigMap(), nil
140+
return NewMap(), nil
140141
}
141142

142143
if reflect.TypeOf(data).Kind() == reflect.Map {
143-
return NewConfigMapFromStringMap(cast.ToStringMap(data)), nil
144+
return NewMapFromStringMap(cast.ToStringMap(data)), nil
144145
}
145146

146147
return nil, fmt.Errorf("unexpected sub-config value kind for key:%s value:%v kind:%v)", key, data, reflect.TypeOf(data).Kind())
147148
}
148149

149150
// ToStringMap creates a map[string]interface{} from a Parser.
150-
func (l *ConfigMap) ToStringMap() map[string]interface{} {
151+
func (l *Map) ToStringMap() map[string]interface{} {
151152
return maps.Unflatten(l.k.All(), KeyDelimiter)
152153
}
153154

config/configparser/parser_test.go renamed to config/configmap_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package configparser
15+
package config
1616

1717
import (
1818
"testing"
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
func TestToStringMap_WithSet(t *testing.T) {
25-
parser := NewConfigMap()
25+
parser := NewMap()
2626
parser.Set("key::embedded", int64(123))
2727
assert.Equal(t, map[string]interface{}{"key": map[string]interface{}{"embedded": int64(123)}}, parser.ToStringMap())
2828
}
@@ -98,7 +98,7 @@ func TestToStringMap(t *testing.T) {
9898
}
9999
for _, test := range tests {
100100
t.Run(test.name, func(t *testing.T) {
101-
parser, err := NewConfigMapFromFile(test.fileName)
101+
parser, err := NewMapFromFile(test.fileName)
102102
require.NoError(t, err, "Unable to read configuration file '%s'", test.fileName)
103103
assert.Equal(t, test.stringMap, parser.ToStringMap())
104104
})

config/configtest/configtest.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"go.opentelemetry.io/collector/component"
2424
"go.opentelemetry.io/collector/config"
25-
"go.opentelemetry.io/collector/config/configparser"
2625
"go.opentelemetry.io/collector/config/configunmarshaler"
2726
"go.opentelemetry.io/collector/consumer/consumererror"
2827
)
@@ -33,7 +32,7 @@ var configFieldTagRegExp = regexp.MustCompile("^[a-z0-9][a-z0-9_]*$")
3332
// LoadConfig loads a config from file, and does NOT validate the configuration.
3433
func LoadConfig(fileName string, factories component.Factories) (*config.Config, error) {
3534
// Read yaml config from file
36-
cp, err := configparser.NewConfigMapFromFile(fileName)
35+
cp, err := config.NewMapFromFile(fileName)
3736
if err != nil {
3837
return nil, err
3938
}

config/configunmarshaler/defaultunmarshaler.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"go.opentelemetry.io/collector/component"
2525
"go.opentelemetry.io/collector/config"
26-
"go.opentelemetry.io/collector/config/configparser"
2726
)
2827

2928
// These are errors that can be returned by Unmarshal(). Note that error codes are not part
@@ -109,9 +108,9 @@ func NewDefault() ConfigUnmarshaler {
109108
return &defaultUnmarshaler{}
110109
}
111110

112-
// Unmarshal the Config from a Parser.
111+
// Unmarshal the Config from a config.Map.
113112
// After the config is unmarshaled, `Validate()` must be called to validate.
114-
func (*defaultUnmarshaler) Unmarshal(v *configparser.ConfigMap, factories component.Factories) (*config.Config, error) {
113+
func (*defaultUnmarshaler) Unmarshal(v *config.Map, factories component.Factories) (*config.Config, error) {
115114
var cfg config.Config
116115

117116
// Unmarshal the config.
@@ -209,7 +208,7 @@ func unmarshalExtensions(exts map[string]map[string]interface{}, factories map[c
209208

210209
// Iterate over extensions and create a config for each.
211210
for key, value := range exts {
212-
componentConfig := configparser.NewConfigMapFromStringMap(value)
211+
componentConfig := config.NewMapFromStringMap(value)
213212
expandEnvConfig(componentConfig)
214213

215214
// Decode the key into type and fullName components.
@@ -280,7 +279,7 @@ func unmarshalService(rawService serviceSettings) (config.Service, error) {
280279
}
281280

282281
// LoadReceiver loads a receiver config from componentConfig using the provided factories.
283-
func LoadReceiver(componentConfig *configparser.ConfigMap, id config.ComponentID, factory component.ReceiverFactory) (config.Receiver, error) {
282+
func LoadReceiver(componentConfig *config.Map, id config.ComponentID, factory component.ReceiverFactory) (config.Receiver, error) {
284283
// Create the default config for this receiver.
285284
receiverCfg := factory.CreateDefaultConfig()
286285
receiverCfg.SetIDName(id.Name())
@@ -301,7 +300,7 @@ func unmarshalReceivers(recvs map[string]map[string]interface{}, factories map[c
301300

302301
// Iterate over input map and create a config for each.
303302
for key, value := range recvs {
304-
componentConfig := configparser.NewConfigMapFromStringMap(value)
303+
componentConfig := config.NewMapFromStringMap(value)
305304
expandEnvConfig(componentConfig)
306305

307306
// Decode the key into type and fullName components.
@@ -338,7 +337,7 @@ func unmarshalExporters(exps map[string]map[string]interface{}, factories map[co
338337

339338
// Iterate over Exporters and create a config for each.
340339
for key, value := range exps {
341-
componentConfig := configparser.NewConfigMapFromStringMap(value)
340+
componentConfig := config.NewMapFromStringMap(value)
342341
expandEnvConfig(componentConfig)
343342

344343
// Decode the key into type and fullName components.
@@ -380,7 +379,7 @@ func unmarshalProcessors(procs map[string]map[string]interface{}, factories map[
380379

381380
// Iterate over processors and create a config for each.
382381
for key, value := range procs {
383-
componentConfig := configparser.NewConfigMapFromStringMap(value)
382+
componentConfig := config.NewMapFromStringMap(value)
384383
expandEnvConfig(componentConfig)
385384

386385
// Decode the key into type and fullName components.
@@ -475,9 +474,9 @@ func parseIDNames(pipelineID config.ComponentID, componentType string, names []s
475474
return ret, nil
476475
}
477476

478-
// expandEnvConfig updates a configparser.ConfigMap with expanded values for all the values (simple, list or map value).
477+
// expandEnvConfig updates a config.Map with expanded values for all the values (simple, list or map value).
479478
// It does not expand the keys.
480-
func expandEnvConfig(v *configparser.ConfigMap) {
479+
func expandEnvConfig(v *config.Map) {
481480
for _, k := range v.AllKeys() {
482481
v.Set(k, expandStringValues(v.Get(k)))
483482
}
@@ -568,7 +567,7 @@ func expandEnv(s string) string {
568567
})
569568
}
570569

571-
func unmarshal(componentSection *configparser.ConfigMap, intoCfg interface{}) error {
570+
func unmarshal(componentSection *config.Map, intoCfg interface{}) error {
572571
if cu, ok := intoCfg.(config.Unmarshallable); ok {
573572
return cu.Unmarshal(componentSection)
574573
}

config/configunmarshaler/defaultunmarshaler_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"go.opentelemetry.io/collector/component"
2727
"go.opentelemetry.io/collector/config"
2828
"go.opentelemetry.io/collector/config/confignet"
29-
"go.opentelemetry.io/collector/config/configparser"
3029
"go.opentelemetry.io/collector/internal/testcomponents"
3130
)
3231

@@ -462,10 +461,10 @@ func TestLoadEmptyAllSections(t *testing.T) {
462461
}
463462

464463
func loadConfigFile(t *testing.T, fileName string, factories component.Factories) (*config.Config, error) {
465-
v, err := configparser.NewConfigMapFromFile(fileName)
464+
v, err := config.NewMapFromFile(fileName)
466465
require.NoError(t, err)
467466

468-
// Unmarshal the config from the configparser.ConfigMap using the given factories.
467+
// Unmarshal the config from the config.Map using the given factories.
469468
return NewDefault().Unmarshal(v, factories)
470469
}
471470

config/configunmarshaler/doc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// Package configunmarshaler implements configuration unmarshalling from a config.Parser.
15+
// Package configunmarshaler implements configuration unmarshalling from a config.Map.
1616
// The implementation relies on registered factories that allow creating
1717
// default configuration for each type of receiver/exporter/processor.
1818
package configunmarshaler

config/configunmarshaler/unmarshaler.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ package configunmarshaler
1717
import (
1818
"go.opentelemetry.io/collector/component"
1919
"go.opentelemetry.io/collector/config"
20-
"go.opentelemetry.io/collector/config/configparser"
2120
)
2221

23-
// ConfigUnmarshaler is the interface that unmarshalls the collector configuration from the configparser.ConfigMap.
22+
// ConfigUnmarshaler is the interface that unmarshalls the collector configuration from the config.Map.
2423
type ConfigUnmarshaler interface {
2524
// Unmarshal the configuration from the given parser and factories.
26-
Unmarshal(v *configparser.ConfigMap, factories component.Factories) (*config.Config, error)
25+
Unmarshal(v *config.Map, factories component.Factories) (*config.Config, error)
2726
}

config/doc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//
2323
// To satisfy these requirements we declare interfaces Receiver, Exporter, Processor,
2424
// which define the behavior. We also provide helper structs ReceiverSettings, ExporterSettings,
25-
// ProcessorSettings, which define the common settings and un-marshaling from config files.
25+
// ProcessorSettings, which define the common settings and unmarshaling from config files.
2626
//
2727
// Specific Receivers/Exporters/Processors are expected to at the minimum implement the
2828
// corresponding interface and if they have additional settings they must also extend

config/experimental/configsource/component.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"context"
1919
"errors"
2020

21-
"go.opentelemetry.io/collector/config/configparser"
21+
"go.opentelemetry.io/collector/config"
2222
)
2323

2424
// ErrSessionClosed is returned by WatchForUpdate functions when its parent Session
@@ -54,7 +54,7 @@ type ConfigSource interface {
5454
//
5555
// The selector is a string that is required on all invocations, the params are optional. Each
5656
// implementation handles the generic params according to their requirements.
57-
Retrieve(ctx context.Context, selector string, paramsConfigMap *configparser.ConfigMap) (Retrieved, error)
57+
Retrieve(ctx context.Context, selector string, paramsConfigMap *config.Map) (Retrieved, error)
5858

5959
// Close signals that the configuration for which it was used to retrieve values is no longer in use
6060
// and the object should close and release any watchers that it may have created.

0 commit comments

Comments
 (0)