Documentation
¶
Overview ¶
Package retriever defines the retriever interfaces and the manager that refreshes the flag configurations.
Index ¶
- Variables
- type CommonInitializableRetriever
- type FormatHinter
- type InitializableRetriever
- type InitializableRetrieverLegacy
- type InitializableRetrieverWithFlagset
- type Manager
- func (m *Manager) ForceRefresh(ctx context.Context) bool
- func (m *Manager) GetCacheRefreshDate() time.Time
- func (m *Manager) GetFlag(flagKey string) (*flagdef.InternalFlag, error)
- func (m *Manager) GetFlagsFromCache(_ context.Context) (map[string]flagdef.Flag, error)
- func (m *Manager) GetFlagsFromCacheReadOnly(_ context.Context) (map[string]flagdef.Flag, error)
- func (m *Manager) Init(ctx context.Context) error
- func (m *Manager) Shutdown(ctx context.Context) error
- func (m *Manager) StartPolling(ctx context.Context)
- func (m *Manager) StopPolling()
- type ManagerConfig
- type Retriever
- type Status
- type Ticker
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyContent = errors.New("the retriever returned empty content, keeping the current flags")
ErrEmptyContent is reported when, on a refresh, a retriever returns no bytes or only white space, or content that decodes to no document at all (YAML or JSON: only comments, `---`, `null`, a byte order mark). An empty read is the signature of a source that is being rewritten, so the manager keeps the current flags and retries on the next refresh. An explicitly empty document (`{}`, or in TOML a file of only comments) still means "no flags". The check applies to each retriever result before the merge: one empty retriever fails the whole refresh.
Functions ¶
This section is empty.
Types ¶
type CommonInitializableRetriever ¶
type CommonInitializableRetriever interface {
Retriever
Shutdown(ctx context.Context) error
Status() Status
}
CommonInitializableRetriever is the common interface for all versions of retrievers that can be initialized and shutdown.
type FormatHinter ¶
type FormatHinter interface {
OutputFormat() string
}
FormatHinter is an optional interface a Retriever can implement to declare the format of the bytes it returns from Retrieve. When implemented, the manager uses this hint to pick the right parser instead of the global FileFormat configuration, avoiding unnecessary YAML parsing of JSON data.
Returned values follow the same convention as ffclient.Config.FileFormat: "json", "yaml", or "toml" (case-insensitive).
type InitializableRetriever ¶
type InitializableRetriever interface {
CommonInitializableRetriever
Init(ctx context.Context, logger *slog.Logger) error
}
InitializableRetriever is an extended version of the retriever that can be initialized and shutdown.
type InitializableRetrieverLegacy ¶
type InitializableRetrieverLegacy interface {
CommonInitializableRetriever
Init(ctx context.Context, logger *log.Logger) error
}
InitializableRetrieverLegacy is an extended version of the retriever that can be initialized and shutdown.
type InitializableRetrieverWithFlagset ¶
type InitializableRetrieverWithFlagset interface {
CommonInitializableRetriever
Init(ctx context.Context, logger *slog.Logger, flagset *string) error
}
InitializableRetrieverWithFlagset is an extended version of the retriever that can be initialized and shutdown. It is used to initialize the retriever with a specific flagset.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is a struct that managed the retrievers.
func NewManager ¶
func NewManager( config ManagerConfig, retrievers []Retriever, cacheManager cache.Manager, logger *slog.Logger) *Manager
NewManager create a new Manager.
func (*Manager) ForceRefresh ¶
ForceRefresh refreshes the flag configurations now and reports whether the refresh succeeded.
func (*Manager) GetCacheRefreshDate ¶
GetCacheRefreshDate gives the last refresh date of the cache.
func (*Manager) GetFlag ¶
func (m *Manager) GetFlag(flagKey string) (*flagdef.InternalFlag, error)
GetFlag returns the flag from the cache with the current state when calling this method.
func (*Manager) GetFlagsFromCache ¶
GetFlagsFromCache returns all the flags present in the cache with their current state when calling this method. If cache hasn't been initialized, an error reporting this is returned.
func (*Manager) GetFlagsFromCacheReadOnly ¶
GetFlagsFromCacheReadOnly is GetFlagsFromCache without the copy of the flags: it is for the callers inside the module that only read them (evaluation of all the flags).
func (*Manager) Init ¶
Init the retrievers. This function will call the Init function of the retrievers that implements the InitializableRetriever interface.
func (*Manager) Shutdown ¶
Shutdown the retrievers. This function will call the Shutdown function of the retrievers that implements the InitializableRetriever interface.
func (*Manager) StartPolling ¶
StartPolling is the daemon that refreshes the cache every X seconds.
func (*Manager) StopPolling ¶
func (m *Manager) StopPolling()
StopPolling stops the background updater and waits for the polling goroutine to return. It is safe to call it several times: the underlying channel is closed only once, since StopPolling is called both by SetOffline() and by Shutdown().
type ManagerConfig ¶
type ManagerConfig struct {
Name *string
// Ticker is the source of the polls; nil is a real [time.Ticker]. An embedder that drives the manager from its own
// clock sets it, and so does a test that polls by hand.
Ticker Ticker
FileFormat string
PersistentFlagConfigurationFile string
PollingInterval time.Duration
DisableNotifierOnInit bool
StartWithRetrieverError bool
EnablePollingJitter bool
}
ManagerConfig is the configuration of the retriever manager.
type Retriever ¶
type Retriever interface {
// Retrieve function is supposed to load the file and to return a []byte of your flag configuration file.
Retrieve(ctx context.Context) ([]byte, error)
}
Retriever is the interface to create a Retriever to load you flags.
type Status ¶
type Status = string
Status is the status of the retriever. It can be used to check if the retriever is ready to be used. If not ready, we wi will not use it.
const ( // RetrieverReady is the status when the retriever is ready to be used. RetrieverReady Status = "READY" // RetrieverNotReady is the status when the retriever is not ready yet to be used. RetrieverNotReady Status = "NOT_READY" // RetrieverError is the status when the retriever is in error. RetrieverError Status = "ERROR" )
type Ticker ¶ added in v1.0.0
Ticker is the source of the moments at which the manager polls its retrievers: it returns the channel of the ticks for an interval, and the function that stops them. The default is a time.Ticker.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package azblobstorageretriever retrieves flag configurations from Azure Blob Storage.
|
Package azblobstorageretriever retrieves flag configurations from Azure Blob Storage. |
|
Package bitbucketretriever retrieves flag configurations from Bitbucket.
|
Package bitbucketretriever retrieves flag configurations from Bitbucket. |
|
Package fileretriever retrieves flag configurations from local files.
|
Package fileretriever retrieves flag configurations from local files. |
|
Package gcstorageretriever retrieves flag configurations from Google Cloud Storage.
|
Package gcstorageretriever retrieves flag configurations from Google Cloud Storage. |
|
Package githubretriever retrieves flag configurations from GitHub repositories.
|
Package githubretriever retrieves flag configurations from GitHub repositories. |
|
Package gitlabretriever retrieves flag configurations from GitLab repositories.
|
Package gitlabretriever retrieves flag configurations from GitLab repositories. |
|
Package httpretriever retrieves flag configurations over HTTP.
|
Package httpretriever retrieves flag configurations over HTTP. |
|
Package k8sretriever retrieves flag configurations from Kubernetes resources.
|
Package k8sretriever retrieves flag configurations from Kubernetes resources. |
|
Package mongodbretriever retrieves flag configurations from MongoDB.
|
Package mongodbretriever retrieves flag configurations from MongoDB. |
|
Package postgresqlretriever retrieves flag configurations from PostgreSQL.
|
Package postgresqlretriever retrieves flag configurations from PostgreSQL. |
|
Package redisretriever retrieves flag configurations from Redis.
|
Package redisretriever retrieves flag configurations from Redis. |
|
Package s3retrieverv2 retrieves flag configurations from Amazon S3.
|
Package s3retrieverv2 retrieves flag configurations from Amazon S3. |
|
Package shared provides the HTTP call helper shared by the retrievers.
|
Package shared provides the HTTP call helper shared by the retrievers. |