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

Move MapProvider interfaces to config/configmapprovider package #4337

Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Force usage of `extensionhelper.NewFactory` to implement `component.ExtensionFactory` (#4338)
- Move `service/parserprovider` package to `config/configmapprovider` (#4206)
- Remove `config.Pipeline.Name` (#4326)
- Move `config.Mapprovider`, `config.WatchableRetrieved` and `config.Retrieved` interfaces to `config/configmapprovider` package (#4337)
- Remove `config.Pipeline.InputDataType` (#4343)

## v0.38.0 Beta
Expand Down
6 changes: 2 additions & 4 deletions config/configmapprovider/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@

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

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

// NewDefaultMapProvider returns the default config.MapProvider, and it creates configuration from a file
// NewDefaultMapProvider returns the default MapProvider, and it creates configuration from a file
// defined by the given configFile and overwrites fields using properties.
func NewDefaultMapProvider(configFileName string, properties []string) config.MapProvider {
func NewDefaultMapProvider(configFileName string, properties []string) MapProvider {
return NewExpandMapProvider(
NewMergeMapProvider(
NewFileMapProvider(configFileName),
Expand Down
12 changes: 5 additions & 7 deletions config/configmapprovider/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,21 @@ package configmapprovider // import "go.opentelemetry.io/collector/config/config
import (
"context"
"os"

"go.opentelemetry.io/collector/config"
)

type expandMapProvider struct {
base config.MapProvider
base MapProvider
}

// NewExpandMapProvider returns a config.MapProvider, that expands all environment variables for a
// config.Map provided by the given config.MapProvider.
func NewExpandMapProvider(base config.MapProvider) config.MapProvider {
// NewExpandMapProvider returns a MapProvider, that expands all environment variables for a
// config.Map provided by the given MapProvider.
func NewExpandMapProvider(base MapProvider) MapProvider {
return &expandMapProvider{
base: base,
}
}

func (emp *expandMapProvider) Retrieve(ctx context.Context) (config.Retrieved, error) {
func (emp *expandMapProvider) Retrieve(ctx context.Context) (Retrieved, error) {
retr, err := emp.base.Retrieve(ctx)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions config/configmapprovider/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ type fileMapProvider struct {
fileName string
}

// NewFileMapProvider returns a new config.MapProvider that reads the configuration from the given file.
func NewFileMapProvider(fileName string) config.MapProvider {
// NewFileMapProvider returns a new MapProvider that reads the configuration from the given file.
func NewFileMapProvider(fileName string) MapProvider {
return &fileMapProvider{
fileName: fileName,
}
}

func (fmp *fileMapProvider) Retrieve(context.Context) (config.Retrieved, error) {
func (fmp *fileMapProvider) Retrieve(context.Context) (Retrieved, error) {
if fmp.fileName == "" {
return nil, errors.New("config file not specified")
}
Expand Down
6 changes: 3 additions & 3 deletions config/configmapprovider/inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ type inMemoryMapProvider struct {
buf io.Reader
}

// NewInMemoryMapProvider returns a new config.MapProvider that reads the configuration, from the provided buffer, as YAML.
func NewInMemoryMapProvider(buf io.Reader) config.MapProvider {
// NewInMemoryMapProvider returns a new MapProvider that reads the configuration, from the provided buffer, as YAML.
func NewInMemoryMapProvider(buf io.Reader) MapProvider {
return &inMemoryMapProvider{buf: buf}
}

func (inp *inMemoryMapProvider) Retrieve(context.Context) (config.Retrieved, error) {
func (inp *inMemoryMapProvider) Retrieve(context.Context) (Retrieved, error) {
cfg, err := config.NewMapFromBuffer(inp.buf)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions config/configmapprovider/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ import (
// TODO: Add support to "merge" watchable interface.

type mergeMapProvider struct {
providers []config.MapProvider
providers []MapProvider
}

// NewMergeMapProvider returns a config.MapProvider, that merges the result from multiple config.MapProvider.
// NewMergeMapProvider returns a MapProvider, that merges the result from multiple MapProvider.
//
// The ConfigMaps are merged in the given order, by merging all of them in order into an initial empty map.
func NewMergeMapProvider(ps ...config.MapProvider) config.MapProvider {
func NewMergeMapProvider(ps ...MapProvider) MapProvider {
return &mergeMapProvider{providers: ps}
}

func (mp *mergeMapProvider) Retrieve(ctx context.Context) (config.Retrieved, error) {
func (mp *mergeMapProvider) Retrieve(ctx context.Context) (Retrieved, error) {
retCfgMap := config.NewMap()
for _, p := range mp.providers {
retr, err := p.Retrieve(ctx)
Expand Down
2 changes: 1 addition & 1 deletion config/configmapprovider/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type errProvider struct {
err error
}

func (epl *errProvider) Retrieve(context.Context) (config.Retrieved, error) {
func (epl *errProvider) Retrieve(context.Context) (Retrieved, error) {
if epl.err == nil {
return &simpleRetrieved{confMap: config.NewMap()}, nil
}
Expand Down
6 changes: 3 additions & 3 deletions config/configmapprovider/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ type propertiesMapProvider struct {
properties []string
}

// NewPropertiesMapProvider returns a config.MapProvider, that provides a config.Map from the given properties.
// NewPropertiesMapProvider returns a MapProvider, that provides a config.Map from the given properties.
//
// 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 NewPropertiesMapProvider(properties []string) config.MapProvider {
func NewPropertiesMapProvider(properties []string) MapProvider {
return &propertiesMapProvider{
properties: properties,
}
}

func (pmp *propertiesMapProvider) Retrieve(context.Context) (config.Retrieved, error) {
func (pmp *propertiesMapProvider) Retrieve(context.Context) (Retrieved, error) {
if len(pmp.properties) == 0 {
return &simpleRetrieved{confMap: config.NewMap()}, nil
}
Expand Down
6 changes: 4 additions & 2 deletions config/provider.go → config/configmapprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

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

import (
"context"

"go.opentelemetry.io/collector/config"
)

// MapProvider is an interface that helps providing configuration's parser.
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -35,7 +37,7 @@ type MapProvider interface {
// Retrieved holds the result of a call to the Retrieve method of a Session object.
type Retrieved interface {
// Get returns the Map.
Get() *Map
Get() *config.Map
}

// WatchableRetrieved is an extension for Retrieved that if implemented,
Expand Down
5 changes: 3 additions & 2 deletions service/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ 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/extension/ballastextension"
Expand Down Expand Up @@ -194,7 +195,7 @@ func (col *Collector) setupConfigurationComponents(ctx context.Context) error {
}

// If the retrieved value is watchable start a goroutine watching for updates.
if watchable, ok := ret.(config.WatchableRetrieved); ok {
if watchable, ok := ret.(configmapprovider.WatchableRetrieved); ok {
go col.watchForConfigUpdates(ctx, watchable)
}

Expand Down Expand Up @@ -281,7 +282,7 @@ func (col *Collector) reloadService(ctx context.Context) error {
return nil
}

func (col *Collector) watchForConfigUpdates(ctx context.Context, watchable config.WatchableRetrieved) {
func (col *Collector) watchForConfigUpdates(ctx context.Context, watchable configmapprovider.WatchableRetrieved) {
err := watchable.WatchForUpdate()
if errors.Is(err, configsource.ErrSessionClosed) {
// This is the case of shutdown of the whole collector server, nothing to do.
Expand Down
5 changes: 2 additions & 3 deletions service/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configmapprovider"
"go.opentelemetry.io/collector/config/configunmarshaler"
"go.opentelemetry.io/collector/internal/testutil"
Expand Down Expand Up @@ -266,7 +265,7 @@ type errParserLoader struct {
err error
}

func (epl *errParserLoader) Retrieve(_ context.Context) (config.Retrieved, error) {
func (epl *errParserLoader) Retrieve(_ context.Context) (configmapprovider.Retrieved, error) {
return nil, epl.err
}

Expand All @@ -282,7 +281,7 @@ func TestCollector_reloadService(t *testing.T) {

tests := []struct {
name string
parserProvider config.MapProvider
parserProvider configmapprovider.MapProvider
service *service
}{
{
Expand Down
5 changes: 3 additions & 2 deletions service/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configmapprovider"
"go.opentelemetry.io/collector/config/configunmarshaler"
)

Expand Down Expand Up @@ -62,8 +63,8 @@ type CollectorSettings struct {
// If it is not provided a default provider is used. The default provider loads the configuration
// from a config file define by the --config command line flag and overrides component's configuration
// properties supplied via --set command line flag.
// If the provider is config.WatchableRetrieved, collector may reload the configuration upon error.
ConfigMapProvider config.MapProvider
// If the provider is configmapprovider.WatchableRetrieved, collector may reload the configuration upon error.
ConfigMapProvider configmapprovider.MapProvider

// ConfigUnmarshaler unmarshalls the configuration's Parser into the service configuration.
// If it is not provided a default unmarshaler is used.
Expand Down