Skip to content

Commit c4108c1

Browse files
authored
Refine configsource interface (#2821)
* Add a few refinements to configsource interface * Small re-wording. * Remove function type. * Remove WatchableRetrieved and add an error instead * Add ErrWatcherNotSupported to WatchForUpdate function * Fix typo
1 parent cd954be commit c4108c1

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

config/internal/configsource/component.go

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,22 @@ import (
2121

2222
// ErrSessionClosed is returned by WatchForUpdate functions when its parent Session
2323
// object is closed.
24+
// This error can be wrapped with additional information. Callers trying to identify this
25+
// specific error must use errors.Is.
2426
var ErrSessionClosed = errors.New("parent session was closed")
2527

28+
// ErrValueUpdated is returned by WatchForUpdate functions when the value being watched
29+
// was changed or expired and needs to be retrieved again.
30+
// This error can be wrapped with additional information. Callers trying to identify this
31+
// specific error must use errors.Is.
32+
var ErrValueUpdated = errors.New("configuration must retrieve the updated value")
33+
34+
// ErrWatcherNotSupported is returned by WatchForUpdate functions when the configuration
35+
// source can't watch for updates on the value.
36+
// This error can be wrapped with additional information. Callers trying to identify this
37+
// specific error must use errors.Is.
38+
var ErrWatcherNotSupported = errors.New("value watcher is not supported")
39+
2640
// ConfigSource is the interface to be implemented by objects used by the collector
2741
// to retrieve external configuration information.
2842
type ConfigSource interface {
@@ -67,21 +81,29 @@ type Session interface {
6781
}
6882

6983
// Retrieved holds the result of a call to the Retrieve method of a Session object.
70-
type Retrieved struct {
84+
type Retrieved interface {
7185
// Value is the retrieved data that will be injected on the configuration.
72-
Value interface{}
73-
// WatchForUpdate must not return until one of the following happens:
86+
Value() interface{}
87+
88+
// WatchForUpdate is used to monitor for updates on the retrieved value.
89+
//
90+
// If a watcher is not supported by the configuration store in general or for the specific
91+
// retrieved value the WatchForUpdate must immediately return ErrWatcherNotSupported or
92+
// an error wrapping it.
93+
//
94+
// When watching is supported WatchForUpdate must not return until one of the following happens:
7495
//
75-
// 1. An update is detected for the monitored value.
96+
// 1. An update is detected for the monitored value. In this case the function should
97+
// return ErrValueUpdated or an error wrapping it.
7698
//
7799
// 2. The parent Session object is closed, in which case the method should return
78-
// ErrSessionClosed.
100+
// ErrSessionClosed or an error wrapping it.
79101
//
80102
// 3. An error happens while watching for updates. The method should not return
81103
// on first instances of transient errors, optionally there should be
82104
// configurable thresholds to control for how long such errors can be ignored.
83105
//
84-
// The method must return with a nil error when an update has happened to
85-
// the value monitored by the Watcher.
86-
WatchForUpdate func() error
106+
// This method must only be called when the RetrieveEnd method of the Session that
107+
// retrieved the value was successfully completed.
108+
WatchForUpdate() error
87109
}

0 commit comments

Comments
 (0)