ldcomponents

package
v5.10.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: Apache-2.0 Imports: 17 Imported by: 7

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
	// DefaultUserKeysCapacity is the default value for EventProcessorBuilder.UserKeysCapacity.
	DefaultUserKeysCapacity = 1000
	// DefaultUserKeysFlushInterval is the default value for EventProcessorBuilder.UserKeysFlushInterval.
	DefaultUserKeysFlushInterval = 5 * time.Minute
	// MinimumDiagnosticRecordingInterval is the minimum value for EventProcessorBuilder.DiagnosticRecordingInterval.
	MinimumDiagnosticRecordingInterval = 60 * time.Second
)
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 DefaultBigSegmentsUserCacheSize = 1000

DefaultBigSegmentsUserCacheSize is the default value for BigSegmentsConfigurationBuilder.UserCacheSize.

View Source
const DefaultBigSegmentsUserCacheTime = time.Second * 5

DefaultBigSegmentsUserCacheTime is the default value for BigSegmentsConfigurationBuilder.UserCacheTime.

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 the PersistentDataStoreBuilder.CacheTime() option.

Variables

This section is empty.

Functions

func ExternalUpdatesOnly

func ExternalUpdatesOnly() interfaces.DataSourceFactory

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

Storing this in LDConfig.DataSource 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

func InMemoryDataStore() interfaces.DataStoreFactory

InMemoryDataStore returns the default in-memory DataStore implementation factory.

func NoEvents

NoEvents returns a configuration object that disables analytics events.

Storing this in Config.Events 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 added in v5.8.0

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 your SDK configuration. 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 added in v5.8.0

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.

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 added in v5.5.0

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 Config.BigSegments:

    config := ld.Config{
        BigSegments: ldcomponents.BigSegments(ldredis.DataStore()).
            UserCacheSize(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 added in v5.5.0

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.DataStore().Prefix("app1")).
        UserCacheSize(2000),
}

You must always specify the storeFactory parameter, to tell the SDK what database you are using. Several database integrations exist for the LaunchDarkly SDK, each with its own behavior and options specific to that database; this is described via some implementation of BigSegmentStoreFactory. 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 UserCacheSize() 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 storeFactory to this function-- the Big Segments feature will be disabled, and any feature flags that reference a Big Segment will behave as if the user was not included in the segment.

func (*BigSegmentsConfigurationBuilder) CreateBigSegmentsConfiguration added in v5.5.0

func (b *BigSegmentsConfigurationBuilder) CreateBigSegmentsConfiguration(
	context interfaces.ClientContext,
) (interfaces.BigSegmentsConfiguration, error)

CreateBigSegmentsConfiguration is called internally by the SDK.

func (*BigSegmentsConfigurationBuilder) StaleAfter added in v5.5.0

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 added in v5.5.0

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.

func (*BigSegmentsConfigurationBuilder) UserCacheSize added in v5.5.0

func (b *BigSegmentsConfigurationBuilder) UserCacheSize(
	userCacheSize int,
) *BigSegmentsConfigurationBuilder

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

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

A higher value for UserCacheSize 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 UserCacheTime.

func (*BigSegmentsConfigurationBuilder) UserCacheTime added in v5.5.0

UserCacheTime sets the maximum length of time that the Big Segment state for a user will be cached by the SDK. The default value is DefaultBigSegmentsUserCacheTime.

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

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 Config.Events:

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 user attributes should be hidden from LaunchDarkly.

If this is true, all user attribute values (other than the key) will be private, not just the attributes specified with PrivateAttributeNames or on a per-user basis with UserBuilder methods. By default, it is false.

func (*EventProcessorBuilder) BaseURI deprecated

func (b *EventProcessorBuilder) BaseURI(baseURI string) *EventProcessorBuilder

BaseURI is a deprecated method for setting a custom base URI for the events service.

If you set this deprecated option to a non-empty value, it overrides any value that was set with ServiceEndpoints.

Deprecated: Use config.ServiceEndpoints instead.

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

func (b *EventProcessorBuilder) CreateEventProcessor(
	context interfaces.ClientContext,
) (ldevents.EventProcessor, error)

CreateEventProcessor is called by the SDK to create the event processor instance.

func (*EventProcessorBuilder) DescribeConfiguration deprecated

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

DescribeConfiguration is obsolete and is not called by the SDK.

Deprecated: This method will be removed in a future major version release.

func (*EventProcessorBuilder) DescribeConfigurationContext added in v5.8.0

func (b *EventProcessorBuilder) DescribeConfigurationContext(context interfaces.ClientContext) ldvalue.Value

DescribeConfigurationContext 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 Capacity).

The default value is DefaultFlushInterval.

func (*EventProcessorBuilder) InlineUsersInEvents

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

InlineUsersInEvents sets whether to include full user details in every analytics event.

The default is false: events will only include the user key, except for one "index" event that provides the full details for the user.

func (*EventProcessorBuilder) PrivateAttributeNames

func (b *EventProcessorBuilder) PrivateAttributeNames(attributes ...lduser.UserAttribute) *EventProcessorBuilder

PrivateAttributeNames marks a set of attribute names as always private.

Any users 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 user with UserBuilder methods. Setting AllAttributePrivate to true overrides this.

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

func (*EventProcessorBuilder) UserKeysCapacity

func (b *EventProcessorBuilder) UserKeysCapacity(userKeysCapacity int) *EventProcessorBuilder

UserKeysCapacity sets the number of user keys that the event processor can remember at any one time.

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

The default value is DefaultUserKeysCapacity.

func (*EventProcessorBuilder) UserKeysFlushInterval

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

UserKeysFlushInterval sets the interval at which the event processor will reset its cache of known user keys.

The default value is DefaultUserKeysFlushInterval.

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 Config.HTTP:

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

func (b *HTTPConfigurationBuilder) CreateHTTPConfiguration(
	basicConfiguration interfaces.BasicConfiguration,
) (interfaces.HTTPConfiguration, error)

CreateHTTPConfiguration is called internally by the SDK.

func (*HTTPConfigurationBuilder) DescribeConfiguration

func (b *HTTPConfigurationBuilder) DescribeConfiguration() 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 ConnectTimeout or 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 Transport, and will not modify any timeout properties you set.

func (*HTTPConfigurationBuilder) Header added in v5.7.0

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 Config.Logging:

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

CreateLoggingConfiguration is called internally by the SDK.

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 user 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) LogUserKeyInErrors

func (b *LoggingConfigurationBuilder) LogUserKeyInErrors(logUserKeyInErrors bool) *LoggingConfigurationBuilder

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

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.

Several database integrations exist for the LaunchDarkly SDK, each with its own behavior and options specific to that database; this is described via some implementation of PersistentDataStoreFactory. There is also universal behavior that the SDK provides for all persistent data stores, such as caching; the PersistentDataStoreBuilder adds this.

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

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

In this example, URL() is an option specifically for the Redis integration, whereas CacheSeconds() is an option that can be used for any persistent data store.

func PersistentDataStore

func PersistentDataStore(persistentDataStoreFactory interfaces.PersistentDataStoreFactory) *PersistentDataStoreBuilder

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

This method is used in conjunction with another factory object provided by specific components such as the Redis integration. The latter provides builder methods for options that are specific to that integration, while the PersistentDataStoreBuilder provides options that are applicable to any persistent data store (such as caching). For example:

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) 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 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 NoCaching).

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

func (*PersistentDataStoreBuilder) CreateDataStore

func (b *PersistentDataStoreBuilder) CreateDataStore(
	context interfaces.ClientContext,
	dataStoreUpdates interfaces.DataStoreUpdates,
) (interfaces.DataStore, error)

CreateDataStore is called by the SDK to create the data store implemntation object.

func (*PersistentDataStoreBuilder) DescribeConfiguration

func (b *PersistentDataStoreBuilder) DescribeConfiguration() 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 your SDK configuration:

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

func (*PollingDataSourceBuilder) BaseURI deprecated

BaseURI is a deprecated method for setting a custom base URI for the polling service.

If you set this deprecated option to a non-empty value, it overrides any value that was set with ServiceEndpoints.

Deprecated: Use config.ServiceEndpoints instead.

func (*PollingDataSourceBuilder) CreateDataSource

func (b *PollingDataSourceBuilder) CreateDataSource(
	context interfaces.ClientContext,
	dataSourceUpdates interfaces.DataSourceUpdates,
) (interfaces.DataSource, error)

CreateDataSource is called by the SDK to create the data source instance.

func (*PollingDataSourceBuilder) DescribeConfiguration deprecated

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

DescribeConfiguration is obsolete and is not called by the SDK.

Deprecated: This method will be removed in a future major version release.

func (*PollingDataSourceBuilder) DescribeConfigurationContext added in v5.8.0

func (b *PollingDataSourceBuilder) DescribeConfigurationContext(context interfaces.ClientContext) ldvalue.Value

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

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 your SDK configuration:

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

func (*StreamingDataSourceBuilder) BaseURI deprecated

BaseURI is a deprecated method for setting a custom base URI for the polling service.

If you set this deprecated option to a non-empty value, it overrides any value that was set with ServiceEndpoints.

Deprecated: Use config.ServiceEndpoints instead.

func (*StreamingDataSourceBuilder) CreateDataSource

func (b *StreamingDataSourceBuilder) CreateDataSource(
	context interfaces.ClientContext,
	dataSourceUpdates interfaces.DataSourceUpdates,
) (interfaces.DataSource, error)

CreateDataSource is called by the SDK to create the data source instance.

func (*StreamingDataSourceBuilder) DescribeConfiguration deprecated

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

DescribeConfiguration is obsolete and is not called by the SDK.

Deprecated: This method will be removed in a future major version release.

func (*StreamingDataSourceBuilder) DescribeConfigurationContext added in v5.8.0

func (b *StreamingDataSourceBuilder) DescribeConfigurationContext(context interfaces.ClientContext) ldvalue.Value

DescribeConfigurationContext 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.

Directories

Path Synopsis
Package ldstoreimpl contains SDK data store implementation objects that may be used by external code such as custom data store integrations and internal LaunchDarkly components.
Package ldstoreimpl contains SDK data store implementation objects that may be used by external code such as custom data store integrations and internal LaunchDarkly components.

Jump to

Keyboard shortcuts

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