Skip to content

Commit

Permalink
Add Scheme to MapProvider interface
Browse files Browse the repository at this point in the history
This is another required step in order to support configuring map providers via the Builder.

Updates open-telemetry#4759

This is a breaking change, since adds a new func to an interface. It is hard to make this backwards compatible, and would like to move forward with this exception.

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu committed Mar 23, 2022
1 parent 89da10b commit 19cbd13
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### 🛑 Breaking changes 🛑

- Add Scheme to MapProvider interface (#5068)
- Remove deprecated `consumerhelper` package (#5028)
- Remove pdata `InternalRep` deprecated funcs (#5018)
- Remove service/defaultcomponents deprecated package (#5019)
Expand Down
3 changes: 3 additions & 0 deletions config/mapprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ type MapProvider interface {
// Should never be called concurrently with itself or with Shutdown.
Retrieve(ctx context.Context, location string, watcher WatcherFunc) (Retrieved, error)

// Scheme returns the location scheme used by Retrieve.
Scheme() string

// Shutdown signals that the configuration for which this Provider was used to
// retrieve values is no longer in use and the Provider should close and release
// any resources that it may have created.
Expand Down
4 changes: 4 additions & 0 deletions config/mapprovider/envmapprovider/mapprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (emp *mapProvider) Retrieve(_ context.Context, location string, _ config.Wa
return config.Retrieved{Map: config.NewMapFromStringMap(data)}, nil
}

func (*mapProvider) Scheme() string {
return schemeName
}

func (*mapProvider) Shutdown(context.Context) error {
return nil
}
4 changes: 4 additions & 0 deletions config/mapprovider/filemapprovider/mapprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func (fmp *mapProvider) Retrieve(_ context.Context, location string, _ config.Wa
return config.Retrieved{Map: config.NewMapFromStringMap(data)}, nil
}

func (*mapProvider) Scheme() string {
return schemeName
}

func (*mapProvider) Shutdown(context.Context) error {
return nil
}
4 changes: 4 additions & 0 deletions config/mapprovider/yamlmapprovider/mapprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (s *mapProvider) Retrieve(_ context.Context, location string, _ config.Watc
return config.Retrieved{Map: config.NewMapFromStringMap(data)}, nil
}

func (*mapProvider) Scheme() string {
return schemeName
}

func (s *mapProvider) Shutdown(context.Context) error {
return nil
}
14 changes: 9 additions & 5 deletions service/config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ func MustNewConfigProvider(
func MustNewDefaultConfigProvider(configLocations []string, properties []string) ConfigProvider {
return MustNewConfigProvider(
configLocations,
map[string]config.MapProvider{
"file": filemapprovider.New(),
"env": envmapprovider.New(),
"yaml": yamlmapprovider.New(),
},
makeConfigMapProviderMap(filemapprovider.New(), envmapprovider.New(), yamlmapprovider.New()),
[]config.MapConverterFunc{
configmapprovider.NewOverwritePropertiesConverter(properties),
configmapprovider.NewExpandConverter(),
Expand Down Expand Up @@ -222,3 +218,11 @@ func (cm *configProvider) mergeRetrieve(ctx context.Context) (*config.Retrieved,
},
}, nil
}

func makeConfigMapProviderMap(providers ...config.MapProvider) map[string]config.MapProvider {
ret := make(map[string]config.MapProvider, len(providers))
for _, provider := range providers {
ret[provider.Scheme()] = provider
}
return ret
}

0 comments on commit 19cbd13

Please sign in to comment.