Skip to content

Commit adaa4fa

Browse files
authored
chore: Add data system configuration. (#193)
Adds a configuration for the data system, this configuration is not yet in use. All methods, that will be eventually exposed, are currently set to internal. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Introduce an internal data system configuration with builders, predefined modes, and FDv2 polling/streaming data source builders, plus comprehensive tests. > > - **Configuration**: > - Add internal `Configuration.DataSystem` and `ConfigurationBuilder.DataSystem(...)` wiring. > - Expose `Components.DataSystem()` (internal) returning `DataSystemModes`. > - **Data system (internal)**: > - New builders and types: `DataSystemBuilder`, `DataSystemModes`, `DataSystemComponents`, `DataSystemConfiguration` (with `Initializers`, `Synchronizers`, `FDv1FallbackSynchronizer`, and persistent store with `ReadOnly/ReadWrite` modes). > - New FDv2 data source builders: `FDv2StreamingDataSourceBuilder` and `FDv2PollingDataSourceBuilder` with endpoint overrides and tuning options. > - **Tests**: > - Extend `ConfigurationTest` with cases covering default/streaming/polling/daemon/persistent-store/custom data system configurations and list replacement/aggregation behaviors. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 8d48a68. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 7db08b3 commit adaa4fa

File tree

10 files changed

+897
-4
lines changed

10 files changed

+897
-4
lines changed

pkgs/sdk/server/src/Components.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,5 +483,14 @@ public static StreamingDataSourceBuilder StreamingDataSource() =>
483483
/// </remarks>
484484
/// <returns>a configuration builder</returns>
485485
public static WrapperInfoBuilder WrapperInfo() => new WrapperInfoBuilder();
486+
487+
/// <summary>
488+
/// Returns a set of builder options for configuring the SDK data system. When the data system configuration
489+
/// is used it overrides <see cref="ConfigurationBuilder.DataSource"/> and
490+
/// <see cref="ConfigurationBuilder.DataStore"/> in the configuration.
491+
/// </summary>
492+
/// <returns>a configuration builder</returns>
493+
/// TODO: SDK-1678: Internal until ready for use.
494+
internal static DataSystemModes DataSystem() => new DataSystemModes();
486495
}
487496
}

pkgs/sdk/server/src/Configuration.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ public class Configuration
116116
/// Contains methods for configuring the SDK's 'plugins' to extend or customize SDK behavior.
117117
/// </summary>
118118
public PluginConfigurationBuilder Plugins { get; }
119+
120+
/// <summary>
121+
/// Contains the data system configuration.
122+
/// <para>
123+
/// This property is not stable, and not subject to any backwards compatibility guarantees or semantic versioning.
124+
/// It is not suitable for production usage. Do not use it. You have been warned.
125+
/// </para>
126+
/// </summary>
127+
/// TODO: SDK-1678: Internal until ready for use.
128+
internal DataSystemBuilder DataSystem { get; }
119129

120130
#endregion
121131

@@ -195,6 +205,7 @@ internal Configuration(ConfigurationBuilder builder)
195205
WrapperInfo = builder._wrapperInfo;
196206
Hooks = builder._hooks;
197207
Plugins = builder._plugins;
208+
DataSystem = builder._dataSystem;
198209
}
199210

200211
#endregion

pkgs/sdk/server/src/ConfigurationBuilder.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public sealed class ConfigurationBuilder
3232

3333
internal static readonly TimeSpan DefaultStartWaitTime = TimeSpan.FromSeconds(10);
3434

35-
// Let's try to keep these properties and methods alphabetical so they're easy to find. Note that they
36-
// are internal rather than private so that they can be read by the Configuration constructor.
35+
// Note that these are internal rather than private so that they can be read by the Configuration constructor.
3736
internal IComponentConfigurer<BigSegmentsConfiguration> _bigSegments = null;
3837
internal IComponentConfigurer<IDataSource> _dataSource = null;
3938
internal IComponentConfigurer<IDataStore> _dataStore = null;
@@ -49,6 +48,7 @@ public sealed class ConfigurationBuilder
4948
internal TimeSpan _startWaitTime = DefaultStartWaitTime;
5049
internal ApplicationInfoBuilder _applicationInfo;
5150
internal WrapperInfoBuilder _wrapperInfo;
51+
internal DataSystemBuilder _dataSystem;
5252

5353
#endregion
5454

@@ -87,6 +87,7 @@ internal ConfigurationBuilder(Configuration copyFrom)
8787
_serviceEndpointsBuilder = new ServiceEndpointsBuilder(copyFrom.ServiceEndpoints);
8888
_startWaitTime = copyFrom.StartWaitTime;
8989
_applicationInfo = copyFrom.ApplicationInfo;
90+
_dataSystem = copyFrom.DataSystem;
9091
}
9192

9293
#endregion
@@ -339,6 +340,7 @@ public ConfigurationBuilder SdkKey(string sdkKey)
339340
SetSdkKeyIfValid(sdkKey);
340341
return this;
341342
}
343+
342344
/// <summary>
343345
/// Sets the SDK's service URIs, using a configuration builder obtained from
344346
/// <see cref="Components.ServiceEndpoints"/>.
@@ -401,6 +403,30 @@ public ConfigurationBuilder WrapperInfo(WrapperInfoBuilder wrapperInfo)
401403
return this;
402404
}
403405

406+
/// <summary>
407+
/// Configure the data system.
408+
/// <para>
409+
/// This class is not stable, and not subject to any backwards compatibility guarantees or semantic versioning.
410+
/// It is not suitable for production usage. Do not use it. You have been warned.
411+
/// </para>
412+
/// </summary>
413+
/// <remarks>
414+
/// <example>
415+
/// <code>
416+
/// var config = Configuration.Builder("my-sdk-key")
417+
/// .DataSystem(Components.DataSystem().Default());
418+
/// </code>
419+
/// </example>
420+
/// </remarks>
421+
/// <param name="dataSystemBuilder">the data system builder</param>
422+
/// <returns>the same builder</returns>
423+
/// TODO: SDK-1678: Internal until ready for use.
424+
internal ConfigurationBuilder DataSystem(DataSystemBuilder dataSystemBuilder)
425+
{
426+
_dataSystem = dataSystemBuilder;
427+
return this;
428+
}
429+
404430
#endregion
405431
}
406432
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
using System.Collections.Generic;
2+
using System.Collections.Immutable;
3+
using LaunchDarkly.Sdk.Server.Subsystems;
4+
5+
namespace LaunchDarkly.Sdk.Server.Integrations
6+
{
7+
/// <summary>
8+
/// Configuration builder for the SDK's data acquisition and storage strategy.
9+
/// <para>
10+
/// This class is not stable, and not subject to any backwards compatibility guarantees or semantic versioning.
11+
/// It is not suitable for production usage. Do not use it. You have been warned.
12+
/// </para>
13+
/// </summary>
14+
internal sealed class DataSystemBuilder
15+
{
16+
// TODO: SDK-1678: Internal until ready for use.
17+
18+
private readonly List<IComponentConfigurer<IDataSource>> _initializers =
19+
new List<IComponentConfigurer<IDataSource>>();
20+
21+
private readonly List<IComponentConfigurer<IDataSource>> _synchronizers =
22+
new List<IComponentConfigurer<IDataSource>>();
23+
24+
private IComponentConfigurer<IDataSource> _fdV1FallbackSynchronizer;
25+
26+
private IComponentConfigurer<IDataStore> _persistentStore;
27+
28+
private DataSystemConfiguration.DataStoreMode _persistentDataStoreMode;
29+
30+
/// <summary>
31+
/// Add one or more initializers to the builder.
32+
/// To replace initializers, please refer to <see cref="DataSystemBuilder.ReplaceInitializers"/>.
33+
/// </summary>
34+
/// <param name="initializers">the initializers to add</param>
35+
/// <returns>a reference to the builder</returns>
36+
public DataSystemBuilder Initializers(params IComponentConfigurer<IDataSource>[] initializers)
37+
{
38+
_initializers.AddRange(initializers);
39+
return this;
40+
}
41+
42+
/// <summary>
43+
/// Replaces any existing initializers with the given initializers.
44+
/// To add initializers, please refer to <see cref="Initializers"/>.
45+
/// </summary>
46+
/// <param name="initializers">the initializers to replace the current initializers with</param>
47+
/// <returns>a reference to this builder</returns>
48+
public DataSystemBuilder ReplaceInitializers(params IComponentConfigurer<IDataSource>[] initializers)
49+
{
50+
_initializers.Clear();
51+
_initializers.AddRange(initializers);
52+
return this;
53+
}
54+
55+
/// <summary>
56+
/// Add one or more synchronizers to the builder.
57+
/// To replace synchronizers, please refer to <see cref="DataSystemBuilder.ReplaceSynchronizers"/>.
58+
/// </summary>
59+
/// <param name="synchronizers">the synchronizers to add</param>
60+
/// <returns>a reference to the builder</returns>
61+
public DataSystemBuilder Synchronizers(params IComponentConfigurer<IDataSource>[] synchronizers)
62+
{
63+
_synchronizers.AddRange(synchronizers);
64+
return this;
65+
}
66+
67+
/// <summary>
68+
/// Replaces any existing synchronizers with the given synchronizers.
69+
/// To add synchronizers, please refer to <see cref="Synchronizers"/>.
70+
/// </summary>
71+
/// <param name="synchronizers">the synchronizers to replace the current synchronizers with</param>
72+
/// <returns>a reference to this builder</returns>
73+
public DataSystemBuilder ReplaceSynchronizers(params IComponentConfigurer<IDataSource>[] synchronizers)
74+
{
75+
_synchronizers.Clear();
76+
_synchronizers.AddRange(synchronizers);
77+
return this;
78+
}
79+
80+
/// <summary>
81+
/// Configured the FDv1 fallback synchronizer.
82+
/// <remarks>LaunchDarkly can instruct the SDK to fall back to this synchronizer.</remarks>
83+
/// </summary>
84+
/// <param name="fdv1FallbackSynchronizer">the FDv1 fallback synchronizer</param>
85+
/// <returns>a reference to the builder</returns>
86+
public DataSystemBuilder FDv1FallbackSynchronizer(IComponentConfigurer<IDataSource> fdv1FallbackSynchronizer)
87+
{
88+
_fdV1FallbackSynchronizer = fdv1FallbackSynchronizer;
89+
return this;
90+
}
91+
92+
public DataSystemBuilder PersistentStore(IComponentConfigurer<IDataStore> persistentStore,
93+
DataSystemConfiguration.DataStoreMode mode)
94+
{
95+
_persistentStore = persistentStore;
96+
_persistentDataStoreMode = mode;
97+
return this;
98+
}
99+
100+
internal DataSystemConfiguration Build()
101+
{
102+
// This function should remain internal.
103+
104+
return new DataSystemConfiguration(
105+
_initializers.ToImmutableList(),
106+
_synchronizers.ToImmutableList(),
107+
_fdV1FallbackSynchronizer,
108+
_persistentStore,
109+
_persistentDataStoreMode);
110+
}
111+
}
112+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using LaunchDarkly.Sdk.Server.Subsystems;
3+
4+
namespace LaunchDarkly.Sdk.Server.Integrations
5+
{
6+
/// <summary>
7+
/// Components for use with the data system.
8+
/// <para>
9+
/// This class is not stable, and not subject to any backwards compatibility guarantees or semantic versioning.
10+
/// It is not suitable for production usage. Do not use it. You have been warned.
11+
/// </para>
12+
/// </summary>
13+
internal static class DataSystemComponents
14+
{
15+
// TODO: SDK-1678: Internal until ready for use.
16+
17+
/// <summary>
18+
/// Get a builder for a polling data source.
19+
/// </summary>
20+
/// <returns>the polling data source builder</returns>
21+
public static FDv2PollingDataSourceBuilder Polling()
22+
{
23+
return new FDv2PollingDataSourceBuilder();
24+
}
25+
26+
/// <summary>
27+
/// Get a builder for a streaming data source.
28+
/// </summary>
29+
/// <returns>the streaming data source builder</returns>
30+
public static FDv2StreamingDataSourceBuilder Streaming()
31+
{
32+
return new FDv2StreamingDataSourceBuilder();
33+
}
34+
35+
/// <summary>
36+
/// Get a builder for a FDv1 compatible polling data source.
37+
/// <remarks>
38+
/// This is intended for use as a fallback.
39+
/// </remarks>
40+
/// </summary>
41+
/// <returns>the FDv1 compatible polling data source.</returns>
42+
public static PollingDataSourceBuilder FDv1Polling()
43+
{
44+
return new PollingDataSourceBuilder();
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)