Documentation
¶
Overview ¶
Package lds3 provides an Amazon S3 data initializer for the LaunchDarkly Go SDK's data system.
The initializer reads one or more objects from an S3 bucket at startup and uses their contents as the SDK's initial set of flag and segment data. Initializers are one-shot: the SDK calls the initializer once during startup, and any ongoing updates must come from a separately configured synchronizer (or from nothing at all, if the S3 data is meant to be the only data source).
A typical use is a two-tier startup strategy: try LaunchDarkly first, and fall back to a known-good snapshot stored in S3 so that the application can always start, even during a network or service outage:
import (
ld "github.com/launchdarkly/go-server-sdk/v7"
"github.com/launchdarkly/go-server-sdk/v7/ldcomponents"
lds3 "github.com/launchdarkly/go-server-sdk-s3"
)
config := ld.Config{
DataSystem: ldcomponents.DataSystem().Custom().
Initializers(
ldcomponents.PollingDataSourceV2().AsInitializer(),
lds3.DataInitializer("my-bucket", "flags/snapshot.json"),
).
Synchronizers(ldcomponents.StreamingDataSourceV2()),
}
client, err := ld.MakeCustomClient("sdk-key", config, 5*time.Second)
The objects must be in the same JSON or YAML document format that the SDK's file data sources use, containing any combination of "flags", "flagValues", and "segments" properties. See the SDK's ldfiledata package documentation for a description of the format.
By default, the initializer creates an S3 client from the default AWS configuration sources (environment variables, shared config files, and instance metadata). Use the builder's methods to supply a custom aws.Config or a preconfigured client.
The initializer validates what it fetches: documents must be valid UTF-8, may be gzip-compressed when the object's Content-Encoding says so, are limited to a configurable maximum size, and a snapshot containing no flag or segment data is rejected rather than applied. The whole fetch is bounded by a configurable timeout so that a slow S3 request cannot consume the SDK's entire initialization wait budget.
Index ¶
- Constants
- type DataInitializerBuilder
- func (b *DataInitializerBuilder) AWSConfig(config aws.Config) *DataInitializerBuilder
- func (b *DataInitializerBuilder) Build(clientContext subsystems.ClientContext) (subsystems.DataInitializer, error)
- func (b *DataInitializerBuilder) DuplicateKeysHandling(duplicateKeysHandling DuplicateKeysHandling) *DataInitializerBuilder
- func (b *DataInitializerBuilder) MaxObjectSize(limit int64) *DataInitializerBuilder
- func (b *DataInitializerBuilder) ObjectKeys(objectKeys ...string) *DataInitializerBuilder
- func (b *DataInitializerBuilder) S3Client(client S3Client) *DataInitializerBuilder
- func (b *DataInitializerBuilder) Timeout(timeout time.Duration) *DataInitializerBuilder
- type DuplicateKeysHandling
- type S3Client
Constants ¶
const ( // DefaultMaxObjectSize is the default value for DataInitializerBuilder.MaxObjectSize: 100MB. DefaultMaxObjectSize int64 = 100 * 1024 * 1024 // DefaultTimeout is the default value for DataInitializerBuilder.Timeout. DefaultTimeout = 30 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DataInitializerBuilder ¶
type DataInitializerBuilder struct {
// contains filtered or unexported fields
}
DataInitializerBuilder is a builder for configuring the S3 data initializer.
Obtain an instance of this type by calling DataInitializer. After calling its methods to specify any desired custom settings, pass it to the Initializers method of github.com/launchdarkly/go-server-sdk/v7/ldcomponents.DataSystemConfigurationBuilder.
Builder calls can be chained, for example:
lds3.DataInitializer("my-bucket", "snapshot.json").AWSConfig(myConfig)
You do not need to call the builder's Build method yourself; that will be done by the SDK.
func DataInitializer ¶
func DataInitializer(bucket string, objectKeys ...string) *DataInitializerBuilder
DataInitializer returns a configurable builder for an S3 data initializer.
The bucket is the name of the S3 bucket to read from, and objectKeys are the keys of one or more objects within it, each containing flag data in the SDK's file data source format. At least one object key is required; additional keys may also be added with DataInitializerBuilder.ObjectKeys.
func (*DataInitializerBuilder) AWSConfig ¶
func (b *DataInitializerBuilder) AWSConfig(config aws.Config) *DataInitializerBuilder
AWSConfig specifies an AWS configuration to create the S3 client from, instead of the default configuration sources (environment variables, shared config files, and instance metadata).
This setting is ignored if a client is provided with DataInitializerBuilder.S3Client.
func (*DataInitializerBuilder) Build ¶
func (b *DataInitializerBuilder) Build( clientContext subsystems.ClientContext, ) (subsystems.DataInitializer, error)
Build creates a DataInitializer instance that can be used by the SDK client.
func (*DataInitializerBuilder) DuplicateKeysHandling ¶
func (b *DataInitializerBuilder) DuplicateKeysHandling( duplicateKeysHandling DuplicateKeysHandling, ) *DataInitializerBuilder
DuplicateKeysHandling specifies how to handle flag or segment keys that are duplicated across objects.
If this is not specified, or if you set it to an unrecognized value, the default is DuplicateKeysFail.
func (*DataInitializerBuilder) MaxObjectSize ¶
func (b *DataInitializerBuilder) MaxObjectSize(limit int64) *DataInitializerBuilder
MaxObjectSize specifies the maximum size in bytes of a single object's flag data. The limit applies to each object separately, and to the decompressed content if an object is compressed. Reading stops with an error if an object exceeds it.
The limit exists so that a misconfigured object key cannot make the SDK buffer an arbitrarily large download during startup. If this is not specified, the default is DefaultMaxObjectSize. The value must be greater than zero.
func (*DataInitializerBuilder) ObjectKeys ¶
func (b *DataInitializerBuilder) ObjectKeys(objectKeys ...string) *DataInitializerBuilder
ObjectKeys adds keys of objects to read from the bucket, after any keys that were previously specified.
func (*DataInitializerBuilder) S3Client ¶
func (b *DataInitializerBuilder) S3Client(client S3Client) *DataInitializerBuilder
S3Client specifies an existing S3 client instance for the initializer to use, instead of creating one. Use this if you need full control of the client's configuration, for example to point it at an S3-compatible service.
func (*DataInitializerBuilder) Timeout ¶
func (b *DataInitializerBuilder) Timeout(timeout time.Duration) *DataInitializerBuilder
Timeout specifies a time limit for the entire data-fetching operation, including reading every configured object. If the limit is reached, the initializer fails and the SDK moves on to the next initializer or synchronizer, instead of letting a slow S3 request consume the SDK's whole initialization wait budget.
If this is not specified, the default is DefaultTimeout. A value of zero disables the limit, leaving the operation bounded only by the SDK's initialization context. The value must not be negative.
type DuplicateKeysHandling ¶
type DuplicateKeysHandling string
DuplicateKeysHandling is a parameter type used with DataInitializerBuilder.DuplicateKeysHandling.
const ( // DuplicateKeysFail is an option for DataInitializerBuilder.DuplicateKeysHandling, meaning that // data loading should fail if keys are duplicated across objects. This is the default behavior. DuplicateKeysFail DuplicateKeysHandling = "fail" // DuplicateKeysKeepFirst is an option for DataInitializerBuilder.DuplicateKeysHandling, // meaning that if keys are duplicated across objects the first occurrence will be used, in the // order the object keys were given. DuplicateKeysKeepFirst DuplicateKeysHandling = "ignore" )
type S3Client ¶
type S3Client interface {
GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
}
S3Client is the subset of the AWS S3 client's operations that the data initializer uses. It is implemented by *s3.Client, and can be implemented by test fakes.