ldcomponents

package
v7.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: Apache-2.0 Imports: 19 Imported by: 4

Documentation

Overview

Package ldcomponents provides the standard implementations and configuration options of LaunchDarkly components.

Some configuration options are represented as fields in the main Config struct; but others are specific to one area of functionality, such as how the SDK receives feature flag updates or processes analytics events. For the latter, the standard way to specify a configuration is to call one of the functions in ldcomponents (such as StreamingDataSource), apply any desired configuration change to the object that that method returns (such as StreamingDataSourceBuilder.InitialReconnectDelay), and then put the configured component builder into the corresponding Config field (such as Config.DataSource) to use that configuration in the SDK.

Index

Constants

View Source
const (
	// DefaultEventsBaseURI is the default value for [EventProcessorBuilder.BaseURI].
	DefaultEventsBaseURI = "https://events.launchdarkly.com"
	// DefaultEventsCapacity is the default value for [EventProcessorBuilder.Capacity].
	DefaultEventsCapacity = 10000
	// DefaultDiagnosticRecordingInterval is the default value for [EventProcessorBuilder.DiagnosticRecordingInterval].
	DefaultDiagnosticRecordingInterval = 15 * time.Minute
	// DefaultFlushInterval is the default value for [EventProcessorBuilder.FlushInterval].
	DefaultFlushInterval = 5 * time.Second
	// DefaultContextKeysCapacity is the default value for [EventProcessorBuilder.ContextKeysCapacity].
	DefaultContextKeysCapacity = 1000
	// DefaultContextKeysFlushInterval is the default value for [EventProcessorBuilder.ContextKeysFlushInterval].
	DefaultContextKeysFlushInterval = 5 * time.Minute
	// MinimumDiagnosticRecordingInterval is the minimum value for [EventProcessorBuilder.DiagnosticRecordingInterval].
	MinimumDiagnosticRecordingInterval = 60 * time.Second
)
View Source
const DefaultBigSegmentsContextCacheSize = 1000

DefaultBigSegmentsContextCacheSize is the default value for BigSegmentsConfigurationBuilder.ContextCacheSize.

View Source
const DefaultBigSegmentsContextCacheTime = time.Second * 5

DefaultBigSegmentsContextCacheTime is the default value for BigSegmentsConfigurationBuilder.ContextCacheTime.

View Source
const DefaultBigSegmentsStaleAfter = time.Second * 120

DefaultBigSegmentsStaleAfter is the default value for BigSegmentsConfigurationBuilder.StaleAfter.

View Source
const DefaultBigSegmentsStatusPollInterval = time.Second * 5

DefaultBigSegmentsStatusPollInterval is the default value for BigSegmentsConfigurationBuilder.StatusPollInterval.

View Source
const DefaultConnectTimeout = 3 * time.Second

DefaultConnectTimeout is the HTTP connection timeout that is used if HTTPConfigurationBuilder.ConnectTimeout is not set.

View Source
const DefaultInitialReconnectDelay = time.Second

DefaultInitialReconnectDelay is the default value for StreamingDataSourceBuilder.InitialReconnectDelay.

View Source
const DefaultLogDataSourceOutageAsErrorAfter = time.Minute

DefaultLogDataSourceOutageAsErrorAfter is the default value for LoggingConfigurationBuilder.LogDataSourceOutageAsErrorAfter: one minute.

View Source
const DefaultPollInterval = 30 * time.Second

DefaultPollInterval is the default value for PollingDataSourceBuilder.PollInterval. This is also the minimum value.

View Source
const DefaultPollingBaseURI = "https://app.launchdarkly.com"

DefaultPollingBaseURI is the default value for [PollingDataSourceBuilder.BaseURI].

View Source
const DefaultStreamingBaseURI = endpoints.DefaultStreamingBaseURI

DefaultStreamingBaseURI is the default value for [StreamingDataSourceBuilder.BaseURI].

View Source
const PersistentDataStoreDefaultCacheTime = 15 * time.Second

PersistentDataStoreDefaultCacheTime is the default amount of time that recently read or updated items will be cached in memory, if you use PersistentDataStore. You can specify otherwise with PersistentDataStoreBuilder.CacheTime.

Variables

This section is empty.

Functions

func ExternalUpdatesOnly

func ExternalUpdatesOnly() subsystems.ComponentConfigurer[subsystems.DataSource]

ExternalUpdatesOnly returns a configuration object that disables a direct connection with LaunchDarkly for feature flag updates.

Storing this in the DataSource field of github.com/launchdarkly/go-server-sdk/v7.Config causes the SDK not to retrieve feature flag data from LaunchDarkly, regardless of any other configuration. This is normally done if you are using the Relay Proxy (https://docs.launchdarkly.com/home/relay-proxy) in "daemon mode", where an external process-- the Relay Proxy-- connects to LaunchDarkly and populates a persistent data store with the feature flag data. The data store could also be populated by another process that is running the LaunchDarkly SDK. If there is no external process updating the data store, then the SDK will not have any feature flag data and will return application default values only.

config := ld.Config{
    DataSource: ldcomponents.ExternalUpdatesOnly(),
}

func InMemoryDataStore

InMemoryDataStore returns the default in-memory DataStore implementation factory.

func NoEvents

NoEvents returns a configuration object that disables analytics events.

Storing this in the Events field of github.com/launchdarkly/go-server-sdk/v7.Config causes the SDK to discard all analytics events and not send them to LaunchDarkly, regardless of any other configuration.

config := ld.Config{
    Events: ldcomponents.NoEvents(),
}

func NoLogging

NoLogging returns a configuration object that disables logging.

config := ld.Config{
    Logging: ldcomponents.NoLogging(),
}

func RelayProxyEndpoints

func RelayProxyEndpoints(relayProxyBaseURI string) interfaces.ServiceEndpoints

RelayProxyEndpoints specifies a single base URI for a Relay Proxy instance, telling the SDK to use the Relay Proxy for all services.

When using the LaunchDarkly Relay Proxy (https://docs.launchdarkly.com/home/relay-proxy), the SDK only needs to know the single base URI of the Relay Proxy, which will provide all of the proxied service endpoints.

Store this value in the ServiceEndpoints field of github.com/launchdarkly/go-server-sdk/v7.Config. For example:

relayURI := "http://my-relay-hostname:8080"
config := ld.Config{
    ServiceEndpoints: ldcomponents.RelayProxyEndpoints(relayURI),
}

If analytics events are enabled, this will also cause the SDK to forward events through the Relay Proxy. If you have not enabled event forwarding in your Relay Proxy configuration and you want the SDK to send events directly to LaunchDarkly instead, use RelayProxyEndpointsWithoutEvents.

See Config.ServiceEndpoints for more details.

func RelayProxyEndpointsWithoutEvents

func RelayProxyEndpointsWithoutEvents(relayProxyBaseURI string) interfaces.ServiceEndpoints

RelayProxyEndpointsWithoutEvents specifies a single base URI for a Relay Proxy instance, telling the SDK to use the Relay Proxy for all services except analytics events. Note that this does not disable events, it instead means events (if enabled) will be sent directly to LaunchDarkly.

When using the LaunchDarkly Relay Proxy (https://docs.launchdarkly.com/home/relay-proxy), the SDK only needs to know the single base URI of the Relay Proxy, which will provide all of the proxied service endpoints.

Store this value in the ServiceEndpoints field of your SDK configuration. For example:

relayURI := "http://my-relay-hostname:8080"
config := ld.Config{
    ServiceEndpoints: ldcomponents.RelayProxyEndpointsWithoutEvents(relayURI),
}

If you do want events to be forwarded through the Relay Proxy, use RelayProxyEndpoints instead.

See Config.ServiceEndpoints for more details.

Types

type BigSegmentsConfigurationBuilder

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

BigSegmentsConfigurationBuilder contains methods for configuring the SDK's Big Segments behavior.

"Big Segments" are a specific type of user segments. For more information, read the LaunchDarkly documentation about user segments: https://docs.launchdarkly.com/home/users

If you want to set non-default values for any of these properties, create a builder with ldcomponents.BigSegments(), change its properties with the BigSegmentsConfigurationBuilder methods, and store it in the BigSegments field of github.com/launchdarkly/go-server-sdk/v7.Config:

    config := ld.Config{
        BigSegments: ldcomponents.BigSegments(ldredis.DataStore()).
            ContextCacheSize(2000).
		       StaleAfter(time.Second * 60),
    }

You only need to use the methods of BigSegmentsConfigurationBuilder if you want to customize options other than the data store itself.

func BigSegments

BigSegments returns a configuration builder for the SDK's Big Segments feature.

"Big Segments" are a specific type of user segments. For more information, read the LaunchDarkly documentation about user segments: https://docs.launchdarkly.com/home/users

After configuring this object, store it in the BigSegments field of your SDK configuration. For example, using the Redis integration:

config := ld.Config{
    BigSegments: ldcomponents.BigSegments(ldredis.BigSegmentStore().Prefix("app1")).
        ContextCacheSize(2000),
}

You must always specify the storeConfigurer parameter, to tell the SDK what database you are using. Several database integrations exist for the LaunchDarkly SDK, each with a configuration builder to that database; the BigSegmentsConfigurationBuilder adds configuration options for aspects of SDK behavior that are independent of the database. In the example above, Prefix() is an option specifically for the Redis integration, whereas ContextCacheSize() is an option that can be used for any data store type.

If you do not set Config.BigSegments-- or if you pass a nil storeConfigurer to this function-- the Big Segments feature will be disabled, and any feature flags that reference a Big Segment will behave as if the evaluation context was not included in the segment.

func (*BigSegmentsConfigurationBuilder) Build

Build is called internally by the SDK.

func (*BigSegmentsConfigurationBuilder) ContextCacheSize

func (b *BigSegmentsConfigurationBuilder) ContextCacheSize(
	contextCacheSize int,
) *BigSegmentsConfigurationBuilder

ContextCacheSize sets the maximum number of users whose Big Segment state will be cached by the SDK at any given time. The default value is DefaultBigSegmentsContextCacheSize.

To reduce database traffic, the SDK maintains a least-recently-used cache by context key. When a feature flag that references a Big Segment is evaluated for some context that is not currently in the cache, the SDK queries the database for all Big Segment memberships of that context, and stores them together in a single cache entry. If the cache is full, the oldest entry is dropped.

A higher value for ContextCacheSize means that database queries for Big Segments will be done less often for recently-referenced users, if the application has many users, at the cost of increased memory used by the cache.

Cache entries can also expire based on the setting of BigSegmentsConfigurationBuilder.ContextCacheTime.

func (*BigSegmentsConfigurationBuilder) ContextCacheTime

func (b *BigSegmentsConfigurationBuilder) ContextCacheTime(
	contextCacheTime time.Duration,
) *BigSegmentsConfigurationBuilder

ContextCacheTime sets the maximum length of time that the Big Segment state for an evaluation context will be cached by the SDK. The default value is DefaultBigSegmentsContextCacheTime.

See BigSegmentsConfigurationBuilder.ContextCacheSize for more about this cache. A higher value for ContextCacheTime means that database queries for the Big Segment state of any given context will be done less often, but that changes to segment membership may not be detected as soon.

func (*BigSegmentsConfigurationBuilder) StaleAfter

StaleAfter sets the maximum length of time between updates of the Big Segments data before the data is considered out of date. The default value is DefaultBigSegmentsStaleAfter.

Normally, the LaunchDarkly Relay Proxy updates a timestamp in the Big Segments store at intervals to confirm that it is still in sync with the LaunchDarkly data, even if there have been no changes to the data. If the timestamp falls behind the current time by the amount specified in StaleAfter, the SDK assumes that something is not working correctly in this process and that the data may not be accurate.

While in a stale state, the SDK will still continue using the last known data, but LDClient.GetBigSegmentsStoreStatusProvider().GetStatus() will return true in its Stale property, and any [ldreason.EvaluationReason] generated from a feature flag that references a Big Segment will have an BigSegmentsStatus of [ldreason.BigSegmentsStale].

func (*BigSegmentsConfigurationBuilder) StatusPollInterval

func (b *BigSegmentsConfigurationBuilder) StatusPollInterval(
	statusPollInterval time.Duration,
) *BigSegmentsConfigurationBuilder

StatusPollInterval sets the interval at which the SDK will poll the Big Segment store to make sure it is available and to determine how long ago it was updated. The default value is DefaultBigSegmentsStatusPollInterval.

type EventProcessorBuilder

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

EventProcessorBuilder provides methods for configuring analytics event behavior.

See SendEvents for usage.

func SendEvents

func SendEvents() *EventProcessorBuilder

SendEvents returns a configuration builder for analytics event delivery.

The default configuration has events enabled with default settings. If you want to customize this behavior, call this method to obtain a builder, change its properties with the EventProcessorBuilder methods, and store it in the Events field of github.com/launchdarkly/go-server-sdk/v7.Config:

config := ld.Config{
    Events: ldcomponents.SendEvents().Capacity(5000).FlushInterval(2 * time.Second),
}

To disable analytics events, use NoEvents instead of SendEvents.

func (*EventProcessorBuilder) AllAttributesPrivate

func (b *EventProcessorBuilder) AllAttributesPrivate(value bool) *EventProcessorBuilder

AllAttributesPrivate sets whether or not all optional context attributes should be hidden from LaunchDarkly.

If this is true, all context attribute values (other than the key) will be private, not just the attributes specified with EventProcessorBuilder.PrivateAttributes or on a per-context basis with [ldcontext.Builder] methods. By default, it is false.

func (*EventProcessorBuilder) Build

Build is called internally by the SDK.

func (*EventProcessorBuilder) Capacity

func (b *EventProcessorBuilder) Capacity(capacity int) *EventProcessorBuilder

Capacity sets the capacity of the events buffer.

The client buffers up to this many events in memory before flushing. If the capacity is exceeded before the buffer is flushed (see EventProcessorBuilder.FlushInterval), events will be discarded. Increasing the capacity means that events are less likely to be discarded, at the cost of consuming more memory.

The default value is DefaultEventsCapacity.

func (*EventProcessorBuilder) ContextKeysCapacity

func (b *EventProcessorBuilder) ContextKeysCapacity(contextKeysCapacity int) *EventProcessorBuilder

ContextKeysCapacity sets the number of context keys that the event processor can remember at any one time.

To avoid sending duplicate context details in analytics events, the SDK maintains a cache of recently seen context keys, expiring at an interval set by EventProcessorBuilder.ContextKeysFlushInterval.

The default value is DefaultContextKeysCapacity.

func (*EventProcessorBuilder) ContextKeysFlushInterval

func (b *EventProcessorBuilder) ContextKeysFlushInterval(interval time.Duration) *EventProcessorBuilder

ContextKeysFlushInterval sets the interval at which the event processor will reset its cache of known context keys.

The default value is DefaultContextKeysFlushInterval.

func (*EventProcessorBuilder) DescribeConfiguration

func (b *EventProcessorBuilder) DescribeConfiguration(context subsystems.ClientContext) ldvalue.Value

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

func (*EventProcessorBuilder) DiagnosticRecordingInterval

func (b *EventProcessorBuilder) DiagnosticRecordingInterval(interval time.Duration) *EventProcessorBuilder

DiagnosticRecordingInterval sets the interval at which periodic diagnostic data is sent.

The default value is DefaultDiagnosticRecordingInterval; the minimum value is MinimumDiagnosticRecordingInterval. This property is ignored if Config.DiagnosticOptOut is set to true.

func (*EventProcessorBuilder) FlushInterval

func (b *EventProcessorBuilder) FlushInterval(interval time.Duration) *EventProcessorBuilder

FlushInterval sets the interval between flushes of the event buffer.

Decreasing the flush interval means that the event buffer is less likely to reach capacity (see EventProcessorBuilder.Capacity).

The default value is DefaultFlushInterval.

func (*EventProcessorBuilder) PrivateAttributes

func (b *EventProcessorBuilder) PrivateAttributes(attributes ...string) *EventProcessorBuilder

PrivateAttributes marks a set of attribute names as always private.

Any contexts sent to LaunchDarkly with this configuration active will have attributes with these names removed. This is in addition to any attributes that were marked as private for an individual context with ldcontext.Builder methods. Setting EventProcessorBuilder.AllAttributesPrivate to true overrides this.

config := ld.Config{
    Events: ldcomponents.SendEvents().
        PrivateAttributeNames("email", "some-custom-attribute"),
}

If and only if a parameter starts with a slash, it is interpreted as a slash-delimited path that can denote a nested property within a JSON object. For instance, "/address/street" means that if there is an attribute called "address" that is a JSON object, and one of the object's properties is "street", the "street" property will be redacted from the analytics data but other properties within "address" will still be sent. This syntax also uses the JSON Pointer convention of escaping a literal slash character as "~1" and a tilde as "~0".

This method replaces any previous parameters that were set on the same builder with PrivateAttributes, rather than adding to them.

type HTTPConfigurationBuilder

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

HTTPConfigurationBuilder contains methods for configuring the SDK's networking behavior.

If you want to set non-default values for any of these properties, create a builder with ldcomponents.HTTPConfiguration(), change its properties with the HTTPConfigurationBuilder methods, and store it in the HTTP field of github.com/launchdarkly/go-server-sdk/v7.Config:

    config := ld.Config{
        HTTP: ldcomponents.HTTPConfiguration().
            ConnectTimeout(3 * time.Second).
		       ProxyURL(proxyUrl),
    }

func HTTPConfiguration

func HTTPConfiguration() *HTTPConfigurationBuilder

HTTPConfiguration returns a configuration builder for the SDK's HTTP configuration.

    config := ld.Config{
        HTTP: ldcomponents.HTTPConfiguration().
            ConnectTimeout(3 * time.Second).
		       ProxyURL(proxyUrl),
    }

func (*HTTPConfigurationBuilder) Build

Build is called internally by the SDK.

func (*HTTPConfigurationBuilder) CACert

CACert specifies a CA certificate to be added to the trusted root CA list for HTTPS requests.

If the certificate is not valid, the LDClient constructor will return an error when you try to create the client.

func (*HTTPConfigurationBuilder) CACertFile

func (b *HTTPConfigurationBuilder) CACertFile(filePath string) *HTTPConfigurationBuilder

CACertFile specifies a CA certificate to be added to the trusted root CA list for HTTPS requests, reading the certificate data from a file in PEM format.

If the certificate is not valid or the file does not exist, the LDClient constructor will return an error when you try to create the client.

func (*HTTPConfigurationBuilder) ConnectTimeout

func (b *HTTPConfigurationBuilder) ConnectTimeout(connectTimeout time.Duration) *HTTPConfigurationBuilder

ConnectTimeout sets the connection timeout.

This is the maximum amount of time to wait for each individual connection attempt to a remote service before determining that that attempt has failed. It is not the same as the timeout for initializing the SDK client (the waitFor parameter to MakeClient); that is the total length of time that MakeClient will wait regardless of how many connection attempts are required.

config := ld.Config{
    HTTP: ldcomponents.ConnectTimeout(),
}

func (*HTTPConfigurationBuilder) DescribeConfiguration

func (b *HTTPConfigurationBuilder) DescribeConfiguration(context subsystems.ClientContext) ldvalue.Value

DescribeConfiguration is internally by the SDK to inspect the configuration.

func (*HTTPConfigurationBuilder) HTTPClientFactory

func (b *HTTPConfigurationBuilder) HTTPClientFactory(httpClientFactory func() *http.Client) *HTTPConfigurationBuilder

HTTPClientFactory specifies a function for creating each HTTP client instance that is used by the SDK.

If you use this option, it overrides any other settings that you may have specified with HTTPConfigurationBuilder.ConnectTimeout or HTTPConfigurationBuilder.ProxyURL; you are responsible for setting up any desired custom configuration on the HTTP client. The SDK may modify the client properties after the client is created (for instance, to add caching), but will not replace the underlying http.Transport, and will not modify any timeout properties you set.

func (*HTTPConfigurationBuilder) Header

Header specifies a custom HTTP header that should be added to all requests. Repeated calls to Header with the same key will overwrite previous entries.

This may be helpful if you are using a gateway or proxy server that requires a specific header in requests.

Overwriting the User-Agent or Authorization headers is not recommended, as it can interfere with communication to LaunchDarkly. To set a custom User Agent, see UserAgent.

func (*HTTPConfigurationBuilder) ProxyURL

ProxyURL specifies a proxy URL to be used for all requests. This overrides any setting of the HTTP_PROXY, HTTPS_PROXY, or NO_PROXY environment variables.

If the string is not a valid URL, the LDClient constructor will return an error when you try to create the client.

To pass basic proxy credentials, use the format 'scheme://username:password@host:port'.

func (*HTTPConfigurationBuilder) UserAgent

func (b *HTTPConfigurationBuilder) UserAgent(userAgent string) *HTTPConfigurationBuilder

UserAgent specifies an additional User-Agent header value to send with HTTP requests.

func (*HTTPConfigurationBuilder) Wrapper

func (b *HTTPConfigurationBuilder) Wrapper(wrapperName, wrapperVersion string) *HTTPConfigurationBuilder

Wrapper allows wrapper libraries to set an identifying name for the wrapper being used.

This will be sent in request headers during requests to the LaunchDarkly servers to allow recording metrics on the usage of these wrapper libraries.

type LoggingConfigurationBuilder

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

LoggingConfigurationBuilder contains methods for configuring the SDK's logging behavior.

If you want to set non-default values for any of these properties, create a builder with ldcomponents.Logging(), change its properties with the LoggingConfigurationBuilder methods, and store it in the Logging field of github.com/launchdarkly/go-server-sdk/v7.Config:

config := ld.Config{
    Logging: ldcomponents.Logging().MinLevel(ldlog.Warn),
}

func Logging

func Logging() *LoggingConfigurationBuilder

Logging returns a configuration builder for the SDK's logging configuration.

The default configuration has logging enabled with default settings. If you want to set non-default values for any of these properties, create a builder with ldcomponents.Logging(), change its properties with the LoggingConfigurationBuilder methods, and store it in Config.Logging:

config := ld.Config{
    Logging: ldcomponents.Logging().MinLevel(ldlog.Warn),
}

func (*LoggingConfigurationBuilder) Build

Build is called internally by the SDK.

func (*LoggingConfigurationBuilder) LogContextKeyInErrors

func (b *LoggingConfigurationBuilder) LogContextKeyInErrors(logContextKeyInErrors bool) *LoggingConfigurationBuilder

LogContextKeyInErrors sets whether log messages for errors related to a specific evaluation context can include the context key. By default, they will not, since the key might be considered privileged information.

func (*LoggingConfigurationBuilder) LogDataSourceOutageAsErrorAfter

func (b *LoggingConfigurationBuilder) LogDataSourceOutageAsErrorAfter(
	logDataSourceOutageAsErrorAfter time.Duration,
) *LoggingConfigurationBuilder

LogDataSourceOutageAsErrorAfter sets the time threshold, if any, after which the SDK will log a data source outage at Error level instead of Warn level.

A data source outage means that an error condition, such as a network interruption or an error from the LaunchDarkly service, is preventing the SDK from receiving feature flag updates. Many outages are brief and the SDK can recover from them quickly; in that case it may be undesirable to log an Error line, which might trigger an unwanted automated alert depending on your monitoring tools. So, by default, the SDK logs such errors at Warn level. However, if the amount of time specified by this method elapses before the data source starts working again, the SDK will log an additional message at Error level to indicate that this is a sustained problem.

The default is DefaultLogDataSourceOutageAsErrorAfter (one minute). Setting it to zero will disable this feature, so you will only get Warn messages.

func (*LoggingConfigurationBuilder) LogEvaluationErrors

func (b *LoggingConfigurationBuilder) LogEvaluationErrors(logEvaluationErrors bool) *LoggingConfigurationBuilder

LogEvaluationErrors sets whether the client should log a warning message whenever a flag cannot be evaluated due to an error (e.g. there is no flag with that key, or the context properties are invalid). By default, these messages are not logged, although you can detect such errors programmatically using the VariationDetail methods. The only exception is that the SDK will always log any error involving invalid flag data, because such data should not be possible and indicates that LaunchDarkly support assistance may be required.

func (*LoggingConfigurationBuilder) Loggers

Loggers specifies an instance of ldlog.Loggers to use for SDK logging. The ldlog package contains methods for customizing the destination and level filtering of log output.

func (*LoggingConfigurationBuilder) MinLevel

MinLevel specifies the minimum level for log output, where ldlog.Debug is the lowest and ldlog.Error is the highest. Log messages at a level lower than this will be suppressed. The default is ldlog.Info.

This is equivalent to creating an ldlog.Loggers instance, calling SetMinLevel() on it, and then passing it to LoggingConfigurationBuilder.Loggers().

type PersistentDataStoreBuilder

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

PersistentDataStoreBuilder is a configurable factory for a persistent data store.

Each LaunchDarkly Go SDK database integration has its own configuration builder, with builder methods for options that are specific to that database. The SDK also provides some universal behaviors for all persistent data stores, such as caching; PersistentDataStoreBuilder provides methods to configure those behaviors. For instance, in this example, URL() is an option that is specific to the Redis integration, whereas CacheSeconds is not specific to Redis:

config := ld.Config{
    DataStore: ldcomponents.PersistentDataStore(
        ldredis.DataStore().URL("redis://my-redis-host"),
    ).CacheSeconds(15),
}

func PersistentDataStore

func PersistentDataStore(
	persistentDataStoreFactory subsystems.ComponentConfigurer[subsystems.PersistentDataStore],
) *PersistentDataStoreBuilder

PersistentDataStore returns a configuration builder for some implementation of a persistent data store.

The return value of this function should be stored in the DataStore field of github.com/launchdarkly/go-server-sdk/v7.Config.

This method is used in conjunction with another configuration builder object provided by specific packages such as the Redis integration. Each LaunchDarkly Go SDK database integration has a DataStore() method that returns a configuration builder, with builder methods for options that are specific to that database. The SDK also provides some universal behaviors for all persistent data stores, such as caching; PersistentDataStoreBuilder provides methods to configure those behaviors. For instance, in this example, URL() is an option that is specific to the Redis integration, whereas CacheSeconds is not specific to Redis:

config := ld.Config{
    DataStore: ldcomponents.PersistentDataStore(
        ldredis.DataStore().URL("redis://my-redis-host"),
    ).CacheSeconds(15),
}

See PersistentDataStoreBuilder for more on how this method is used.

For more information on the available persistent data store implementations, see the reference guide on "Persistent data stores": https://docs.launchdarkly.com/sdk/concepts/data-stores

func (*PersistentDataStoreBuilder) Build

Build is called internally by the SDK.

func (*PersistentDataStoreBuilder) CacheForever

CacheForever specifies that the in-memory cache should never expire. In this mode, data will be written to both the underlying persistent store and the cache, but will only ever be read from the persistent store if the SDK is restarted.

Use this 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.

func (*PersistentDataStoreBuilder) CacheSeconds

func (b *PersistentDataStoreBuilder) CacheSeconds(cacheSeconds int) *PersistentDataStoreBuilder

CacheSeconds is a shortcut for calling PersistentDataStoreBuilder.CacheTime with a duration in seconds.

func (*PersistentDataStoreBuilder) CacheTime

CacheTime specifies the cache TTL. Items will be evicted from the cache after this amount of time from the time when they were originally cached.

If the value is zero, caching is disabled (equivalent to PersistentDataStoreBuilder.NoCaching).

If the value is negative, data is cached forever (equivalent to PersistentDataStoreBuilder.CacheForever).

func (*PersistentDataStoreBuilder) DescribeConfiguration

func (b *PersistentDataStoreBuilder) DescribeConfiguration(context subsystems.ClientContext) ldvalue.Value

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

func (*PersistentDataStoreBuilder) NoCaching

NoCaching specifies that the SDK should not use an in-memory cache for the persistent data store. This means that every feature flag evaluation will trigger a data store query.

type PollingDataSourceBuilder

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

PollingDataSourceBuilder provides methods for configuring the polling data source.

See PollingDataSource for usage.

func PollingDataSource

func PollingDataSource() *PollingDataSourceBuilder

PollingDataSource returns a configurable factory for using polling mode to get feature flag data.

Polling is not the default behavior; by default, the SDK uses a streaming connection to receive feature flag data from LaunchDarkly. In polling mode, the SDK instead makes a new HTTP request to LaunchDarkly at regular intervals. HTTP caching allows it to avoid redundantly downloading data if there have been no changes, but polling is still less efficient than streaming and should only be used on the advice of LaunchDarkly support.

To use polling mode, create a builder with PollingDataSource(), set its properties with the methods of PollingDataSourceBuilder, and then store it in the DataSource field of github.com/launchdarkly/go-server-sdk/v7.Config:

config := ld.Config{
    DataSource: ldcomponents.PollingDataSource().PollInterval(45 * time.Second),
}

func (*PollingDataSourceBuilder) Build

Build is called internally by the SDK.

func (*PollingDataSourceBuilder) DescribeConfiguration

func (b *PollingDataSourceBuilder) DescribeConfiguration(context subsystems.ClientContext) ldvalue.Value

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

func (*PollingDataSourceBuilder) PayloadFilter

func (b *PollingDataSourceBuilder) PayloadFilter(filterKey string) *PollingDataSourceBuilder

PayloadFilter sets the filter key for the polling connection.

By default, the SDK is able to evaluate all flags in an environment. If this is undesirable - for example, the environment contains thousands of flags, but this application only needs to evaluate a smaller, known subset - then a filter may be setup in LaunchDarkly, and the filter's key specified here.

Evaluations for flags that aren't part of the filtered environment will return default values.

func (*PollingDataSourceBuilder) PollInterval

func (b *PollingDataSourceBuilder) PollInterval(pollInterval time.Duration) *PollingDataSourceBuilder

PollInterval sets the interval at which the SDK will poll for feature flag updates.

The default and minimum value is DefaultPollInterval. Values less than this will be set to the default.

type StreamingDataSourceBuilder

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

StreamingDataSourceBuilder provides methods for configuring the streaming data source.

See StreamingDataSource for usage.

func StreamingDataSource

func StreamingDataSource() *StreamingDataSourceBuilder

StreamingDataSource returns a configurable factory for using streaming mode to get feature flag data.

By default, the SDK uses a streaming connection to receive feature flag data from LaunchDarkly. To use the default behavior, you do not need to call this method. However, if you want to customize the behavior of the connection, call this method to obtain a builder, set its properties with the StreamingDataSourceBuilder methods, and then store it in the DataSource field of github.com/launchdarkly/go-server-sdk/v7.Config:

config := ld.Config{
    DataSource: ldcomponents.StreamingDataSource().InitialReconnectDelay(500 * time.Millisecond),
}

func (*StreamingDataSourceBuilder) Build

Build is called internally by the SDK.

func (*StreamingDataSourceBuilder) DescribeConfiguration

func (b *StreamingDataSourceBuilder) DescribeConfiguration(context subsystems.ClientContext) ldvalue.Value

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

func (*StreamingDataSourceBuilder) InitialReconnectDelay

func (b *StreamingDataSourceBuilder) InitialReconnectDelay(
	initialReconnectDelay time.Duration,
) *StreamingDataSourceBuilder

InitialReconnectDelay sets the initial reconnect delay for the streaming connection.

The streaming service uses a backoff algorithm (with jitter) every time the connection needs to be reestablished. The delay for the first reconnection will start near this value, and then increase exponentially for any subsequent connection failures.

The default value is DefaultInitialReconnectDelay.

func (*StreamingDataSourceBuilder) PayloadFilter

func (b *StreamingDataSourceBuilder) PayloadFilter(filterKey string) *StreamingDataSourceBuilder

PayloadFilter sets the payload filter key for this streaming connection. The filter key cannot be an empty string.

By default, the SDK is able to evaluate all flags in an environment. If this is undesirable - for example, the environment contains thousands of flags, but this application only needs to evaluate a smaller, known subset - then a payload filter may be setup in LaunchDarkly, and the filter's key specified here.

Evaluations for flags that aren't part of the filtered environment will return default values.

Jump to

Keyboard shortcuts

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