Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ class StreamingBuilder {
return *this;
}

/**
* Overrides the streaming base URL for this specific source. When unset,
* the synchronizer uses the top-level ServiceEndpoints streaming URL.
* Intended for FDv2 configurations where individual synchronizers may
* target different endpoints.
*
* @param base_url The base URL to use for this source.
* @return Reference to this builder.
*/
template <typename T = SDK>
std::enable_if_t<is_server_sdk<T>::value, StreamingBuilder&> BaseUrl(
std::string base_url) {
config_.base_url_override = std::move(base_url);
return *this;
}

/**
* Build the streaming config. Used internal to the SDK.
* @return The built config.
Expand Down Expand Up @@ -119,6 +135,22 @@ class PollingBuilder {
return *this;
}

/**
* Overrides the polling base URL for this specific source. When unset,
* the synchronizer uses the top-level ServiceEndpoints polling URL.
* Intended for FDv2 configurations where individual synchronizers may
* target different endpoints.
*
* @param base_url The base URL to use for this source.
* @return Reference to this builder.
*/
template <typename T = SDK>
std::enable_if_t<is_server_sdk<T>::value, PollingBuilder&> BaseUrl(
std::string base_url) {
config_.base_url_override = std::move(base_url);
return *this;
}

/**
* Build the polling config. Used internal to the SDK.
* @return The built config.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ struct StreamingConfig<ServerSDK> {
std::chrono::milliseconds initial_reconnect_delay;
std::string streaming_path;
std::optional<std::string> filter_key;
std::optional<std::string> base_url_override;
};

inline bool operator==(StreamingConfig<ServerSDK> const& lhs,
StreamingConfig<ServerSDK> const& rhs) {
return lhs.initial_reconnect_delay == rhs.initial_reconnect_delay &&
lhs.streaming_path == rhs.streaming_path &&
lhs.filter_key == rhs.filter_key;
lhs.filter_key == rhs.filter_key &&
lhs.base_url_override == rhs.base_url_override;
}

template <typename SDK>
Expand All @@ -49,6 +51,7 @@ struct PollingConfig<ServerSDK> {
std::string polling_get_path;
std::chrono::seconds min_polling_interval;
std::optional<std::string> filter_key;
std::optional<std::string> base_url_override;
};

template <typename SDK>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <launchdarkly/server_side/config/builders/data_system/background_sync_builder.hpp>
#include <launchdarkly/server_side/config/builders/data_system/fdv2_builder.hpp>
#include <launchdarkly/server_side/config/builders/data_system/lazy_load_builder.hpp>
#include <launchdarkly/server_side/config/built/data_system/data_system_config.hpp>

Expand All @@ -13,6 +14,7 @@ class DataSystemBuilder {
DataSystemBuilder();
using BackgroundSync = BackgroundSyncBuilder;
using LazyLoad = LazyLoadBuilder;
using FDv2 = FDv2Builder;

/**
* @brief Alias for Enabled(false).
Expand Down Expand Up @@ -46,10 +48,19 @@ class DataSystemBuilder {
*/
DataSystemBuilder& Method(LazyLoad lazy_load);

/**
* @brief Configures the FDv2 data system, which receives flag delivery
* updates over the new changeset-based protocol with built-in fallback
* and recovery semantics.
* @param fdv2 FDv2 configuration.
* @return Reference to this.
*/
DataSystemBuilder& Method(FDv2 fdv2);

[[nodiscard]] tl::expected<built::DataSystemConfig, Error> Build() const;

private:
std::optional<std::variant<BackgroundSync, LazyLoad>> method_builder_;
std::optional<std::variant<BackgroundSync, LazyLoad, FDv2>> method_builder_;
built::DataSystemConfig config_;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#pragma once

#include <launchdarkly/config/shared/builders/data_source_builder.hpp>
#include <launchdarkly/config/shared/sdks.hpp>
#include <launchdarkly/server_side/config/built/data_system/fdv2_config.hpp>

#include <chrono>

namespace launchdarkly::server_side::config::builders {

class FDv2Builder {
public:
using Streaming = launchdarkly::config::shared::builders::StreamingBuilder<
launchdarkly::config::shared::ServerSDK>;
using Polling = launchdarkly::config::shared::builders::PollingBuilder<
launchdarkly::config::shared::ServerSDK>;

FDv2Builder();

/**
* @brief Appends a polling initializer to the initializers list. The
* first call to this method on a default-constructed builder replaces
* the spec-default initializer list; subsequent calls append.
* @param source Polling source configuration for the initializer.
* @return Reference to this.
*/
FDv2Builder& Initializer(Polling source);

/**
* @brief Appends a streaming synchronizer to the synchronizers list.
* Order in the list determines preference: the first entry is the
* primary synchronizer, subsequent entries are fallbacks. The first
* call to a Synchronizer overload on a default-constructed builder
* replaces the spec-default synchronizer list; subsequent calls append.
* @param source Streaming source configuration.
* @return Reference to this.
*/
FDv2Builder& Synchronizer(Streaming source);

/**
* @brief Appends a polling synchronizer to the synchronizers list. See
* Synchronizer(Streaming) for ordering and default-replacement
* semantics.
* @param source Polling source configuration.
* @return Reference to this.
*/
FDv2Builder& Synchronizer(Polling source);

/**
* @brief Configures the FDv1 streaming source used as a last-resort
* fallback when the LaunchDarkly service signals (via the
* X-LD-FD-Fallback header) that the SDK should switch to FDv1.
* Enabled by default with standard streaming settings.
* @param source Streaming source configuration to use for the FDv1
* fallback connection.
* @return Reference to this.
*/
FDv2Builder& FDv1Fallback(Streaming source);

/**
* @brief Configures the FDv1 polling source used as a last-resort
* fallback when the LaunchDarkly service signals (via the
* X-LD-FD-Fallback header) that the SDK should switch to FDv1.
* @param source Polling source configuration to use for the FDv1
* fallback connection.
* @return Reference to this.
*/
FDv2Builder& FDv1Fallback(Polling source);

/**
* @brief Disables the FDv1 fallback. After this call, an FDv1
* fallback directive from the service transitions the SDK to
* OFFLINE rather than reconnecting via FDv1.
* @return Reference to this.
*/
FDv2Builder& DisableFDv1Fallback();

/**
* @brief Sets how long the active synchronizer may remain interrupted
* before the orchestrator falls back to the next-preferred synchronizer.
* @param timeout Duration the synchronizer must be continuously
* interrupted for before fallback fires.
* @return Reference to this.
*/
FDv2Builder& FallbackTimeout(std::chrono::milliseconds timeout);

/**
* @brief Sets how long a fallback synchronizer must run successfully
* before the orchestrator attempts to recover to the primary
* synchronizer.
* @param timeout Duration the fallback synchronizer must run before a
* recovery attempt is made.
* @return Reference to this.
*/
FDv2Builder& RecoveryTimeout(std::chrono::milliseconds timeout);

[[nodiscard]] built::FDv2Config Build() const;

private:
built::FDv2Config config_;
bool initializers_explicit_;
bool synchronizers_explicit_;
};

} // namespace launchdarkly::server_side::config::builders
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <launchdarkly/server_side/config/built/data_system/background_sync_config.hpp>
#include <launchdarkly/server_side/config/built/data_system/fdv2_config.hpp>
#include <launchdarkly/server_side/config/built/data_system/lazy_load_config.hpp>

#include <variant>
Expand All @@ -9,7 +10,7 @@ namespace launchdarkly::server_side::config::built {

struct DataSystemConfig {
bool disabled;
std::variant<LazyLoadConfig, BackgroundSyncConfig> system_;
std::variant<LazyLoadConfig, BackgroundSyncConfig, FDv2Config> system_;
};

} // namespace launchdarkly::server_side::config::built
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <launchdarkly/config/shared/built/data_source_config.hpp>
#include <launchdarkly/config/shared/sdks.hpp>

#include <chrono>
#include <optional>
#include <variant>
#include <vector>

namespace launchdarkly::server_side::config::built {

struct FDv2Config {
using StreamingConfig =
launchdarkly::config::shared::built::StreamingConfig<
launchdarkly::config::shared::ServerSDK>;
using PollingConfig = launchdarkly::config::shared::built::PollingConfig<
launchdarkly::config::shared::ServerSDK>;

std::vector<PollingConfig> initializers;
std::vector<std::variant<StreamingConfig, PollingConfig>> synchronizers;
std::optional<std::variant<StreamingConfig, PollingConfig>> fdv1_fallback;
std::chrono::milliseconds fallback_timeout;
std::chrono::milliseconds recovery_timeout;
};

} // namespace launchdarkly::server_side::config::built
5 changes: 5 additions & 0 deletions libs/server-sdk/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ target_sources(${LIBNAME}
config/builders/data_system/background_sync_builder.cpp
config/builders/data_system/bootstrap_builder.cpp
config/builders/data_system/data_system_builder.cpp
config/builders/data_system/fdv2_builder.cpp
config/builders/data_system/lazy_load_builder.cpp
config/builders/data_system/data_destination_builder.cpp
config/builders/big_segments_builder.cpp
Expand Down Expand Up @@ -73,6 +74,10 @@ target_sources(${LIBNAME}
data_systems/fdv2/fdv2_data_system.cpp
data_systems/fdv2/fdv1_adapter_synchronizer.hpp
data_systems/fdv2/fdv1_adapter_synchronizer.cpp
data_systems/fdv2/synchronizer_factories.hpp
data_systems/fdv2/synchronizer_factories.cpp
data_systems/fdv2/initializer_factories.hpp
data_systems/fdv2/initializer_factories.cpp
data_systems/background_sync/sources/streaming/streaming_data_source.hpp
data_systems/background_sync/sources/streaming/streaming_data_source.cpp
data_systems/background_sync/sources/streaming/event_handler.hpp
Expand Down
Loading
Loading