Commit 6e49f81
authored
feat(tracer): periodically poll agent /info endpoint for dynamic capability updates (#4451)
### What does this PR do?
The tracer currently queries the Datadog Agent's `/info` endpoint **once at startup**. Any agent-side capability changes (peer-tag policies, span events support, `client_drop_p0s`, etc.) require a full tracer restart to take effect.
This PR adds periodic polling of `/info` every 5 seconds so the tracer picks up agent config changes dynamically, without a restart.
**Thread-safety design:** `agentFeatures` is wrapped in `atomicAgentFeatures` backed by `atomic.Pointer[agentFeatures]`, giving lock-free snapshot reads on the hot path. A CAS-loop `update()` method prevents lost-update races if two writers ever race. All reads were updated from `c.agent.X` to `c.agent.load().X`.
**Static vs dynamic field split:** Fields baked into components at init (transport URL, statsd address, AppSec config, concentrator aggregation key, obfuscator feature flags) are preserved across every poll. Only fields safe to update at runtime (DropP0s, Stats, peerTags, spanEventsAvailable, obfuscationVersion) are refreshed.
### Motivation
- Jira: https://datadoghq.atlassian.net/browse/APMLP-860
- Operators changing agent configuration (e.g. enabling peer tags, adjusting stats collection) currently require bouncing all tracers. With periodic polling, changes propagate within 5 seconds.
### Reviewer's Checklist
- [x] Changed code has unit tests for its functionality at or near 100% coverage.
- `TestRefreshAgentFeaturesPreservesStaticFields` — static fields frozen, dynamic fields updated
- `TestPollAgentInfoUpdatesFeaturesDynamically` — convergence verified via `assert.Eventually`
- `TestPollAgentInfoRetainsLastKnownGoodOnError` — network failure preserves last known good
- `TestPollAgentInfoRetainsLastKnownGoodOn404` — 404 (agent downgrade) preserves last known good
- `TestPollAgentInfoGoroutineStopsOnTracerStop` — no goroutine leak on `Stop()`
- [ ] [System-Tests](https://github.com/DataDog/system-tests/) covering this feature have been added and enabled with the va.b.c-dev version tag.
- [ ] There is a benchmark for any new code, or changes to existing code.
- [x] If this interacts with the agent in a new way, a system test has been added. *(polls existing `/info` endpoint — no new agent interaction)*
- [x] New code is free of linting errors. You can check this by running `make lint` locally.
- [x] New code doesn't break existing tests. You can check this by running `make test` locally.
- [ ] Add an appropriate team label so this PR gets put in the right place for the release notes.
- [ ] All generated files are up to date. You can check this by running `make generate` locally.
- [ ] Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild. Make sure all nested modules are up to date by running `make fix-modules` locally. *(no go.mod changes)*
Co-authored-by: kemal.akkoyun <[email protected]>1 parent e9cc077 commit 6e49f81
10 files changed
Lines changed: 521 additions & 79 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
149 | | - | |
150 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
151 | 157 | | |
152 | 158 | | |
153 | 159 | | |
| |||
465 | 471 | | |
466 | 472 | | |
467 | 473 | | |
468 | | - | |
469 | | - | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
470 | 477 | | |
471 | 478 | | |
472 | 479 | | |
| |||
483 | 490 | | |
484 | 491 | | |
485 | 492 | | |
486 | | - | |
| 493 | + | |
487 | 494 | | |
488 | 495 | | |
489 | 496 | | |
| |||
507 | 514 | | |
508 | 515 | | |
509 | 516 | | |
510 | | - | |
| 517 | + | |
511 | 518 | | |
512 | 519 | | |
513 | 520 | | |
| |||
540 | 547 | | |
541 | 548 | | |
542 | 549 | | |
543 | | - | |
544 | | - | |
| 550 | + | |
545 | 551 | | |
546 | 552 | | |
547 | 553 | | |
548 | 554 | | |
549 | 555 | | |
550 | | - | |
| 556 | + | |
551 | 557 | | |
552 | 558 | | |
553 | 559 | | |
| |||
665 | 671 | | |
666 | 672 | | |
667 | 673 | | |
668 | | - | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | | - | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
674 | 706 | | |
675 | | - | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
676 | 724 | | |
677 | | - | |
678 | | - | |
| 725 | + | |
679 | 726 | | |
680 | | - | |
681 | | - | |
682 | | - | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
683 | 730 | | |
684 | 731 | | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
685 | 740 | | |
686 | 741 | | |
687 | 742 | | |
| |||
695 | 750 | | |
696 | 751 | | |
697 | 752 | | |
698 | | - | |
699 | 753 | | |
700 | | - | |
701 | | - | |
702 | | - | |
| 754 | + | |
| 755 | + | |
703 | 756 | | |
704 | | - | |
| 757 | + | |
705 | 758 | | |
706 | 759 | | |
707 | 760 | | |
| |||
730 | 783 | | |
731 | 784 | | |
732 | 785 | | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
733 | 800 | | |
734 | 801 | | |
735 | 802 | | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
736 | 810 | | |
737 | 811 | | |
738 | 812 | | |
| |||
770 | 844 | | |
771 | 845 | | |
772 | 846 | | |
773 | | - | |
| 847 | + | |
| 848 | + | |
774 | 849 | | |
775 | 850 | | |
776 | 851 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
205 | | - | |
| 205 | + | |
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
211 | | - | |
| 211 | + | |
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
221 | | - | |
| 221 | + | |
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
231 | | - | |
| 231 | + | |
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
243 | | - | |
244 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
245 | 246 | | |
246 | 247 | | |
247 | 248 | | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
255 | 256 | | |
256 | 257 | | |
257 | 258 | | |
| |||
261 | 262 | | |
262 | 263 | | |
263 | 264 | | |
264 | | - | |
265 | | - | |
266 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
267 | 269 | | |
268 | 270 | | |
269 | 271 | | |
| |||
273 | 275 | | |
274 | 276 | | |
275 | 277 | | |
276 | | - | |
| 278 | + | |
277 | 279 | | |
278 | 280 | | |
279 | 281 | | |
| |||
284 | 286 | | |
285 | 287 | | |
286 | 288 | | |
287 | | - | |
288 | | - | |
289 | | - | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
290 | 293 | | |
291 | 294 | | |
292 | 295 | | |
| |||
0 commit comments