Elffuss BraidHub

kikocis/EDC public

cc2a9ff178c4 · 9.3 KiBRenderedRawPermalink
1# Technical concept DPF Selector
2
3This document presents the technical concept for the "DataPlaneFramework Selector", henceforth "DPF Selector" or "DPFS"
4for short. In typical clustered environments (Kubernetes) we anticipate a multitude of connector runtimes and DPF
5runtimes, scaling independently of each other, depending on a particular use case. Also, the DPFs may have different
6configurations, so they may not even be in the same replica set (in Azure this would be Availability Sets vs. Scale
7Sets).
8
9Further, we assume that every connector has access to multiple DPF runtimes, even if they are not homogenous replicas.
10For example, some deployments may choose to have one dedicated DPF per geographical region, or even per `DataSink`
11/`DataSource` pair.
12
13Whenever a data transfer request hits the connector, it eventually will delegate the transfer to the DPF. For that, it
14needs to know _which DPF to delegate to_. In simple deployments, there may just be one single DPF, so the DPF selector
15is essentially a preconfigured value, but in more complex scenarios sophisticated algorithms may be employed to select
16the best-fitting DPF.
17
18This is not dissimilar to how load-balancers work, one key difference being that the DPF selector will distribute the
19request based on not just the load situation, but also based on request metadata or even functional requirements (e.g. "
20must be able to store in Azure BlobStore").
21
22Another key difference to (most) load balancers is the modularity and flexibility of the DPF selector: it can be
23embedded into another process (e.g. a connector), standalone, it can handle different storage and API technologies, it
24itself could theoretically run clustered, etc.
25
26## Terminology
27
28- DPF: one DataPlaneFramework runtime instance
29- CP: one ControlPlane instance, often used synonymous to "connector"
30- connector: one connector runtime
31- selector: one DPF selector runtime, either embedded or standalone
32- DataSource: one particular implementation that the DPF uses to fetch data from (e.g. Amazon S3)
33- DataSink: one particular implementation of a data destination (e.g. AzureBlob)
34- Seeding: the process of pre-populating a database. Often used synonymous to "loading".
35- Feature pack: a collection of Java modules that fulfill one particular purpose, typically accompanied by a BOM (
36 bill-of-materials)
37
38## Proposed solution
39
40We propose to create another "feature pack" in the EDC repository, essentially a meta module
41named `:extensions:data-plane-selector`, which will contain (at least) the following submodules:
42
43- `selector-spi`: for interfaces and extensibility points such as store, strategy
44- `data-plane-selector-api`: REST API
45- `selector-core`: common code, default implementations for store and strategies
46
47Furthermore there should be a `selector-launcher` in the `launchers` directory containing a build file for standalone
48deployment.
49
50Centrally to the DPF selector is an interface `DataPlaneSelector` whos purpose is to select a DPF instance based on an
51incoming `DataRequest` and an optional `SelectionStrategy`:
52
53```java
54public interface DataPlaneSelector {
55
56 default DataPlaneInstance select(DataRequest dataRequest) {
57 return select(dataRequest, new RandomSelectionStrategy());
58 }
59
60 DataPlaneInstance select(DataRequest dataRequest, SelectionStrategy strategy);
61}
62```
63
64The main business object is the `DataPlaneInstance` which represents one particular DPF instance with circa the
65following signature:
66
67```java
68public interface DataPlaneInstance {
69 boolean canHandle(DataRequest request);
70
71 URL getUrl(); //returns the url+path to the DataPlane API
72
73 int turnCount(); //how often selected
74
75 long lastActive(); //when selected last
76
77 Map<String, Object> getProperties(); //extensible properties
78}
79```
80
81Thus, the `DataPlaneInstance` itself determines whether it can support a particular data request, based on various
82capabilities such as its `DataSink` and `DataSource` implementations, streaming capabilities, etc.
83
84Requests come in either through an API or an SPI hit the `DataPlaneSelector`, which then filters its list
85of `DataPlaneInstace` records and selects the best fitting DPF based on a strategy. By default selection is made at
86random.
87
88### API/SPI considerations
89
90We'll provide both a REST API and a Java SPI (i.e. the `DataPlaneSelector`), so that the DPF selector can run embedded
91in another process, or as a standalone runtime. Both of those should offer the same functionality, which is:
92
93- `get-instance`: selects the best-fit DPF for a `DataRequest`, optionally accepts a `SelectionStrategy`
94- `add-instance`: adds a `DataPlaneInstance` to the internal store
95- `remove-instance`: removes a `DataPlaneInstance` from the internal store
96
97Both the REST API and the SPI implement these use cases.
98
99### Single vs Multi DPF
100
101In case a particular deployment uses just one DPF, the entire selection process can be simplified to always return the
102pre-configured DPF URL. This is likely to be used in end-to-end-test scenarios, demos or samples.
103
104### Store concepts
105
106The DPF selector needs a storage backend where it can save its `DataPlaneInstance` objects. The default implementation
107will be an in-memory one, but extensions can be provided for CosmosDB, SQL, etc.
108
109Whether a centralized persistent or an ephemeral store should be used will largely depend on the deployment scenario and
110whether the DPF selector runs standalone or embedded in the connector.
111
112**Seeding:** As a starting point we will provide a mechanism to load a preconfigured list of DPF instances using the EDC
113configuration mechanism. Named properties similar will be used, similar to what we currently have for web contexts, for
114example:
115
116```properties
117edc.dpf.selector.pod1.url=http://some.url
118edc.dpf.selector.pod1.someOtherProperty=...
119//...=
120edc.dpf.selector.pod2.url=http://some.other.url
121edc.dpf.selector.pod2.someOtherProperty=...
122```
123
124In addition, using the aforementioned API, any sort of data seeding scenario is possible, e.g. terraform, a dedicated
125loader, scripting, etc.
126
127### Selection Strategies
128
129A `SelectionStrategy` (as in: [strategy pattern](https://en.wikipedia.org/wiki/Strategy_pattern)) influences the
130best-fit criteria for a `DataPlaneInstance`. By default, we will implement the following ones:
131
132- `RandomSelectionStrategy`: will select one DPF instance at random. Assuming normal distribution of the RNG, all DPFs
133 will be selected at approximately equal frequency.
134- `RoundRobinSelectionStrategy`: selects the "next" DPF instance in an ordered list. **Requires state!**
135- [optional] `OldestNextSelectionStrategy`: selects the DPF instance that was idle the longest
136
137_Please note that when multiple DPF selector instances are used, some of the selection strategies only work as intended
138if DPF selectors share their storage, otherwise the counters would be inconsitent!_
139
140All `SelectionStrategy` objects must be registered with the DPF selector before it can be passed in through a REST API
141or used in the SPI. This requires the use of a `SelectionStrategyRegistry` into which customer extensions can register
142their specific strategies.
143
144## Deployment scenarios
145
146With this modular approach, the DPF selector can run as a standalone application, for example in a Kubernetes Deployment
147or as plain sidecar container. However, this type of deployment scenario practically _requires_ adding the `-api` module
148to the build, otherwise no interaction with the selector is possible.
149
150Another way of running a DPF selector would be as extension, i.e. embedded in an EDC connector runtime. In this scenario
151the `-api` module can be ignored, as all communication happens through the Java SPI. Again, situations with multiple
152connector instances practically _require_ using a persistent centralized storage (such as CosmosDB).
153
154**Client lib**: it should be transparent for the connector whether an embedded or a remote DPF selector is used,
155therefore we propose creating a small "DPF selector lib" in the EDC codebase, consisting of a single interface:
156
157```java
158public interface DataPlaneSelectorClient {
159 DataPlaneInstance select(DataRequest dataRequest);
160}
161
162// when the DPF selector is embedded --> default
163class LocalDataPlaneSelectorClient implements DataPlaneSelectorClient {
164 private final DataPlaneSelector selector;
165 private SelectionStrategy strategy; //could be null
166
167 // CTor(s)
168
169 public DataPlaneInstance select(DataRequest dataRequest) {
170 return strategy != null ? selector.select(dataRequest, strategy) : selector.select(dataRequest);
171 }
172}
173
174// when the DPF selector is remote
175class RemoteDataPlaneSelectorClient implements DataPlaneSelectorClient {
176 private final EdcHttpClient client;
177 private String strategyName; //could be null
178
179 // CTor(s)
180
181 public DataPlaneInstance select(DataRequest dataRequest) {
182 //invoke REST API of the remote selector
183 }
184}
185```
186
187## Future developments
188
189Once we have performance metrics and instrumentation built-in into the DPF, we can create a small extension that reports
190those dynamic metrics back to the DPF selector, who then stores them and uses them as additional input parameter to the
191selection algorithm.
192
193Another possible improvement would be a DPF selector that can interact with the Kubernetes backend and dynamically
194update its internal storage based on Kubernetes auto-scaling: when Kubernetes scales out the DPF pods, the selector
195tracks that and automatically updates its internal storage.