Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate confmap.Received.AsMap in favor of confmap.Received.AsConf #5465

Merged
merged 1 commit into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Package `filemapprovider` -> `fileprovider`
- Package `overwritepropertiesmapconverter` -> `overwritepropertiesconverter`
- Deprecate `component.ExtensionDefaultConfigFunc` in favor of `component.ExtensionCreateDefaultConfigFunc` (#5451)
- Deprecate `confmap.Received.AsMap` in favor of `confmap.Received.AsConf` (#5465)

### 💡 Enhancements 💡

Expand Down
2 changes: 1 addition & 1 deletion confmap/confmaptest/configtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ func LoadConf(fileName string) (*confmap.Conf, error) {
if err != nil {
return nil, err
}
return ret.AsMap()
return ret.AsConf()
}
9 changes: 7 additions & 2 deletions confmap/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@ func NewRetrieved(rawConf map[string]interface{}, opts ...RetrievedOption) (Retr
return Retrieved{conf: NewFromStringMap(rawConf), closeFunc: set.closeFunc}, nil
}

// AsMap returns the retrieved configuration parsed as a Map.
func (r Retrieved) AsMap() (*Conf, error) {
// Deprecated: [v0.53.0] Use AsConf.
func (r *Retrieved) AsMap() (*Conf, error) {
return r.AsConf()
}

// AsConf returns the retrieved configuration parsed as a Conf.
func (r Retrieved) AsConf() (*Conf, error) {
return r.conf, nil
}

Expand Down
2 changes: 1 addition & 1 deletion confmap/provider/envprovider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestEnv(t *testing.T) {
env := New()
ret, err := env.Retrieve(context.Background(), envSchemePrefix+envName, nil)
require.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
assert.NoError(t, err)
expectedMap := confmap.NewFromStringMap(map[string]interface{}{
"processors::batch": nil,
Expand Down
4 changes: 2 additions & 2 deletions confmap/provider/fileprovider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestRelativePath(t *testing.T) {
fp := New()
ret, err := fp.Retrieve(context.Background(), fileSchemePrefix+filepath.Join("testdata", "default-config.yaml"), nil)
require.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
assert.NoError(t, err)
expectedMap := confmap.NewFromStringMap(map[string]interface{}{
"processors::batch": nil,
Expand All @@ -78,7 +78,7 @@ func TestAbsolutePath(t *testing.T) {
fp := New()
ret, err := fp.Retrieve(context.Background(), fileSchemePrefix+absolutePath(t, filepath.Join("testdata", "default-config.yaml")), nil)
require.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
assert.NoError(t, err)
expectedMap := confmap.NewFromStringMap(map[string]interface{}{
"processors::batch": nil,
Expand Down
4 changes: 2 additions & 2 deletions confmap/provider/internal/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
func TestNewRetrievedFromYAML(t *testing.T) {
ret, err := NewRetrievedFromYAML([]byte{})
require.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
require.NoError(t, err)
assert.Equal(t, confmap.New(), retMap)
assert.NoError(t, ret.Close(context.Background()))
Expand All @@ -38,7 +38,7 @@ func TestNewRetrievedFromYAMLWithOptions(t *testing.T) {
want := errors.New("my error")
ret, err := NewRetrievedFromYAML([]byte{}, confmap.WithRetrievedClose(func(context.Context) error { return want }))
require.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
require.NoError(t, err)
assert.Equal(t, confmap.New(), retMap)
assert.Equal(t, want, ret.Close(context.Background()))
Expand Down
10 changes: 5 additions & 5 deletions confmap/provider/yamlprovider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestOneValue(t *testing.T) {
sp := New()
ret, err := sp.Retrieve(context.Background(), "yaml:processors::batch::timeout: 2s", nil)
assert.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{
"processors": map[string]interface{}{
Expand All @@ -55,7 +55,7 @@ func TestNamedComponent(t *testing.T) {
sp := New()
ret, err := sp.Retrieve(context.Background(), "yaml:processors::batch/foo::timeout: 3s", nil)
assert.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{
"processors": map[string]interface{}{
Expand All @@ -71,7 +71,7 @@ func TestMapEntry(t *testing.T) {
sp := New()
ret, err := sp.Retrieve(context.Background(), "yaml:processors: {batch/foo::timeout: 3s, batch::timeout: 2s}", nil)
assert.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{
"processors": map[string]interface{}{
Expand All @@ -90,7 +90,7 @@ func TestNewLine(t *testing.T) {
sp := New()
ret, err := sp.Retrieve(context.Background(), "yaml:processors::batch/foo::timeout: 3s\nprocessors::batch::timeout: 2s", nil)
assert.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{
"processors": map[string]interface{}{
Expand All @@ -109,7 +109,7 @@ func TestDotSeparator(t *testing.T) {
sp := New()
ret, err := sp.Retrieve(context.Background(), "yaml:processors.batch.timeout: 4s", nil)
assert.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{"processors.batch.timeout": "4s"}, retMap.ToStringMap())
assert.NoError(t, sp.Shutdown(context.Background()))
Expand Down
4 changes: 2 additions & 2 deletions confmap/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
func TestNewRetrieved(t *testing.T) {
ret, err := NewRetrieved(nil)
require.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
require.NoError(t, err)
assert.Equal(t, New(), retMap)
assert.NoError(t, ret.Close(context.Background()))
Expand All @@ -36,7 +36,7 @@ func TestNewRetrievedWithOptions(t *testing.T) {
want := errors.New("my error")
ret, err := NewRetrieved(nil, WithRetrievedClose(func(context.Context) error { return want }))
require.NoError(t, err)
retMap, err := ret.AsMap()
retMap, err := ret.AsConf()
require.NoError(t, err)
assert.Equal(t, New(), retMap)
assert.Equal(t, want, ret.Close(context.Background()))
Expand Down
2 changes: 1 addition & 1 deletion confmap/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (mr *Resolver) Resolve(ctx context.Context) (*Conf, error) {
if err != nil {
return nil, err
}
retCfgMap, err := ret.AsMap()
retCfgMap, err := ret.AsConf()
if err != nil {
return nil, err
}
Expand Down