lddynamodb

package
v5.0.0-beta.1+incompat... Latest Latest
Warning

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

Go to latest
Published: May 14, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package lddynamodb provides a DynamoDB-backed feature store for the LaunchDarkly Go SDK.

For more details about how and why you can use a persistent feature store, see: https://docs.launchdarkly.com/v2.0/docs/using-a-persistent-feature-store

To use the DynamoDB feature store with the LaunchDarkly client:

factory, err := lddynamodb.NewDynamoDBFeatureStoreFactory("my-table-name")
if err != nil { ... }

config := ld.DefaultConfig
config.FeatureStoreFactory = factory
client, err := ld.MakeCustomClient("sdk-key", config, 5*time.Second)

Note that the specified table must already exist in DynamoDB. It must have a partition key of "namespace", and a sort key of "key".

By default, the feature store uses a basic DynamoDB client configuration that is equivalent to doing this:

dynamoClient := dynamodb.New(session.NewSession())

This default configuration will only work if your AWS credentials and region are available from AWS environment variables and/or configuration files. If you want to set those programmatically or modify any other configuration settings, you can use the SessionOptions function, or use an already-configured client via the DynamoClient function.

If you are using the same DynamoDB table as a feature store for multiple LaunchDarkly environments, use the Prefix option and choose a different prefix string for each, so they will not interfere with each other's data.

Index

Constants

View Source
const (
	// DefaultCacheTTL is the amount of time that recently read or updated items will be cached
	// in memory, unless you specify otherwise with the CacheTTL option.
	DefaultCacheTTL = 15 * time.Second
)

Variables

This section is empty.

Functions

func NewDynamoDBFeatureStore deprecated

func NewDynamoDBFeatureStore(table string, options ...FeatureStoreOption) (ld.FeatureStore, error)

NewDynamoDBFeatureStore creates a new DynamoDB feature store to be used by the LaunchDarkly client.

By default, this function uses https://docs.aws.amazon.com/sdk-for-go/api/aws/session/#NewSession to configure access to DynamoDB, so the configuration will use your local AWS credentials as well as AWS environment variables. You can also override the default configuration with the SessionOptions option, or use an already-configured DynamoDB client instance with the DynamoClient option.

Deprecated: Please use NewDynamoDBFeatureStoreFactory.

func NewDynamoDBFeatureStoreFactory

func NewDynamoDBFeatureStoreFactory(table string, options ...FeatureStoreOption) (ld.FeatureStoreFactory, error)

NewDynamoDBFeatureStoreFactory returns a factory function for a DynamoDB-backed feature store with an optional memory cache. You may customize its behavior with FeatureStoreOption values, such as CacheTTL and SessionOptions.

By default, this function uses https://docs.aws.amazon.com/sdk-for-go/api/aws/session/#NewSession to configure access to DynamoDB, so the configuration will use your local AWS credentials as well as AWS environment variables. You can also override the default configuration with the SessionOptions option, or use an already-configured DynamoDB client instance with the DynamoClient option.

Set the FeatureStoreFactory field in your Config to the returned value. Because this is specified as a factory function, the Consul client is not actually created until you create the SDK client. This also allows it to use the same logging configuration as the SDK, so you do not have to specify the Logger option separately.

Types

type FeatureStoreOption

type FeatureStoreOption interface {
	// contains filtered or unexported methods
}

FeatureStoreOption is the interface for optional configuration parameters that can be passed to NewDynamoDBFeatureStoreFactory. These include SessionOptions, CacheTTL, DynamoClient, and Logger.

func CacheTTL

func CacheTTL(ttl time.Duration) FeatureStoreOption

CacheTTL creates an option for NewDynamoDBFeatureStoreFactory to set the amount of time that recently read or updated items should remain in an in-memory cache. This reduces the amount of database access if the same feature flags are being evaluated repeatedly.

The default value is DefaultCacheTTL. A value of zero disables in-memory caching completely. A negative value means data is cached forever (i.e. it will only be read again from the database if the SDK is restarted). Use the "cached forever" mode with caution: it means that in a scenario where multiple processes are sharing the database, and the current process loses connectivity to LaunchDarkly while other processes are still receiving updates and writing them to the database, the current process will have stale data.

factory, err := lddynamodb.NewDynamoDBFeatureStoreFactory("my-table-name",
    lddynamodb.CacheTTL(30*time.Second))

func ClientConfig

func ClientConfig(config *aws.Config) FeatureStoreOption

ClientConfig creates an option for NewDynamoDBFeatureStoreFactory to add an AWS configuration object for the DynamoDB client. This allows you to customize settings such as the retry behavior.

func DynamoClient

func DynamoClient(client dynamodbiface.DynamoDBAPI) FeatureStoreOption

DynamoClient creates an option for NewDynamoDBFeatureStoreFactory to specify an existing DynamoDB client instance. Use this if you want to customize the client used by the feature store in ways that are not supported by other NewDynamoDBFeatureStoreFactory options. If you specify this option, then any configurations specified with SessionOptions or ClientConfig will be ignored.

factory, err := lddynamodb.NewDynamoDBFeatureStoreFactory("my-table-name",
    lddynamodb.DynamoClient(myDBClient))

func Logger

func Logger(logger ld.Logger) FeatureStoreOption

Logger creates an option for NewDynamoDBFeatureStore, to specify where to send log output. If not specified, a log.Logger is used.

If you use NewDynamoDBFeatureStoreFactory rather than the deprecated constructor, you normally do not need to specify a logger because it will use the same logging configuration as the SDK client.

store, err := lddynamodb.NewDynamoDBFeatureStore("my-table-name", lddynamodb.Logger(myLogger))

func Prefix

func Prefix(prefix string) FeatureStoreOption

Prefix creates an option for NewDynamoDBFeatureStoreFactory to specify a string that should be prepended to all partition keys used by the feature store. A colon will be added to this automatically. If this is unspecified, no prefix will be used.

factory, err := lddynamodb.NewDynamoDBFeatureStoreFactory(lddynamodb.Prefix("ld-data"))

func SessionOptions

func SessionOptions(options session.Options) FeatureStoreOption

SessionOptions creates an option for NewDynamoDBFeatureStoreFactory, to specify an AWS Session.Options object to use when creating the DynamoDB session. This can be used to set properties such as the region programmatically, rather than relying on the defaults from the environment.

factory, err := lddynamodb.NewDynamoDBFeatureStoreFactory("my-table-name",
    lddynamodb.SessionOptions(myOptions))

Jump to

Keyboard shortcuts

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