Commit 401e623
authored
refactor(remote-config)!: DI via RemoteConfigParsedData trait + ParserRegistry (#1945)
# What does this PR do?
The `datadog-remote-config` crate previously owned the full deserialization pipeline for every product via a closed `RemoteConfigData` enum. Adding a new product required editing the RC crate itself, importing product types, and adding enum variants — creating compile-time coupling to `datadog-live-debugger` and `datadog-ffe` via Cargo optional features.
This PR flips the dependency: RC defines a typed `RemoteConfigContent` trait (with a `PRODUCT` const and a `parse` method), an opaque `RemoteConfigParsedData` trait-object boundary, and a `ParserRegistry` to compose products. Product crates implement `RemoteConfigContent` on their own types; a blanket `impl<T: RemoteConfigContent> RemoteConfigParsedData for T` lets the registry hold them as `Box<dyn RemoteConfigParsedData>` without knowing the concrete type.
## Follow-up changes on this branch
- **Sidecar LiveDebugger parser registration.** Pre-refactor, `datadog-sidecar` enabled the `live-debugger` Cargo feature on `datadog-remote-config`, which made the closed-enum parser handle LiveDebugger payloads. After the DI refactor that feature is gone, so `RemoteConfigManager::new()` now explicitly registers the `LiveDebuggingData` parser on top of `default_registry()` to preserve pre-refactor sidecar behavior. Added a regression test (`test_live_debugger_config_parsed`) that drives a `SERVICE_CONFIGURATION` payload through the SHM round trip and asserts the downcast to `LiveDebuggingData` succeeds.
- **`set_extra_services` on the fetchers.** Runtime-discovered extra services live on `ConfigClientState` (the per-client mutable state), not on `Target`. New API: `ConfigClientState::set_extra_services(Vec<String>)`, `SingleFetcher::set_extra_services`, `SingleChangesFetcher::set_extra_services`. `fetch_once` reads from `opaque_state` and forwards via `ClientTracer.extra_services` exactly as before. Replace-semantics: each set fully overrides the previous list. This was kept off `Target` because `Target` is `Hash + Eq + Clone` (used as a map key in `MultiTargetFetcher`) — putting growing dynamic state on it would force costly map rekeying or break the `Hash`/`Eq` contract.
## Adding a new RC product going forward
1. **In `datadog-remote-config`** (still required): add a variant to `RemoteConfigProduct` and its `Display`/`try_parse` arms in `path.rs`. The product taxonomy is still a closed enum.
2. **In the product crate**: implement `RemoteConfigContent` on the product's config type:
```rust
impl RemoteConfigContent for MyProductConfig {
const PRODUCT: RemoteConfigProduct = RemoteConfigProduct::MyProduct;
fn parse(data: &[u8]) -> anyhow::Result<Self> { /* … */ }
}
```
3. **At construction time**: chain `.with::<MyProductConfig>()` onto a `ParserRegistry` (typically `default_registry()`).
Only the parsing is fully extensible after this PR; the product enumeration is still closed. Making `RemoteConfigProduct` open (e.g. `Cow<'static, str>` or a sealed trait) would close that gap and is a reasonable follow-up.
## Motivation
Drives `datadog-remote-config`'s coupling to product crates from compile-time (Cargo features + closed enum) to runtime (registry injection), so consumers compose the products they care about without forcing the RC crate to know about every product.
## Note
Check [this](#1958) other PR with a different approach
Co-authored-by: igor.unanua <igor.unanua@datadoghq.com>1 parent 1612ee9 commit 401e623
20 files changed
Lines changed: 602 additions & 168 deletions
File tree
- datadog-ffe
- src
- datadog-live-debugger
- src
- datadog-remote-config
- examples
- src
- config
- fetch
- datadog-sidecar
- src
- libdd-tracer-flare/src
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| 38 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | | - | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
33 | | - | |
34 | | - | |
35 | 32 | | |
36 | 33 | | |
37 | 34 | | |
| |||
47 | 44 | | |
48 | 45 | | |
49 | 46 | | |
| 47 | + | |
50 | 48 | | |
51 | 49 | | |
52 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
| 92 | + | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
95 | 98 | | |
96 | 99 | | |
97 | 100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| |||
0 commit comments