5.0.0
[5.0.0] - 2020-09-18
This is a major rewrite that introduces a cleaner API design, adds new features, and makes the SDK code easier to maintain and extend. See the Go 4.x to 5.0 migration guide for an in-depth look at the changes in this version; the following is a summary.
Added:
- You can tell the SDK to notify you whenever a feature flag's configuration has changed (either in general, or in terms of its result for a specific user), using
LDClient.GetFlagTracker(). - You can monitor the status of the SDK's data source (which normally means the streaming connection to the LaunchDarkly service) with
LDClient.GetDataSourceStatusProvider(). This allows you to check the current connection status, and to be notified if this status changes. - You can monitor the status of a persistent data store with
LDClient.GetDataStoreStatusProvider(). This allows you to check whether database updates are succeeding, to be notified if this status changes, and to get caching statistics. LDClient.WithEventsDisabled()is a decorator that allows you to temporarily turn off analytics events even if events are enabled in your configuration.LDConfig.Loggingis a new configuration category for options related to logging. Seeldcomponents.Logging()andldcomponents.NoLogging().- The
testhelpers/ldtestdatapackage provides an alternative toldfiledatafor simulating feature flag data in test code. - The object returned by
AllFlagsState()can now be constructed (such as for testing purposes) withflagstate.NewAllFlagsBuilder(). - In
interfaces,LDClientInterface,LDClientEvaluations, andLDClientEventsare new interfaces describing the existing methods ofLDClient. These may be useful for creating mocks in testing.
Changed (breaking changes from 4.x):
- The
UserandUserBuildertypes are now in the packagegopkg.in/launchdarkly/go-sdk-common.v2/lduser. Users can no longer be created as inline structs; you must uselduser.NewUser,lduser.NewAnonymousUser, orlduser.NewUserBuilder. - The
EvaluationDetailandEvaluationReasontypes are now in the packagegopkg.in/launchdarkly/go-sdk-common.v2/ldreason. EvaluationDetail.VariationIndexnow uses the typeldvalue.OptionalIntinstead of the*intpointer type.EvaluationReasonis now a struct rather than an interface, and is just one type rather than having separate types for eachKind.- The
ldlog.Loggersabstraction is now in the packagegopkg.in/launchdarkly/go-sdk-common.v2/ldlog. - Configuration properties that are specific to one mode of operation are no longer represented as fields in
Config, but as builder methods on a component that is provided by the newldcomponentspackage and is then placed inConfig. For instance, instead of settingCapacity: 1000, you would now setEvents: ldcomponents.SendEvents().Capacity(1000); to disable events, instead of settingSendEvents: false, you would setEvents: ldcomponents.NoEvents()(note thatNoEventsdoes not allow you to setCapacity, since that would be meaningless if events are disabled). Similarly, to disable streaming and use polling, setDataSource: ldcomponents.PollingDataSource()which then provides optional methods for configuring polling. SeeConfigandldcomponentsfor more details. - The database integrations that were formerly in the
redis,lddynamodb, andldconsulsubpackages have been moved to their own repositories: go-server-sdk-redis-redigo, go-server-sdk-dynamodb, and go-server-sdk-consul. This removes the transitive dependencies on Redigo, AWS, etc.— which would otherwise be loaded for all Go modules that reference the SDK, even if you do not reference the subpackages that use them— and also allows fixes or new features to be released for those integrations without requiring a new SDK release. - The configuration syntax for the database integrations has changed so that they now use a builder pattern, instead of a factory function with option arguments, and must be used in combination with
ldcomponents.PersistentDataStore. See the new repositories for documentation and examples. - The
ldfiledataintegration now also uses a builder pattern for configuration. - Types related to
LDClient.AllFlagsState()are now in theinterfaces/flagstatepackage, and their names have changed as follows:FeatureFlagsStateis nowflagstate.AllFlags;ClientSideOnlyis nowflagstate.OptionClientSideOnly();DetailsOnlyForTrackedFlags is nowflagstate.OptionDetailsOnlyForTrackedFlags()`. - The component interfaces
FeatureStoreandUpdateProcessorhave been renamed toDataStoreandDataSource. The factory interfaces for these components now receive SDK configuration options in a different way that does not expose other components' configurations to each other. - The
PersistentDataStoreinterface for creating your own database integrations has been simplified by moving all of the serialization and caching logic into the main SDK code. FeatureFlag,Segment, and other data model types are now in the packagegopkg.in/launchdarkly/go-server-sdk-evaluation.v1. Application code will not normally need to refer to these types.- All types related to the low-level handling of analytics events are now in the package
gopkg.in/launchdarkly/go-sdk-events.v1. Application code will not normally need to refer to these types.
Changed (requirements/dependencies/build):
- The lowest supported Go version is 1.14.
- Code coverage reports and benchmarks are now generated in every build. Unit test coverage of the entire SDK codebase has been greatly improved.
Changed (behavioral changes):
- If analytics events are disabled, the SDK now avoids generating any analytics event objects internally. Previously they were created and then discarded, causing unnecessary heap churn.
- Network failures and server errors for streaming or polling requests were previously logged at
ERRORlevel in most cases but sometimes atWARNlevel. They are now all atWARNlevel, but with a new behavior: if connection failures continue without a successful retry for a certain amount of time, the SDK will log a specialERROR-level message to warn you that this is not just a brief outage. The amount of time is one minute by default, but can be changed with the newLogDataSourceOutageAsErrorAfteroption inLoggingConfigurationBuilder. - Reading a
Userfrom JSON withjson.Unmarshalnow returns an error if thekeyproperty is missing or null.
Changed (performance improvements):
- Improved the performance of flag evaluations when there is a very long user target list in a feature flag or user segment, by representing the user key collection internally as a map.
- Evaluation of rules involving regex matches, date/time values, and semantic versions, has been speeded up by pre-parsing the values in the rules. Also, parsing of date/time values and semantic versions in user attributes now uses a faster implementation and does not make any heap allocations.
- Evaluation of rules involving an equality match to multiple values (such as "name is one of X, Y, Z") has been speeded up by converting the list of values to a map.
- Many internal methods have been rewritten to reduce the number of heap allocations in general.
Removed:
DefaultConfigwas removed since it is no longer necessary: an emptyConfig{}is valid and will provide all of the documented default behavior. If you need to access the default value for a property, use the corresponding constant, such asldcomponents.DefaultEventsCapacity.- The
sharedtestsubpackage, which contains test helpers for the SDK itself, is now internal and cannot be used from application code. Test helpers that were meant to be public are now in thetesthelperssubpackage. - Removed all types, fields, and methods that were deprecated as of the most recent 4.x release.