Commit 6e8edac
[Backport 7.82.x] fix(dataobs): reuse stored base config across DO_QUERY_ACTIONS updates (#54292)
Backport 83b0223 from #54212.
___
<!--Please give us some feedback on your experience writing this PR ! https://app.datadoghq.com/forms/43db4c02-6837-400c-8083-692e141b1b88 !-->
### What does this PR do?
Follow-up to #54200 (merged). Fixes a **second, distinct** duplication bug in
`comp/dataobs/queryactions/impl/handler.go`, surfaced while verifying #54200: after the first
`DO_QUERY_ACTIONS` update correctly retires a base config in favor of a DO check, a **second**
RC update for the same `config_id` (e.g. editing the monitor's queries) could resurrect the
already-retired base config alongside the new DO check — reintroducing the "parallel checks"
duplication that #54200 fixed for the first-update case.
Root cause: `onRCUpdate` always re-derived the "base config" via `findMatchingConfig`, which
searches only currently-*active* (scheduled) configs. Once the true original is unscheduled after
the first update, the only thing left matching that host is the DO component's own
previously-scheduled check — which also satisfies `matchesIdentifier` and `instanceHasDOEnabled`,
so it looks like a legitimate base config from the outside. Adopting it as the new "base" gives it
a different digest than the true original, so `reconcileBases`'s digest-based tracking loses track
of the true original and wrongly restores it.
Fix: added `resolveBaseConfig`, which reuses the previously-stored `baseCfg` for an already-active
`config_id` instead of re-deriving it every update. Falls back to a fresh `findMatchingConfig`
search if the stored base no longer has a matching instance (e.g. a genuine host change).
Extracted `findMatchingInstance` so both the fresh-search path and the reuse path share identical
matching logic.
Rebased onto latest `main` (now including #54215, an orthogonal fix for a same-host/different-port
remainder-matching bug — no overlap with this change; both coexist cleanly).
### Motivation
Confirmed live against a real SAP HANA instance, with #54200 already applied: editing a monitor
tied to an already-active `DO_QUERY_ACTIONS` config (growing its query count) reliably triggered
`reconcileBases | Restored original postgres config` and a second concurrent
`schema-collection`/`data_observability` cycle, exactly reproducing the duplication bug via a
different trigger than #54200 covers.
### Describe how you validated your changes
- Added `TestOnRCUpdate_SecondUpdateReusesStoredBase`, a regression test using a mutable mock
`GetUnresolvedConfigs()` that reflects what autodiscovery would actually look like after the
first update (existing tests' static fixtures couldn't exercise this — they never reflect a
prior update's `changes.Schedule`/`Unschedule`). Verified this test fails with the pre-fix
behavior (temporarily reverted the fix locally, confirmed the test fails with the same
"Restored original postgres config" signature seen live, then restored the fix).
- `dda inv test --targets=./comp/dataobs/queryactions/impl` — all 39 tests pass (41 counting
table-driven subtests).
- Live-verified end-to-end against a running SAP HANA Express instance: first RC delivery settles
cleanly (base retired, DO check active), then a real monitor edit triggers a second delivery for
the same `config_id` (query count 4 → 5) — before this fix, that reproduced the duplication;
after, the base config is never rescheduled and exactly one check instance remains active
throughout, confirmed via schema-collection logs showing only a single running instance.
- Re-verified after rebasing onto latest `main` (with #54215 merged): build succeeds, all tests
still pass, agent runs cleanly against the live SAP HANA instance.
### Additional Notes
None outstanding — the two known duplication triggers (first update in #54200, second update
here) are both covered now.
Co-authored-by: axel.vonengel <axel.vonengel@datadoghq.com>1 parent c9150d5 commit 6e8edac
3 files changed
Lines changed: 136 additions & 15 deletions
File tree
- comp/dataobs/queryactions/impl
- releasenotes/notes
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
323 | 354 | | |
324 | 355 | | |
325 | 356 | | |
| |||
329 | 360 | | |
330 | 361 | | |
331 | 362 | | |
332 | | - | |
333 | | - | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
334 | 366 | | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
| 367 | + | |
| 368 | + | |
347 | 369 | | |
348 | 370 | | |
349 | 371 | | |
| |||
355 | 377 | | |
356 | 378 | | |
357 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
358 | 404 | | |
359 | 405 | | |
360 | 406 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1232 | 1232 | | |
1233 | 1233 | | |
1234 | 1234 | | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
0 commit comments