Skip to content

Commit

Permalink
Fix broken code due to renaming of CustomUnmarshable to Unmarshallable
Browse files Browse the repository at this point in the history
  • Loading branch information
emaderer committed Aug 17, 2021
1 parent de03f5e commit e09a9e3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 28 deletions.
5 changes: 0 additions & 5 deletions internal/configprovider/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ import (
"go.opentelemetry.io/collector/config/experimental/configsource"
)

// WatcherNotSupported is the a watcher function that always returns ErrWatcherNotSupported.
func WatcherNotSupported() error {
return configsource.ErrWatcherNotSupported
}

type retrieved struct {
value interface{}
watchForUpdateFn func() error
Expand Down
4 changes: 0 additions & 4 deletions internal/configprovider/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@ func (m *Manager) WatchForUpdate() error {

err := watcher.WatchForUpdate()
switch {
case errors.Is(err, configsource.ErrWatcherNotSupported):
// The watcher for the retrieved value is not supported, nothing to
// do, just exit from the goroutine.
return
case errors.Is(err, configsource.ErrSessionClosed):
// The Session from which this watcher was retrieved is being closed.
// There is no error to report, just exit from the goroutine.
Expand Down
4 changes: 2 additions & 2 deletions internal/configsource/envvarconfigsource/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (e *envVarSession) Retrieve(_ context.Context, selector string, params inte
value, ok := os.LookupEnv(selector)
if ok {
// Environment variable found, everything is done.
return configprovider.NewRetrieved(value, configprovider.WatcherNotSupported), nil
return configprovider.NewRetrieved(value, func() error {return nil}), nil
}

defaultValue, ok := e.defaults[selector]
Expand All @@ -70,7 +70,7 @@ func (e *envVarSession) Retrieve(_ context.Context, selector string, params inte
}
}

return configprovider.NewRetrieved(defaultValue, configprovider.WatcherNotSupported), nil
return configprovider.NewRetrieved(defaultValue, func() error {return nil}), nil
}

func (e *envVarSession) RetrieveEnd(context.Context) error {
Expand Down
6 changes: 3 additions & 3 deletions internal/configsource/includeconfigsource/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (is *includeSession) Retrieve(_ context.Context, selector string, params in
}

if !is.WatchFiles {
return configprovider.NewRetrieved(buf.Bytes(), configprovider.WatcherNotSupported), nil
return configprovider.NewRetrieved(buf.Bytes(), func() error {return nil}), nil
}

watchForUpdateFn, err := is.watchFile(selector)
Expand Down Expand Up @@ -91,10 +91,10 @@ func newSession(config Config) *includeSession {
}

func (is *includeSession) watchFile(file string) (func() error, error) {
watchForUpdateFn := configprovider.WatcherNotSupported
var watchForUpdateFn func() error
if _, watched := is.watchedFiles[file]; watched {
// This file is already watched another watch function is not needed.
return watchForUpdateFn, nil
return func() error {return nil}, nil
}

if is.watcher == nil {
Expand Down
24 changes: 10 additions & 14 deletions internal/configsource/vaultconfigsource/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ type vaultSession struct {
var _ configsource.Session = (*vaultSession)(nil)

func (v *vaultSession) Retrieve(_ context.Context, selector string, _ interface{}) (configsource.Retrieved, error) {
// By default assume that watcher is not supported. The exception will be the first
// value read from the vault secret.
watchForUpdateFn := watcherNotSupported

var watchForUpdateFn func() error
if v.secret == nil {
if err := v.readSecret(); err != nil {
return nil, err
Expand Down Expand Up @@ -210,20 +207,23 @@ func (v *vaultSession) buildPollingWatcher() (func() error, error) {
// added to the secret.
mdValue := v.secret.Data["metadata"]
if mdValue == nil || !strings.Contains(v.path, "/data/") {
v.logger.Warn("Missing metadata to create polling watcher for vault config source", zap.String("path", v.path))
return watcherNotSupported, nil
msg := "Missing metadata to create polling watcher for vault config source"
v.logger.Warn(msg, zap.String("path", v.path))
return func() error {return errors.New(msg)}, nil
}

mdMap, ok := mdValue.(map[string]interface{})
if !ok {
v.logger.Warn("Metadata not in the expected format to create polling watcher for vault config source", zap.String("path", v.path))
return watcherNotSupported, nil
msg := "Metadata not in the expected format to create polling watcher for vault config source"
v.logger.Warn(msg, zap.String("path", v.path))
return func() error {return errors.New(msg)}, nil
}

originalVersion := v.extractVersionMetadata(mdMap, "created_time", "version")
if originalVersion == nil {
v.logger.Warn("Failed to extract version metadata to create to create polling watcher for vault config source", zap.String("path", v.path))
return watcherNotSupported, nil
msg := "Failed to extract version metadata to create to create polling watcher for vault config source"
v.logger.Warn(msg, zap.String("path", v.path))
return func() error {return errors.New(msg)}, nil
}

watcherFn := func() error {
Expand Down Expand Up @@ -316,7 +316,3 @@ func traverseToKey(data map[string]interface{}, key string) interface{} {
}
}
}

func watcherNotSupported() error {
return configsource.ErrWatcherNotSupported
}

0 comments on commit e09a9e3

Please sign in to comment.