ldstoreimpl

package
v6.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: Apache-2.0 Imports: 15 Imported by: 3

Documentation

Overview

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. Application code normally will not use this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllKinds

func AllKinds() []ldstoretypes.DataKind

AllKinds returns a list of supported StoreDataKinds. Among other things, this list might be used by data stores to know what data (namespaces) to expect.

func Features

func Features() ldstoretypes.DataKind

Features returns the StoreDataKind instance corresponding to feature flag data.

func NewBigSegmentMembershipFromSegmentRefs

func NewBigSegmentMembershipFromSegmentRefs(
	includedSegmentRefs []string,
	excludedSegmentRefs []string,
) subsystems.BigSegmentMembership

NewBigSegmentMembershipFromSegmentRefs creates a BigSegmentMembership based on the specified lists of included and excluded segment references. This method is intended to be used by Big Segment store implementations; application code does not need to use it.

As described in interfaces.BigSegmentMembership, a segmentRef is not the same as the key property in the segment data model; it includes the key but also versioning information that the SDK will provide. The store implementation should not be concerned with the format of this.

The returned object's CheckMembership method will return ldvalue.NewOptionalBool(true) for any segmentRef that is in the included list, ldvalue.NewOptionalBool(false) for any segmentRef that is in the excluded list and *not* also in the included list, and ldvalue.OptionalBool{} (undefined) for all others.

The exact implementation type of the returned value may vary, to provide the most efficient representation of the data.

func NewDataStoreEvaluatorDataProvider

func NewDataStoreEvaluatorDataProvider(store subsystems.DataStore, loggers ldlog.Loggers) ldeval.DataProvider

NewDataStoreEvaluatorDataProvider provides an adapter for using a DataStore with the Evaluator type in go-server-sdk-evaluation.

Normal use of the SDK does not require this type. It is provided for use by other LaunchDarkly components that use DataStore and Evaluator separately from the SDK.

func Segments

func Segments() ldstoretypes.DataKind

Segments returns the StoreDataKind instance corresponding to user segment data.

Types

type BigSegmentStoreWrapper

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

BigSegmentStoreWrapper is a component that adds status polling and caching to a BigSegmentStore, and provides integration with the evaluation engine.

This component is exposed in the SDK's public API because it needs to be used by the LaunchDarkly Relay Proxy as well (or any other component that is calling the evaluation engine in go-server-sdk-evaluation directly and needs to provide the same Big Segment functionality as the SDK). It implements the BigSegmentProvider interface that go-server-sdk-evaluation uses to query Big Segments (similar to how ldstoreimpl.NewDataStoreEvaluatorDataProvider provides an implementation of the DataProvider interface). It is also responsible for caching membership queries and polling the store's metadata to make sure it is not stale.

To avoid unnecessarily exposing implementation details that are subject to change, this type should not have any public methods that are not strictly necessary for its use by the SDK and by the Relay Proxy.

func NewBigSegmentStoreWrapperWithConfig

func NewBigSegmentStoreWrapperWithConfig(
	config BigSegmentsConfigurationProperties,
	statusUpdateFn func(interfaces.BigSegmentStoreStatus),
	loggers ldlog.Loggers,
) *BigSegmentStoreWrapper

NewBigSegmentStoreWrapperWithConfig creates a BigSegmentStoreWrapper.

It also immediately begins polling the store status, unless config.StatusPollingInitiallyPaused is true.

The BigSegmentStoreWrapper takes ownership of the BigSegmentStore's lifecycle at this point, so calling Close on the BigSegmentStoreWrapper will also close the store.

If not nil, statusUpdateFn will be called whenever the store status has changed.

func (*BigSegmentStoreWrapper) ClearCache

func (w *BigSegmentStoreWrapper) ClearCache()

ClearCache invalidates the cache of per-context Big Segment state, so subsequent queries will get the latest data.

This is used by the Relay Proxy, but is not currently used by the SDK otherwise.

func (*BigSegmentStoreWrapper) Close

func (w *BigSegmentStoreWrapper) Close()

Close shuts down the manager, the store, and the polling task.

func (*BigSegmentStoreWrapper) GetMembership

GetMembership is called by the evaluator when it needs to get the Big Segment membership state for an evaluation context.

If there is a cached membership state for the context, it returns the cached state. Otherwise, it converts the context key into the hash string used by the BigSegmentStore, queries the store, and caches the result. The returned status value indicates whether the query succeeded, and whether the result (regardless of whether it was from a new query or the cache) should be considered "stale".

We do not need to know the context kind, because each big segment can only be for one kind. Thus, if the memberships for context key "x" include segments A and B, it is OK if segment A is referring to the context {"kind": "user", "key": x"} while segment B is referring to the context {"kind": "org", "key": "x"}; even though those are two different contexts, there is no ambiguity when it comes to checking against either of those segments.

func (*BigSegmentStoreWrapper) GetStatus

GetStatus returns a BigSegmentStoreStatus describing whether the store seems to be available (that is, the last query to it did not return an error) and whether it is stale (that is, the last known update time is too far in the past).

If we have not yet obtained that information (the poll task has not executed yet), then this method immediately does a metadata query and waits for it to succeed or fail. This means that if an application using Big Segments evaluates a feature flag immediately after creating the SDK client, before the first status poll has happened, that evaluation may block for however long it takes to query the store.

func (*BigSegmentStoreWrapper) SetPollingActive

func (w *BigSegmentStoreWrapper) SetPollingActive(active bool)

SetPollingActive switches the polling task on or off.

This is used by the Relay Proxy, but is not currently used by the SDK otherwise.

type BigSegmentsConfigurationProperties

type BigSegmentsConfigurationProperties struct {
	// Store the data store instance that is used for Big Segments data. If nil, Big Segments are disabled.
	Store subsystems.BigSegmentStore

	// ContextCacheSize is the maximum number of contexts whose Big Segment state will be cached by the SDK
	// at any given time.
	ContextCacheSize int

	// ContextCacheTime is the maximum length of time that the Big Segment state for a context will be cached
	// by the SDK.
	ContextCacheTime time.Duration

	// StatusPollInterval is 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
	StatusPollInterval time.Duration

	// StaleAfter is the maximum length of time between updates of the Big Segments data before the data
	// is considered out of date.
	StaleAfter time.Duration

	// StartPolling is true if the polling task should be started immediately. Otherwise, it will only
	// start after calling BigSegmentsStoreWrapper.SetPollingActive(true). This property is always true
	// in regular use of the SDK; the Relay Proxy may set it to false.
	StartPolling bool
}

BigSegmentsConfigurationProperties encapsulates the SDK's configuration with regard to Big Segments.

This struct implements the BigSegmentsConfiguration interface, but allows for addition of new properties. In a future version, BigSegmentsConfigurationBuilder and other configuration builders may be changed to use concrete types instead of interfaces.

func (BigSegmentsConfigurationProperties) GetContextCacheSize

func (p BigSegmentsConfigurationProperties) GetContextCacheSize() int

func (BigSegmentsConfigurationProperties) GetContextCacheTime

func (p BigSegmentsConfigurationProperties) GetContextCacheTime() time.Duration

func (BigSegmentsConfigurationProperties) GetStaleAfter

func (BigSegmentsConfigurationProperties) GetStatusPollInterval

func (p BigSegmentsConfigurationProperties) GetStatusPollInterval() time.Duration

func (BigSegmentsConfigurationProperties) GetStore

Jump to

Keyboard shortcuts

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