Skip to content

Commit 6ab7780

Browse files
committed
Rename configparser package to configmap
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent 8b8a0a1 commit 6ab7780

23 files changed

+91
-69
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
## 🛑 Breaking changes 🛑
6+
-
7+
- Rename `configparser` package to `configmap` (#4075)
8+
59
## v0.36.0 Beta
610

711
## 🛑 Breaking changes 🛑

config/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
"go.uber.org/zap/zapcore"
2222

23-
"go.opentelemetry.io/collector/config/configparser"
23+
"go.opentelemetry.io/collector/config/configmap"
2424
)
2525

2626
var (
@@ -206,7 +206,7 @@ type Unmarshallable interface {
206206
// Unmarshal is a function that un-marshals a Parser into the unmarshable struct in a custom way.
207207
// componentSection *Parser
208208
// The config for this specific component. May be nil or empty if no config available.
209-
Unmarshal(componentSection *configparser.ConfigMap) error
209+
Unmarshal(componentSection *configmap.ConfigMap) error
210210
}
211211

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

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

+3-2
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 configmap
1616

1717
import (
1818
"fmt"
@@ -73,7 +73,8 @@ func NewConfigMapFromStringMap(data map[string]interface{}) *ConfigMap {
7373
return p
7474
}
7575

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

config/configparser/parser_test.go renamed to config/configmap/configmap_test.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 configparser
15+
package configmap
1616

1717
import (
1818
"testing"

config/configmap/doc.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package configmap defines the configuration map and the map providers for
16+
// the OpenTelemetry Collector.
17+
package configmap

config/configtest/configtest.go

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

2323
"go.opentelemetry.io/collector/component"
2424
"go.opentelemetry.io/collector/config"
25-
"go.opentelemetry.io/collector/config/configparser"
25+
"go.opentelemetry.io/collector/config/configmap"
2626
"go.opentelemetry.io/collector/config/configunmarshaler"
2727
"go.opentelemetry.io/collector/consumer/consumererror"
2828
)
@@ -33,7 +33,7 @@ var configFieldTagRegExp = regexp.MustCompile("^[a-z0-9][a-z0-9_]*$")
3333
// LoadConfig loads a config from file, and does NOT validate the configuration.
3434
func LoadConfig(fileName string, factories component.Factories) (*config.Config, error) {
3535
// Read yaml config from file
36-
cp, err := configparser.NewConfigMapFromFile(fileName)
36+
cp, err := configmap.NewConfigMapFromFile(fileName)
3737
if err != nil {
3838
return nil, err
3939
}

config/configunmarshaler/defaultunmarshaler.go

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

2424
"go.opentelemetry.io/collector/component"
2525
"go.opentelemetry.io/collector/config"
26-
"go.opentelemetry.io/collector/config/configparser"
26+
"go.opentelemetry.io/collector/config/configmap"
2727
)
2828

2929
// These are errors that can be returned by Unmarshal(). Note that error codes are not part
@@ -111,7 +111,7 @@ func NewDefault() ConfigUnmarshaler {
111111

112112
// Unmarshal the Config from a Parser.
113113
// After the config is unmarshaled, `Validate()` must be called to validate.
114-
func (*defaultUnmarshaler) Unmarshal(v *configparser.ConfigMap, factories component.Factories) (*config.Config, error) {
114+
func (*defaultUnmarshaler) Unmarshal(v *configmap.ConfigMap, factories component.Factories) (*config.Config, error) {
115115
var cfg config.Config
116116

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

210210
// Iterate over extensions and create a config for each.
211211
for key, value := range exts {
212-
componentConfig := configparser.NewConfigMapFromStringMap(value)
212+
componentConfig := configmap.NewConfigMapFromStringMap(value)
213213
expandEnvConfig(componentConfig)
214214

215215
// Decode the key into type and fullName components.
@@ -280,7 +280,7 @@ func unmarshalService(rawService serviceSettings) (config.Service, error) {
280280
}
281281

282282
// 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) {
283+
func LoadReceiver(componentConfig *configmap.ConfigMap, id config.ComponentID, factory component.ReceiverFactory) (config.Receiver, error) {
284284
// Create the default config for this receiver.
285285
receiverCfg := factory.CreateDefaultConfig()
286286
receiverCfg.SetIDName(id.Name())
@@ -301,7 +301,7 @@ func unmarshalReceivers(recvs map[string]map[string]interface{}, factories map[c
301301

302302
// Iterate over input map and create a config for each.
303303
for key, value := range recvs {
304-
componentConfig := configparser.NewConfigMapFromStringMap(value)
304+
componentConfig := configmap.NewConfigMapFromStringMap(value)
305305
expandEnvConfig(componentConfig)
306306

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

339339
// Iterate over Exporters and create a config for each.
340340
for key, value := range exps {
341-
componentConfig := configparser.NewConfigMapFromStringMap(value)
341+
componentConfig := configmap.NewConfigMapFromStringMap(value)
342342
expandEnvConfig(componentConfig)
343343

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

381381
// Iterate over processors and create a config for each.
382382
for key, value := range procs {
383-
componentConfig := configparser.NewConfigMapFromStringMap(value)
383+
componentConfig := configmap.NewConfigMapFromStringMap(value)
384384
expandEnvConfig(componentConfig)
385385

386386
// Decode the key into type and fullName components.
@@ -475,9 +475,9 @@ func parseIDNames(pipelineID config.ComponentID, componentType string, names []s
475475
return ret, nil
476476
}
477477

478-
// expandEnvConfig updates a configparser.ConfigMap with expanded values for all the values (simple, list or map value).
478+
// expandEnvConfig updates a configmap.ConfigMap with expanded values for all the values (simple, list or map value).
479479
// It does not expand the keys.
480-
func expandEnvConfig(v *configparser.ConfigMap) {
480+
func expandEnvConfig(v *configmap.ConfigMap) {
481481
for _, k := range v.AllKeys() {
482482
v.Set(k, expandStringValues(v.Get(k)))
483483
}
@@ -568,7 +568,7 @@ func expandEnv(s string) string {
568568
})
569569
}
570570

571-
func unmarshal(componentSection *configparser.ConfigMap, intoCfg interface{}) error {
571+
func unmarshal(componentSection *configmap.ConfigMap, intoCfg interface{}) error {
572572
if cu, ok := intoCfg.(config.Unmarshallable); ok {
573573
return cu.Unmarshal(componentSection)
574574
}

config/configunmarshaler/defaultunmarshaler_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525

2626
"go.opentelemetry.io/collector/component"
2727
"go.opentelemetry.io/collector/config"
28+
"go.opentelemetry.io/collector/config/configmap"
2829
"go.opentelemetry.io/collector/config/confignet"
29-
"go.opentelemetry.io/collector/config/configparser"
3030
"go.opentelemetry.io/collector/internal/testcomponents"
3131
)
3232

@@ -462,10 +462,10 @@ func TestLoadEmptyAllSections(t *testing.T) {
462462
}
463463

464464
func loadConfigFile(t *testing.T, fileName string, factories component.Factories) (*config.Config, error) {
465-
v, err := configparser.NewConfigMapFromFile(fileName)
465+
v, err := configmap.NewConfigMapFromFile(fileName)
466466
require.NoError(t, err)
467467

468-
// Unmarshal the config from the configparser.ConfigMap using the given factories.
468+
// Unmarshal the config from the configmap.ConfigMap using the given factories.
469469
return NewDefault().Unmarshal(v, factories)
470470
}
471471

config/configunmarshaler/unmarshaler.go

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

23-
// ConfigUnmarshaler is the interface that unmarshalls the collector configuration from the configparser.ConfigMap.
23+
// ConfigUnmarshaler is the interface that unmarshalls the collector configuration from the configmap.ConfigMap.
2424
type ConfigUnmarshaler interface {
2525
// Unmarshal the configuration from the given parser and factories.
26-
Unmarshal(v *configparser.ConfigMap, factories component.Factories) (*config.Config, error)
26+
Unmarshal(v *configmap.ConfigMap, factories component.Factories) (*config.Config, error)
2727
}

config/internal/configsource/manager.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
"gopkg.in/yaml.v2"
2828

29-
"go.opentelemetry.io/collector/config/configparser"
29+
"go.opentelemetry.io/collector/config/configmap"
3030
"go.opentelemetry.io/collector/config/experimental/configsource"
3131
"go.opentelemetry.io/collector/consumer/consumererror"
3232
)
@@ -173,7 +173,7 @@ type Manager struct {
173173
// NewManager creates a new instance of a Manager to be used to inject data from
174174
// ConfigSource objects into a configuration and watch for updates on the injected
175175
// data.
176-
func NewManager(_ *configparser.ConfigMap) (*Manager, error) {
176+
func NewManager(_ *configmap.ConfigMap) (*Manager, error) {
177177
// TODO: Config sources should be extracted for the config itself, need Factories for that.
178178

179179
return &Manager{
@@ -185,8 +185,8 @@ func NewManager(_ *configparser.ConfigMap) (*Manager, error) {
185185
// Resolve inspects the given config.Parser and resolves all config sources referenced
186186
// in the configuration, returning a config.Parser fully resolved. This must be called only
187187
// once per lifetime of a Manager object.
188-
func (m *Manager) Resolve(ctx context.Context, parser *configparser.ConfigMap) (*configparser.ConfigMap, error) {
189-
res := configparser.NewConfigMap()
188+
func (m *Manager) Resolve(ctx context.Context, parser *configmap.ConfigMap) (*configmap.ConfigMap, error) {
189+
res := configmap.NewConfigMap()
190190
allKeys := parser.AllKeys()
191191
for _, k := range allKeys {
192192
value, err := m.expandStringValues(ctx, parser.Get(k))
@@ -467,8 +467,8 @@ func parseCfgSrc(s string) (cfgSrcName, selector string, params interface{}, err
467467
selector = strings.Trim(parts[0], " ")
468468

469469
if len(parts) > 1 && len(parts[1]) > 0 {
470-
var cp *configparser.ConfigMap
471-
cp, err = configparser.NewConfigMapFromBuffer(bytes.NewReader([]byte(parts[1])))
470+
var cp *configmap.ConfigMap
471+
cp, err = configmap.NewConfigMapFromBuffer(bytes.NewReader([]byte(parts[1])))
472472
if err != nil {
473473
return
474474
}

config/internal/configsource/manager_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/stretchr/testify/assert"
2626
"github.com/stretchr/testify/require"
2727

28-
"go.opentelemetry.io/collector/config/configparser"
28+
"go.opentelemetry.io/collector/config/configmap"
2929
"go.opentelemetry.io/collector/config/experimental/configsource"
3030
)
3131

@@ -54,7 +54,7 @@ func TestConfigSourceManager_Simple(t *testing.T) {
5454
},
5555
}
5656

57-
cp := configparser.NewConfigMapFromStringMap(originalCfg)
57+
cp := configmap.NewConfigMapFromStringMap(originalCfg)
5858

5959
actualParser, err := manager.Resolve(ctx, cp)
6060
require.NoError(t, err)
@@ -107,7 +107,7 @@ func TestConfigSourceManager_ResolveErrors(t *testing.T) {
107107
require.NoError(t, err)
108108
manager.configSources = tt.configSourceMap
109109

110-
res, err := manager.Resolve(ctx, configparser.NewConfigMapFromStringMap(tt.config))
110+
res, err := manager.Resolve(ctx, configmap.NewConfigMapFromStringMap(tt.config))
111111
require.Error(t, err)
112112
require.Nil(t, res)
113113
require.NoError(t, manager.Close(ctx))
@@ -131,11 +131,11 @@ func TestConfigSourceManager_ArraysAndMaps(t *testing.T) {
131131
}
132132

133133
file := path.Join("testdata", "arrays_and_maps.yaml")
134-
cp, err := configparser.NewConfigMapFromFile(file)
134+
cp, err := configmap.NewConfigMapFromFile(file)
135135
require.NoError(t, err)
136136

137137
expectedFile := path.Join("testdata", "arrays_and_maps_expected.yaml")
138-
expectedParser, err := configparser.NewConfigMapFromFile(expectedFile)
138+
expectedParser, err := configmap.NewConfigMapFromFile(expectedFile)
139139
require.NoError(t, err)
140140

141141
actualParser, err := manager.Resolve(ctx, cp)
@@ -183,11 +183,11 @@ func TestConfigSourceManager_ParamsHandling(t *testing.T) {
183183
}
184184

185185
file := path.Join("testdata", "params_handling.yaml")
186-
cp, err := configparser.NewConfigMapFromFile(file)
186+
cp, err := configmap.NewConfigMapFromFile(file)
187187
require.NoError(t, err)
188188

189189
expectedFile := path.Join("testdata", "params_handling_expected.yaml")
190-
expectedParser, err := configparser.NewConfigMapFromFile(expectedFile)
190+
expectedParser, err := configmap.NewConfigMapFromFile(expectedFile)
191191
require.NoError(t, err)
192192

193193
actualParser, err := manager.Resolve(ctx, cp)
@@ -221,7 +221,7 @@ func TestConfigSourceManager_WatchForUpdate(t *testing.T) {
221221
},
222222
}
223223

224-
cp := configparser.NewConfigMapFromStringMap(originalCfg)
224+
cp := configmap.NewConfigMapFromStringMap(originalCfg)
225225
_, err = manager.Resolve(ctx, cp)
226226
require.NoError(t, err)
227227

@@ -277,7 +277,7 @@ func TestConfigSourceManager_MultipleWatchForUpdate(t *testing.T) {
277277
},
278278
}
279279

280-
cp := configparser.NewConfigMapFromStringMap(originalCfg)
280+
cp := configmap.NewConfigMapFromStringMap(originalCfg)
281281
_, err = manager.Resolve(ctx, cp)
282282
require.NoError(t, err)
283283

@@ -328,11 +328,11 @@ func TestConfigSourceManager_EnvVarHandling(t *testing.T) {
328328
}
329329

330330
file := path.Join("testdata", "envvar_cfgsrc_mix.yaml")
331-
cp, err := configparser.NewConfigMapFromFile(file)
331+
cp, err := configmap.NewConfigMapFromFile(file)
332332
require.NoError(t, err)
333333

334334
expectedFile := path.Join("testdata", "envvar_cfgsrc_mix_expected.yaml")
335-
expectedParser, err := configparser.NewConfigMapFromFile(expectedFile)
335+
expectedParser, err := configmap.NewConfigMapFromFile(expectedFile)
336336
require.NoError(t, err)
337337

338338
actualParser, err := manager.Resolve(ctx, cp)

internal/testcomponents/example_exporter.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
"go.opentelemetry.io/collector/component"
2121
"go.opentelemetry.io/collector/config"
22-
"go.opentelemetry.io/collector/config/configparser"
22+
"go.opentelemetry.io/collector/config/configmap"
2323
"go.opentelemetry.io/collector/consumer"
2424
"go.opentelemetry.io/collector/exporter/exporterhelper"
2525
"go.opentelemetry.io/collector/model/pdata"
@@ -38,7 +38,7 @@ type ExampleExporter struct {
3838
}
3939

4040
// Unmarshal a viper data into the config struct
41-
func (cfg *ExampleExporter) Unmarshal(componentParser *configparser.ConfigMap) error {
41+
func (cfg *ExampleExporter) Unmarshal(componentParser *configmap.ConfigMap) error {
4242
return componentParser.UnmarshalExact(cfg)
4343
}
4444

receiver/otlpreceiver/config.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"go.opentelemetry.io/collector/config"
2121
"go.opentelemetry.io/collector/config/configgrpc"
2222
"go.opentelemetry.io/collector/config/confighttp"
23-
"go.opentelemetry.io/collector/config/configparser"
23+
"go.opentelemetry.io/collector/config/configmap"
2424
)
2525

2626
const (
@@ -56,7 +56,7 @@ func (cfg *Config) Validate() error {
5656
}
5757

5858
// Unmarshal a config.Parser into the config struct.
59-
func (cfg *Config) Unmarshal(componentParser *configparser.ConfigMap) error {
59+
func (cfg *Config) Unmarshal(componentParser *configmap.ConfigMap) error {
6060
if componentParser == nil || len(componentParser.AllKeys()) == 0 {
6161
return fmt.Errorf("empty config for OTLP receiver")
6262
}
@@ -66,7 +66,7 @@ func (cfg *Config) Unmarshal(componentParser *configparser.ConfigMap) error {
6666
return err
6767
}
6868

69-
// next manually search for protocols in the configparser.ConfigMap, if a protocol is not present it means it is disable.
69+
// next manually search for protocols in the configmap.ConfigMap, if a protocol is not present it means it is disable.
7070
protocols, err := componentParser.Sub(protocolsFieldName)
7171
if err != nil {
7272
return err

0 commit comments

Comments
 (0)