Skip to content

Commit

Permalink
Deprecate configmapprovider package, replace with mapconverter
Browse files Browse the repository at this point in the history
The new `config/mapconverter` has the same structure as the `config/mapprovider` so it is consistent.

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu committed Apr 7, 2022
1 parent 620c88c commit d49e6f8
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 14 deletions.
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: use expandmapconverter.New.
var NewExpandConverter = expandmapconverter.New

// Deprecated: 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/configmapprovider"

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.
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/configmapprovider"

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

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))
}

0 comments on commit d49e6f8

Please sign in to comment.