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.DataInitializerForObject("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" and "segments" properties. The file data sources' simplified "flagValues" entries are not supported; an object that contains a "flagValues" section is rejected. 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) *DataInitializerBuilderdeprecated
- func (b *DataInitializerBuilder) MaxObjectSize(limit int64) *DataInitializerBuilderdeprecated
- func (b *DataInitializerBuilder) MaxObjectSizeBytes(limit int64) *DataInitializerBuilder
- func (b *DataInitializerBuilder) ObjectKeys(objectKeys ...string) *DataInitializerBuilderdeprecated
- func (b *DataInitializerBuilder) S3Client(client S3Client) *DataInitializerBuilder
- func (b *DataInitializerBuilder) Timeout(timeout time.Duration) *DataInitializerBuilder
- type DuplicateKeysHandlingdeprecated
- type S3Client
Constants ¶
const ( // DefaultMaxObjectSizeBytes is the default value for DataInitializerBuilder.MaxObjectSizeBytes: // 100 MiB. DefaultMaxObjectSizeBytes int64 = 100 * 1024 * 1024 // DefaultMaxObjectSize is the default value for DataInitializerBuilder.MaxObjectSize: 100 MiB. // // Deprecated: Use [DefaultMaxObjectSizeBytes] instead. DefaultMaxObjectSize = DefaultMaxObjectSizeBytes // 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
deprecated
func DataInitializer(bucket string, objectKeys ...string) *DataInitializerBuilder
DataInitializer returns a configurable builder for an S3 data initializer.
Deprecated: Use DataInitializerForObject instead. The initializer reads one object; when more than one object key is given, only the first is used.
func DataInitializerForObject ¶ added in v0.2.0
func DataInitializerForObject(bucket string, objectKey string) *DataInitializerBuilder
DataInitializerForObject returns a configurable builder for an S3 data initializer.
The bucket is the name of the S3 bucket to read from, and objectKey is the key of an object within it, containing flag data in the SDK's file data source format.
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
deprecated
func (b *DataInitializerBuilder) DuplicateKeysHandling( DuplicateKeysHandling, ) *DataInitializerBuilder
DuplicateKeysHandling specifies how to handle flag or segment keys that are duplicated across objects.
Deprecated: The initializer reads one object, so this option has no effect.
func (*DataInitializerBuilder) MaxObjectSize
deprecated
func (b *DataInitializerBuilder) MaxObjectSize(limit int64) *DataInitializerBuilder
MaxObjectSize specifies the maximum size in bytes of the object's flag data.
Deprecated: Use DataInitializerBuilder.MaxObjectSizeBytes instead. The two methods have the same behavior.
func (*DataInitializerBuilder) MaxObjectSizeBytes ¶ added in v0.2.0
func (b *DataInitializerBuilder) MaxObjectSizeBytes(limit int64) *DataInitializerBuilder
MaxObjectSizeBytes specifies the maximum size in bytes of the object's flag data. The limit applies to the decompressed content if the object is compressed. Reading stops with an error if the 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 DefaultMaxObjectSizeBytes. The value must be greater than zero.
func (*DataInitializerBuilder) ObjectKeys
deprecated
func (b *DataInitializerBuilder) ObjectKeys(objectKeys ...string) *DataInitializerBuilder
ObjectKeys adds keys of objects to read from the bucket, after any keys that were previously specified.
Deprecated: The initializer reads one object; keys after the first are ignored.
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
deprecated
type DuplicateKeysHandling string
DuplicateKeysHandling is a parameter type used with DataInitializerBuilder.DuplicateKeysHandling.
Deprecated: The initializer reads one object, so keys cannot be duplicated across objects.
const ( // DuplicateKeysFail is an option for DataInitializerBuilder.DuplicateKeysHandling. // // Deprecated: The initializer reads one object, so this option has no effect. DuplicateKeysFail DuplicateKeysHandling = "fail" // DuplicateKeysKeepFirst is an option for DataInitializerBuilder.DuplicateKeysHandling. // // Deprecated: The initializer reads one object, so this option has no effect. 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.