Skip to content

Commit

Permalink
Add Scheme to MapProvider interface (open-telemetry#5068)
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>

Co-authored-by: Alex Boten <aboten@lightstep.com>
  • Loading branch information
bogdandrutu and Alex Boten authored Apr 4, 2022
1 parent 46e9040 commit 1c3be5d
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 @@ -7,6 +7,7 @@
- Remove deprecated structs/funcs from previous versions (#5131)
- Do not set TraceProvider to global otel (#5138)
- Remove deprecated funcs from otlpgrpc (#5144)
- Add Scheme to MapProvider interface (#5068)

### 🚩 Deprecations 🚩

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, uri 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, uri string, _ config.Watcher
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, uri string, _ config.Watcher
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, uri string, _ config.WatcherFu
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 1c3be5d

Please sign in to comment.