lddynamodb

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2020 License: Apache-2.0 Imports: 12 Imported by: 1

README

LaunchDarkly Server-side SDK for Go - Dynamodb integration

Circle CI Documentation

This library provides a DynamoDB-backed persistence mechanism (data store) for the LaunchDarkly Go SDK, replacing the default in-memory data store.

This version of the library requires at least version 5.0.0 of the LaunchDarkly Go SDK. In earlier Go SDK versions, the lddynamodb package was built into the SDK (gopkg.in/launchdarkly/go-server-sdk.v4/lddynamodb).

The minimum Go version is 1.14.

For more information, see also: Using a persistent feature store.

This is prerelease code

This project is currently in beta. The full 1.0.0 release will be done when Go SDK 5.0.0 is released.

Quick setup

This assumes that you have already installed the LaunchDarkly Go SDK.

  1. Import the LaunchDarkly SDK packages and the package for this library:
import (
    ld "gopkg.in/launchdarkly/go-server-sdk.v5"
    "gopkg.in/launchdarkly/go-server-sdk.v5/ldcomponents"
    lddynamodb "github.com/launchdarkly/go-server-sdk-dynamodb"
)
  1. When configuring your SDK client, add the DynamoDB data store as a PersistentDataStore. You may specify any custom DynamoDB options using the methods of DynamoDBDataStoreBuilder. For instance:
    var config ld.Config{}
    config.DataStore = ldcomponents.PersistentDataStore(
        lddymamodb.DataStore("my-table-name").
            SessionOptions(session.Options{Profile: "profile_name"}),
    )

By default, the DynamoDB client will try to get your AWS credentials and region name from environment variables and/or local configuration files, as described in the AWS SDK documentation.

Caching behavior

The LaunchDarkly SDK has a standard caching mechanism for any persistent data store, to reduce database traffic. This is configured through the SDK's PersistentDataStoreBuilder class as described the SDK documentation. For instance, to specify a cache TTL of 5 minutes:

    var config ld.Config{}
    config.DataStore = ldcomponents.PersistentDataStore(
        lddynamodb.DataStore("my-table-name"),
    ).CacheMinutes(5)

Data size limitation

DynamoDB does not support storing values greater than 400KB (or slightly less, since that number includes the size of the column metadata). Therefore, this integration will not work if the JSON representation of any feature flag or user segment exceeds that size.

To see the JSON representations of all flags and segments, query https://app.launchdarkly.com/sdk/latest-all with your SDK key in an Authorization header.

LaunchDarkly overview

LaunchDarkly is a feature management platform that serves over 100 billion feature flags daily to help teams build better software, faster. Get started using LaunchDarkly today!

About LaunchDarkly

  • LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
    • Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
    • Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
    • Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
    • Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
  • LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Check out our documentation for a complete list.
  • Explore LaunchDarkly

Documentation

Overview

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

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

To use the DynamoDB data store with the LaunchDarkly client:

import lddynamodb "github.com/launchdarkly/go-server-sdk-dynamodb"

config := ld.Config{
    DataStore: ldcomponents.PersistentDataStore(lddynamodb.DataStore("my-table-name")),
}
client, err := ld.MakeCustomClient("sdk-key", config, 5*time.Second)

By default, the data 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 methods of the lddynamodb.DataStoreBuilder returned by lddynamodb.DataStore(). For example:

config := ld.Config{
    DataStore: ldcomponents.PersistentDataStore(
        lddynamodb.DataStore("my-table-name").Prefix("key-prefix"),
    ).CacheSeconds(30),
}

Note that CacheSeconds() is not a method of lddynamodb.DataStoreBuilder, but rather a method of ldcomponents.PersistentDataStore(), because the caching behavior is provided by the SDK for all database integrations.

If you are also using DynamoDB for other purposes, the data store can coexist with other data in the same table as long as you use the Prefix option to make each application use different keys. However, it is advisable to configure separate tables in DynamoDB, for better control over permissions and throughput.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataStoreBuilder

type DataStoreBuilder struct {
	// contains filtered or unexported fields
}

DataStoreBuilder is a builder for configuring the DynamoDB-based persistent data store.

Obtain an instance of this type by calling DataStore(). After calling its methods to specify any desired custom settings, wrap it in a PersistentDataStoreBuilder by calling ldcomponents.PersistentDataStore(), and then store this in the SDK configuration's DataStore field.

Builder calls can be chained, for example:

config.DataStore = lddynamodb.DataStore("tablename").SessionOptions(someOption).Prefix("prefix")

You do not need to call the builder's CreatePersistentDataStore() method yourself to build the actual data store; that will be done by the SDK.

func DataStore

func DataStore(tableName string) *DataStoreBuilder

DataStore returns a configurable builder for a DynamoDB-backed data store.

The tableName parameter is required, and the table must already exist in DynamoDB.

func (*DataStoreBuilder) ClientConfig

func (b *DataStoreBuilder) ClientConfig(config *aws.Config) *DataStoreBuilder

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

func (*DataStoreBuilder) CreatePersistentDataStore

func (b *DataStoreBuilder) CreatePersistentDataStore(
	context interfaces.ClientContext,
) (interfaces.PersistentDataStore, error)

CreatePersistentDataStore is called internally by the SDK to create the data store implementation object.

func (*DataStoreBuilder) DescribeConfiguration

func (b *DataStoreBuilder) DescribeConfiguration() ldvalue.Value

DescribeConfiguration is used internally by the SDK to inspect the configuration.

func (*DataStoreBuilder) DynamoClient

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

func (*DataStoreBuilder) Prefix

func (b *DataStoreBuilder) Prefix(prefix string) *DataStoreBuilder

Prefix specifies a prefix for namespacing the data store's keys.

func (*DataStoreBuilder) SessionOptions

func (b *DataStoreBuilder) SessionOptions(options session.Options) *DataStoreBuilder

SessionOptions specifies 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.

Jump to

Keyboard shortcuts

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