ldconsul

package module
Version: v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

README

LaunchDarkly Server-side SDK for Go - Consul integration

Circle CI Documentation

This library provides a Consul-backed persistence mechanism (data store) for the LaunchDarkly Go SDK, replacing the default in-memory data store. It uses the standard Consul Go client.

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

The minimum Go version is 1.14.

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

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"
    ldconsul "github.com/launchdarkly/go-server-sdk-consul"
)
  1. When configuring your SDK client, add the Consul data store as a PersistentDataStore. You may specify any custom Consul options using the methods of ConsulsDataStoreBuilder. For instance, to customize the Consul hostname:
    var config ld.Config{}
    config.DataStore = ldcomponents.PersistentDataStore(
        ldconsul.DataStore().Address("my-consul-host"),
    )

By default, the store will try to connect to a local Consul instance on port 8500.

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(
        ldconsul.DataStore(),
    ).CacheMinutes(5)

Data size limitation

Consul does not support storing values greater than 512KB. 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. Read our documentation for a complete list.
  • Explore LaunchDarkly

Documentation

Overview

Package ldconsul provides a Consul-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/sdk/features/storing-data/consul#go

To use the Consul data store with the LaunchDarkly client:

import ldconsul "github.com/launchdarkly/go-server-sdk-consul"

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

The default Consul configuration uses an address of localhost:8500. You may customize the configuration by using the methods of the ldconsul.DataStoreBuilder returned by ldconsul.DataStore(). For example:

config := ld.Config{
    DataStore: ldcomponents.PersistentDataStore(
        ldconsul.DataStore().Address("my-consul-hostname"),
    ).CacheSeconds(30),
}

Note that CacheSeconds() is not a method of ldconsul.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 Consul for other purposes, the data store can coexist with other data as long as you are not using the same keys. By default, the keys used by the data store will always start with "launchdarkly/"; you can change this to another prefix if desired.

Index

Constants

View Source
const (
	// DefaultPrefix is a string that is prepended (along with a slash) to all Consul keys used
	// by the data store. You can change this value with the Prefix() option.
	DefaultPrefix = "launchdarkly"
)

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 Consul-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 = ldconsul.DataStore().Address("hostname:8500).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() *DataStoreBuilder

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

func (*DataStoreBuilder) Address

func (b *DataStoreBuilder) Address(address string) *DataStoreBuilder

Address sets the address of the Consul server. If placed after Config(), this modifies the preivously specified configuration.

func (*DataStoreBuilder) Config

func (b *DataStoreBuilder) Config(consulConfig c.Config) *DataStoreBuilder

Config specifies an entire configuration for the Consul driver. This overwrites any previous Consul settings that may have been specified.

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) Prefix

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

Prefix specifies a prefix for namespacing the data store's keys. The default value is DefaultPrefix.

Jump to

Keyboard shortcuts

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