Commit 74c3ab4
refactor: single RC subscriber (#16299)
# Description
This PR refactors the Remote Configuration (RC) architecture from a multiple-subscriber model (one thread per product) to a single-subscriber model with product dispatching. This reduces thread overhead and simplifies the RC polling infrastructure.
## Key Changes
### Architectural Simplification
- **Before**: Each product registered its own subscriber thread
- **After**: Single global subscriber dispatches payloads to registered product callbacks
- **Benefit**: Reduced thread count improves resource efficiency and simplifies lifecycle management
### New RCCallback Interface
Products now register callbacks by implementing the RCCallback abstract base class:
```python
from ddtrace.internal.remoteconfig import RCCallback, Payload
from typing import Sequence
class MyProductCallback(RCCallback):
def __call__(self, payloads: Sequence[Payload]) -> None:
"""Process configuration payloads when received."""
for payload in payloads:
# Process configuration updates
...
def periodic(self) -> None:
"""Optional: Perform periodic operations at every polling cycle."""
# Emit metrics, check stale state, etc.
pass
```
## Key features:
- `__call__(payloads)`: Abstract method called when configuration updates are received
- `periodic()`: Optional method called at every polling interval (before payload processing), regardless of whether new configuration was received
- Enables time-based operations like probe status emission, stale request cleanup, and periodic metrics
### Registration Pattern
```python
from ddtrace.internal.remoteconfig.worker import remoteconfig_poller
callback = MyProductCallback()
remoteconfig_poller.register(
product="MY_PRODUCT",
callback=callback,
capabilities=[...]
)
```
The single subscriber calls:
1. `callback.periodic()` for all registered callbacks at every poll cycle
2. `callback(payloads)` when new configuration is available for that product
## Benefits
1. **Reduced thread overhead**: One subscriber thread instead of N threads (one per product)
2. **Cleaner separation**: Periodic operations separated from payload processing logic
3. **Better testability**: Callbacks can test periodic() independently of payload handling
4. **Consistent interface**: All products follow the same registration pattern
## Migration Notes
Existing callbacks automatically get no-op periodic() behavior. No breaking changes for products that don't need periodic operations.
# Additional Notes
Claude Code made the largest chunk of the changes. It has been guided step-by-step to perform the following tasks
- Move to a single subscriber design whereby a single subscriber thread runs in each process. It then dispatches configurations to the appropriate callbacks.
- Use the smaller RCCallback for registering product RC callbacks and remove most of the PubSub boilerplate code into the single subscriber.
## Specific changes in appsec
- remove the appsec preprocessing part, as it's not required anymore to be outside of the usual appsec callback
- update the tests accordingly
the appsec RC layer is tested extensively on the system tests
APPSEC-61160
Co-authored-by: christophe-papazian <[email protected]>
Co-authored-by: gabriele.tornetta <[email protected]>1 parent 88b4e89 commit 74c3ab4
31 files changed
Lines changed: 1447 additions & 1282 deletions
File tree
- ddtrace
- appsec
- debugging
- _probe
- internal
- appsec
- flare
- openfeature
- remoteconfig
- products
- symbol_db
- tests
- appsec/appsec
- debugging
- probe
- internal
- remoteconfig
- openfeature
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 15 | + | |
19 | 16 | | |
20 | 17 | | |
21 | 18 | | |
| |||
28 | 25 | | |
29 | 26 | | |
30 | 27 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | 28 | | |
48 | 29 | | |
49 | | - | |
| 30 | + | |
50 | 31 | | |
51 | 32 | | |
52 | 33 | | |
53 | 34 | | |
54 | 35 | | |
55 | 36 | | |
56 | 37 | | |
57 | | - | |
58 | | - | |
59 | 38 | | |
60 | 39 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | 40 | | |
67 | 41 | | |
68 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
69 | 47 | | |
| 48 | + | |
70 | 49 | | |
71 | | - | |
72 | | - | |
73 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
74 | 54 | | |
75 | 55 | | |
76 | 56 | | |
| |||
89 | 69 | | |
90 | 70 | | |
91 | 71 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
100 | 119 | | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 120 | + | |
| 121 | + | |
114 | 122 | | |
115 | 123 | | |
116 | 124 | | |
| |||
181 | 189 | | |
182 | 190 | | |
183 | 191 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | | - | |
35 | | - | |
36 | 35 | | |
37 | 36 | | |
38 | 37 | | |
| |||
189 | 188 | | |
190 | 189 | | |
191 | 190 | | |
192 | | - | |
| 191 | + | |
193 | 192 | | |
194 | 193 | | |
195 | 194 | | |
| |||
235 | 234 | | |
236 | 235 | | |
237 | 236 | | |
238 | | - | |
| 237 | + | |
239 | 238 | | |
240 | 239 | | |
241 | 240 | | |
242 | 241 | | |
243 | 242 | | |
244 | 243 | | |
245 | 244 | | |
246 | | - | |
247 | | - | |
| 245 | + | |
| 246 | + | |
248 | 247 | | |
249 | 248 | | |
250 | 249 | | |
| |||
288 | 287 | | |
289 | 288 | | |
290 | 289 | | |
291 | | - | |
292 | | - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
293 | 298 | | |
294 | 299 | | |
295 | 300 | | |
| |||
579 | 584 | | |
580 | 585 | | |
581 | 586 | | |
582 | | - | |
| 587 | + | |
583 | 588 | | |
584 | 589 | | |
585 | 590 | | |
| |||
0 commit comments