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

Add Scheme to MapProvider interface #5068

Merged
merged 2 commits into from
Apr 4, 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
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
}