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 configmapprovider package, replace with mapconverter #5167

Merged
merged 1 commit into from
Apr 8, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

### 🚩 Deprecations 🚩

- Deprecate configmapprovider package, replace with mapconverter (#5167)

### 💡 Enhancements 💡

- OTLP HTTP receiver will use HTTP/2 over TLS if client supports it (#5190)
Expand Down
26 changes: 26 additions & 0 deletions config/configmapprovider/deprecated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package configmapprovider // import "go.opentelemetry.io/collector/config/configmapprovider"

import (
"go.opentelemetry.io/collector/config/mapconverter/expandmapconverter"
"go.opentelemetry.io/collector/config/mapconverter/overwritepropertiesmapconverter"
)

// Deprecated: [v0.49.0] use expandmapconverter.New.
var NewExpandConverter = expandmapconverter.New

// Deprecated: [v0.49.0] use overwritepropertiesmapconverter.New.
var NewOverwritePropertiesConverter = overwritepropertiesmapconverter.New
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package configmapprovider // import "go.opentelemetry.io/collector/config/configmapprovider"
package expandmapconverter // import "go.opentelemetry.io/collector/config/mapconverter/expandmapconverter"

import (
"context"
Expand All @@ -21,10 +21,10 @@ import (
"go.opentelemetry.io/collector/config"
)

// NewExpandConverter returns a service.ConfigMapConverterFunc, that expands all environment variables for a given config.Map.
// New returns a config.MapConverterFunc, that expands all environment variables for a given config.Map.
//
// Notice: This API is experimental.
codeboten marked this conversation as resolved.
Show resolved Hide resolved
func NewExpandConverter() config.MapConverterFunc {
func New() config.MapConverterFunc {
return func(_ context.Context, cfgMap *config.Map) error {
for _, k := range cfgMap.AllKeys() {
cfgMap.Set(k, expandStringValues(cfgMap.Get(k)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package configmapprovider
package expandmapconverter

import (
"context"
Expand Down Expand Up @@ -56,7 +56,7 @@ func TestNewExpandConverter(t *testing.T) {
require.NoError(t, err, "Unable to get config")

// Test that expanded configs are the same with the simple config with no env vars.
require.NoError(t, NewExpandConverter()(context.Background(), cfgMap))
require.NoError(t, New()(context.Background(), cfgMap))
assert.Equal(t, expectedCfgMap.ToStringMap(), cfgMap.ToStringMap())
})
}
Expand All @@ -75,7 +75,7 @@ func TestNewExpandConverter_EscapedMaps(t *testing.T) {
"recv": "$MAP_VALUE",
}},
)
require.NoError(t, NewExpandConverter()(context.Background(), cfgMap))
require.NoError(t, New()(context.Background(), cfgMap))

expectedMap := map[string]interface{}{
"test_string_map": map[string]interface{}{
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestNewExpandConverter_EscapedEnvVars(t *testing.T) {
// escaped $ alone
"recv.7": "$",
}}
require.NoError(t, NewExpandConverter()(context.Background(), cfgMap))
require.NoError(t, New()(context.Background(), cfgMap))
assert.Equal(t, expectedMap, cfgMap.ToStringMap())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package configmapprovider // import "go.opentelemetry.io/collector/config/configmapprovider"
package overwritepropertiesmapconverter // import "go.opentelemetry.io/collector/config/mapconverter/overwritepropertiesmapconverter"

import (
"bytes"
Expand All @@ -25,13 +25,13 @@ import (
"go.opentelemetry.io/collector/config"
)

// NewOverwritePropertiesConverter returns a config.MapConverterFunc, that overrides all the given properties into the
// New returns a config.MapConverterFunc, that overrides all the given properties into the
// input map.
//
// Properties must follow the Java properties format, key-value list separated by equal sign with a "."
// as key delimiter.
// ["processors.batch.timeout=2s", "processors.batch/foo.timeout=3s"]
func NewOverwritePropertiesConverter(properties []string) config.MapConverterFunc {
func New(properties []string) config.MapConverterFunc {
return func(_ context.Context, cfgMap *config.Map) error {
return convert(properties, cfgMap)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package configmapprovider
package overwritepropertiesmapconverter
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved

import (
"context"
Expand All @@ -25,7 +25,7 @@ import (
)

func TestOverwritePropertiesConverter_Empty(t *testing.T) {
pmp := NewOverwritePropertiesConverter(nil)
pmp := New(nil)
cfgMap := config.NewMapFromStringMap(map[string]interface{}{"foo": "bar"})
assert.NoError(t, pmp(context.Background(), cfgMap))
assert.Equal(t, map[string]interface{}{"foo": "bar"}, cfgMap.ToStringMap())
Expand All @@ -39,7 +39,7 @@ func TestOverwritePropertiesConverter(t *testing.T) {
"exporters.kafka.brokers=foo:9200,foo2:9200",
}

pmp := NewOverwritePropertiesConverter(props)
pmp := New(props)
cfgMap := config.NewMap()
require.NoError(t, pmp(context.Background(), cfgMap))
keys := cfgMap.AllKeys()
Expand All @@ -51,7 +51,7 @@ func TestOverwritePropertiesConverter(t *testing.T) {
}

func TestOverwritePropertiesConverter_InvalidProperty(t *testing.T) {
pmp := NewOverwritePropertiesConverter([]string{"=2s"})
pmp := New([]string{"=2s"})
cfgMap := config.NewMap()
assert.Error(t, pmp(context.Background(), cfgMap))
}
7 changes: 4 additions & 3 deletions service/config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configmapprovider"
"go.opentelemetry.io/collector/config/configunmarshaler"
"go.opentelemetry.io/collector/config/experimental/configsource"
"go.opentelemetry.io/collector/config/mapconverter/expandmapconverter"
"go.opentelemetry.io/collector/config/mapconverter/overwritepropertiesmapconverter"
"go.opentelemetry.io/collector/config/mapprovider/envmapprovider"
"go.opentelemetry.io/collector/config/mapprovider/filemapprovider"
"go.opentelemetry.io/collector/config/mapprovider/yamlmapprovider"
Expand Down Expand Up @@ -108,8 +109,8 @@ func MustNewDefaultConfigProvider(configLocations []string, properties []string)
configLocations,
makeConfigMapProviderMap(filemapprovider.New(), envmapprovider.New(), yamlmapprovider.New()),
[]config.MapConverterFunc{
configmapprovider.NewOverwritePropertiesConverter(properties),
configmapprovider.NewExpandConverter(),
overwritepropertiesmapconverter.New(properties),
expandmapconverter.New(),
},
configunmarshaler.NewDefault())
}
Expand Down