From a1a4a0d5ec6be59e7a8a068a59c142a66fb0cb8a Mon Sep 17 00:00:00 2001 From: Paulo Janotti Date: Fri, 26 Mar 2021 11:07:15 -0700 Subject: [PATCH 1/6] Add a few refinements to configsource interface --- config/internal/configsource/component.go | 34 ++++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/config/internal/configsource/component.go b/config/internal/configsource/component.go index 445b1e7b502..50f430fbb90 100644 --- a/config/internal/configsource/component.go +++ b/config/internal/configsource/component.go @@ -21,8 +21,16 @@ import ( // ErrSessionClosed is returned by WatchForUpdate functions when its parent Session // object is closed. +// This error can be wrapped with additional information. Callers trying to identify this +// specific error must use errors.Is. var ErrSessionClosed = errors.New("parent session was closed") +// ErrValueUpdated is returned by WatchForUpdate functions when the value being watched +// was changed or expired and needs to be retrieved again. +// This error can be wrapped with additional information. Callers trying to identify this +// specific error must use errors.Is. +var ErrValueUpdated = errors.New("configuration must retrieve the updated value") + // ConfigSource is the interface to be implemented by objects used by the collector // to retrieve external configuration information. type ConfigSource interface { @@ -67,21 +75,33 @@ type Session interface { } // Retrieved holds the result of a call to the Retrieve method of a Session object. -type Retrieved struct { +type Retrieved interface { // Value is the retrieved data that will be injected on the configuration. - Value interface{} + Value() interface{} +} + +// WatchableRetrieved holds the result of a call to the Retrieve method of a Session object +// for a value that can be watched for updates. +type WatchableRetrieved interface { + Retrieved + // WatchForUpdate must not return until one of the following happens: // - // 1. An update is detected for the monitored value. + // 1. An update is detected for the monitored value. In this case the function should + // return ErrValueUpdated or an error wrapping it. // // 2. The parent Session object is closed, in which case the method should return - // ErrSessionClosed. + // ErrSessionClosed or an error wrapping it. // // 3. An error happens while watching for updates. The method should not return // on first instances of transient errors, optionally there should be // configurable thresholds to control for how long such errors can be ignored. // - // The method must return with a nil error when an update has happened to - // the value monitored by the Watcher. - WatchForUpdate func() error + // This method must be only called when all calls to the Retrieve methods of the + // Session that retrieved the value were made. + WatchForUpdate() error } + +// WatchForUpdate defines the signature used by the method used to monitor for updates +// on a retrieved configuration. +type WatchForUpdate func() error From a65083294dd43df0ef6427d50225498fe863890e Mon Sep 17 00:00:00 2001 From: Paulo Janotti Date: Fri, 26 Mar 2021 11:12:26 -0700 Subject: [PATCH 2/6] Small re-wording. --- config/internal/configsource/component.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/internal/configsource/component.go b/config/internal/configsource/component.go index 50f430fbb90..a6702b9a5ad 100644 --- a/config/internal/configsource/component.go +++ b/config/internal/configsource/component.go @@ -97,8 +97,8 @@ type WatchableRetrieved interface { // on first instances of transient errors, optionally there should be // configurable thresholds to control for how long such errors can be ignored. // - // This method must be only called when all calls to the Retrieve methods of the - // Session that retrieved the value were made. + // This method must only be called when the RetrieveEnd method of the Session that + // retrieved the value was successfully completed. WatchForUpdate() error } From 179ee0d6a6e158cac705a66b2da10e892b6762af Mon Sep 17 00:00:00 2001 From: Paulo Janotti Date: Fri, 26 Mar 2021 11:50:01 -0700 Subject: [PATCH 3/6] Remove function type. --- config/internal/configsource/component.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/config/internal/configsource/component.go b/config/internal/configsource/component.go index a6702b9a5ad..4b911aa186f 100644 --- a/config/internal/configsource/component.go +++ b/config/internal/configsource/component.go @@ -101,7 +101,3 @@ type WatchableRetrieved interface { // retrieved the value was successfully completed. WatchForUpdate() error } - -// WatchForUpdate defines the signature used by the method used to monitor for updates -// on a retrieved configuration. -type WatchForUpdate func() error From 68cc173becb016d4b467fe4e84cc46f5035d3152 Mon Sep 17 00:00:00 2001 From: Paulo Janotti Date: Fri, 26 Mar 2021 12:03:11 -0700 Subject: [PATCH 4/6] Remove WatchableRetrieved and add an error instead --- config/internal/configsource/component.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config/internal/configsource/component.go b/config/internal/configsource/component.go index 4b911aa186f..f21f25a7316 100644 --- a/config/internal/configsource/component.go +++ b/config/internal/configsource/component.go @@ -31,6 +31,12 @@ var ErrSessionClosed = errors.New("parent session was closed") // specific error must use errors.Is. var ErrValueUpdated = errors.New("configuration must retrieve the updated value") +// ErrWatcherNotSupported is returned by WatchForUpdate functions when the configuration +// source can't watch for updates on the value. +// This error can be wrapped with additional information. Callers trying to identify this +// specific error must use errors.Is. +var ErrWatcherNotSupported = errors.New("value watcher is not supported") + // ConfigSource is the interface to be implemented by objects used by the collector // to retrieve external configuration information. type ConfigSource interface { @@ -78,12 +84,6 @@ type Session interface { type Retrieved interface { // Value is the retrieved data that will be injected on the configuration. Value() interface{} -} - -// WatchableRetrieved holds the result of a call to the Retrieve method of a Session object -// for a value that can be watched for updates. -type WatchableRetrieved interface { - Retrieved // WatchForUpdate must not return until one of the following happens: // From 11c29ffd6fba1adedc60abf595e33bc0c8786204 Mon Sep 17 00:00:00 2001 From: Paulo Janotti Date: Sat, 27 Mar 2021 00:43:08 +0000 Subject: [PATCH 5/6] Add ErrWatcherNotSupported to WatchForUpdate function --- config/internal/configsource/component.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/config/internal/configsource/component.go b/config/internal/configsource/component.go index f21f25a7316..8fe5fd1f77c 100644 --- a/config/internal/configsource/component.go +++ b/config/internal/configsource/component.go @@ -85,7 +85,13 @@ type Retrieved interface { // Value is the retrieved data that will be injected on the configuration. Value() interface{} - // WatchForUpdate must not return until one of the following happens: + // WatchForUpdate is used to monitor for updates on the retrived value. + // + // If a watcher is not supported by the configuration store in general or for the specific + // retrieved value the WatchForUpdate must immediately return ErrWatcherNotSupported or + // an error wrapping it. + // + // When watching is supported WatchForUpdate must not return until one of the following happens: // // 1. An update is detected for the monitored value. In this case the function should // return ErrValueUpdated or an error wrapping it. From 358f128b0a4f89aff9c794f186e8f59f45116ff8 Mon Sep 17 00:00:00 2001 From: Paulo Janotti Date: Sat, 27 Mar 2021 01:12:14 +0000 Subject: [PATCH 6/6] Fix typo --- config/internal/configsource/component.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/internal/configsource/component.go b/config/internal/configsource/component.go index 8fe5fd1f77c..c65ea9bda5c 100644 --- a/config/internal/configsource/component.go +++ b/config/internal/configsource/component.go @@ -85,7 +85,7 @@ type Retrieved interface { // Value is the retrieved data that will be injected on the configuration. Value() interface{} - // WatchForUpdate is used to monitor for updates on the retrived value. + // WatchForUpdate is used to monitor for updates on the retrieved value. // // If a watcher is not supported by the configuration store in general or for the specific // retrieved value the WatchForUpdate must immediately return ErrWatcherNotSupported or