configmapprovider

package
v0.43.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewExpandConverter added in v0.43.0

func NewExpandConverter() config.MapConverterFunc

NewExpandConverter returns a service.ConfigMapConverterFunc, that expands all environment variables for a given config.Map.

Notice: This API is experimental.

func NewOverwritePropertiesConverter added in v0.43.0

func NewOverwritePropertiesConverter(properties []string) config.MapConverterFunc

NewOverwritePropertiesConverter returns a service.ConfigMapConverterFunc, that overrides all the given properties into the input map.

Properties must follow the Java properties format, key-value list separated by equal sign with a "." as key delimiter.

["processors.batch.timeout=2s", "processors.batch/foo.timeout=3s"]

Types

type ChangeEvent

type ChangeEvent struct {
	// Error is nil if the config is changed and needs to be re-fetched.
	// Any non-nil error indicates that there was a problem with watching the config changes.
	Error error
}

ChangeEvent describes the particular change event that happened with the config. TODO: see if this can be eliminated.

type CloseFunc added in v0.42.0

type CloseFunc func(context.Context) error

CloseFunc specifies the function invoked when the Retrieved.Close is being called.

func (CloseFunc) Close added in v0.42.0

func (f CloseFunc) Close(ctx context.Context) error

Close implements the Retrieved.Close.

type GetFunc added in v0.42.0

type GetFunc func(context.Context) (*config.Map, error)

GetFunc specifies the function invoked when the Retrieved.Get is being called.

func (GetFunc) Get added in v0.42.0

func (f GetFunc) Get(ctx context.Context) (*config.Map, error)

Get implements the Retrieved.Get.

type Provider

type Provider interface {
	// Retrieve goes to the configuration source and retrieves the selected data which
	// contains the value to be injected in the configuration and the corresponding watcher that
	// will be used to monitor for updates of the retrieved value.
	//
	// `location` must follow the "<scheme>:<opaque_data>" format. This format is compatible
	// with the URI definition (see https://datatracker.ietf.org/doc/html/rfc3986). The "<scheme>"
	// must be always included in the `location`. The scheme supported by any provider MUST be at
	// least 2 characters long to avoid conflicting with a driver-letter identifier as specified
	// in https://tools.ietf.org/id/draft-kerwin-file-scheme-07.html#syntax.
	//
	// `watcher` callback is called when the config changes. watcher may be called from
	// a different go routine. After watcher is called Retrieved.Get should be called
	// to get the new config. See description of Retrieved for more details.
	// watcher may be nil, which indicates that the caller is not interested in
	// knowing about the changes.
	//
	// If ctx is cancelled should return immediately with an error.
	// Should never be called concurrently with itself or with Shutdown.
	Retrieve(ctx context.Context, location string, watcher WatcherFunc) (Retrieved, error)

	// 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.
	//
	// This method must be called when the Collector service ends, either in case of
	// success or error. Retrieve cannot be called after Shutdown.
	//
	// Should never be called concurrently with itself or with Retrieve.
	// If ctx is cancelled should return immediately with an error.
	Shutdown(ctx context.Context) error
}

Provider is an interface that helps to retrieve a config map and watch for any changes to the config map. Implementations may load the config from a file, a database or any other source.

The typical usage is the following:

r := mapProvider.Retrieve("file:/path/to/config")
r.Get()
// wait for onChange() to be called.
r.Close()
r = mapProvider.Retrieve("file:/path/to/config")
r.Get()
// wait for onChange() to be called.
r.Close()
// repeat Retrieve/Get/wait/Close cycle until it is time to shut down the Collector process.
// ...
mapProvider.Shutdown()

func NewEnv added in v0.42.0

func NewEnv() Provider

NewEnv returns a new Provider that reads the configuration from the given environment variable.

This Provider supports "env" scheme, and can be called with a selector: `env:NAME_OF_ENVIRONMENT_VARIABLE`

func NewFile

func NewFile() Provider

NewFile returns a new Provider that reads the configuration from a file.

This Provider supports "file" scheme, and can be called with a "location" that follows:

file-location = "file:" local-path
local-path    = [ drive-letter ] file-path
drive-letter  = ALPHA ":"

The "file-path" can be relative or absolute, and it can be any OS supported format.

Examples: `file:path/to/file` - relative path (unix, windows) `file:/path/to/file` - absolute path (unix, windows) `file:c:/path/to/file` - absolute path including drive-letter (windows) `file:c:\path\to\file` - absolute path including drive-letter (windows)

type Retrieved

type Retrieved interface {
	// Get returns the config Map. Should never be called after Close.
	// Should never be called concurrently with itself or Close.
	Get(ctx context.Context) (*config.Map, error)

	// Close signals that the configuration for which it was used to retrieve values is
	// no longer in use and should close and release any watchers that it may have created.
	//
	// Should block until all resources are closed, and guarantee that `onChange` is not
	// going to be called after it returns except when `ctx` is cancelled.
	//
	// Should never be called concurrently with itself or Get.
	Close(ctx context.Context) error
	// contains filtered or unexported methods
}

Retrieved holds the result of a call to the Retrieve method of a Provider object. This interface cannot be directly implemented. Implementations must use the NewRetrieved helper.

func NewRetrieved added in v0.42.0

func NewRetrieved(getFunc GetFunc, options ...RetrievedOption) (Retrieved, error)

NewRetrieved returns a Retrieved configured with the provided options.

type RetrievedOption added in v0.42.0

type RetrievedOption func(*retrieved)

RetrievedOption represents the possible options for NewRetrieved.

func WithClose added in v0.42.0

func WithClose(closeFunc CloseFunc) RetrievedOption

WithClose overrides the default `Close` function for a Retrieved. The default always returns nil.

type WatcherFunc added in v0.43.0

type WatcherFunc func(*ChangeEvent)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL