Commit d276cd8
committed
client: capture demand RU on onResponseWait throttle-fail
The new `demand_ru_per_sec` gauge promised "every entry point, never
subtracted on throttle failure", but `onResponseWaitImpl` increments
`mu.demandRUTotal` only after `acquireTokens` succeeds, so a throttle
rejection silently drops the demand sample -- exactly the case the
metric is meant to surface.
Root cause: the increment was co-located with the consumption update
inside the post-acquire lock block, even though demand and consumption
have different lifetimes (demand is monotonic; consumption is rolled
back on rejection). Four call sites carried the same inline expression,
making the wrong placement easy to add and hard to notice.
This commit makes the invariant structural:
* Add `(*groupCostController).recordDemand`, the single point where
`mu.demandRUTotal` grows. Its doc comment states the rule: callers
MUST invoke it before any limiter wait/acquire so demand survives a
rejection.
* Route `onRequestWaitImpl`, `onResponseImpl`, `onResponseWaitImpl`,
and `addRUConsumption` through `recordDemand`. In
`onResponseWaitImpl` this also hoists the call above
`acquireTokens`, fixing the bug.
* Add `TestDemandRUCapturedOnResponseWaitThrottle` to lock the
invariant in via the throttle-fail path.
* Rewrite the EMA portion of `TestDemandRUTracking`: the previous
version assigned `gc.run.now` only to have `updateRunState`
immediately overwrite it with `time.Now()`, so the two-tick EMA
assertion was a no-op. The new version drives `calcDemandAvg`
directly with hand-set timestamps and asserts the actual EMA
trajectory.
* Mirror the `acceleratedReportingPeriod` failpoint into
`calcDemandAvg` so any test that accelerates `calcAvg` accelerates
the demand EMA in lockstep.
* `calcDemandAvg` now returns whether it actually updated; the gauge
Set is gated on that so we never re-publish a stale value when no
time has elapsed. Drop the `< 0` clamp -- the input counter is
monotonically increasing, so the EMA cannot go negative.
* Extend the leak-TODO in `cleanUpResourceGroup` to include
`LowTokenRequestNotifyCounter`, which has the same per-group label
cardinality as the others on the list.
Signed-off-by: JmPotato <github@ipotato.me>1 parent 4d6937d commit d276cd8
File tree
3 files changed
+131
-26
lines changed- client/resource_group/controller
3 files changed
+131
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
637 | 637 | | |
638 | 638 | | |
639 | 639 | | |
640 | | - | |
641 | | - | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
642 | 643 | | |
643 | 644 | | |
644 | 645 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
281 | 298 | | |
282 | 299 | | |
283 | 300 | | |
| |||
287 | 304 | | |
288 | 305 | | |
289 | 306 | | |
290 | | - | |
291 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
292 | 310 | | |
293 | 311 | | |
294 | 312 | | |
| |||
337 | 355 | | |
338 | 356 | | |
339 | 357 | | |
340 | | - | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
341 | 366 | | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
342 | 370 | | |
343 | | - | |
| 371 | + | |
344 | 372 | | |
345 | 373 | | |
346 | 374 | | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | 375 | | |
351 | 376 | | |
| 377 | + | |
352 | 378 | | |
353 | 379 | | |
354 | 380 | | |
| |||
584 | 610 | | |
585 | 611 | | |
586 | 612 | | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
587 | 617 | | |
588 | 618 | | |
589 | | - | |
590 | 619 | | |
591 | 620 | | |
592 | 621 | | |
| |||
634 | 663 | | |
635 | 664 | | |
636 | 665 | | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
637 | 673 | | |
638 | 674 | | |
639 | 675 | | |
| |||
644 | 680 | | |
645 | 681 | | |
646 | 682 | | |
647 | | - | |
648 | | - | |
649 | 683 | | |
650 | 684 | | |
651 | 685 | | |
| |||
667 | 701 | | |
668 | 702 | | |
669 | 703 | | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
670 | 711 | | |
671 | 712 | | |
672 | 713 | | |
| |||
687 | 728 | | |
688 | 729 | | |
689 | 730 | | |
690 | | - | |
691 | 731 | | |
692 | 732 | | |
693 | 733 | | |
| |||
703 | 743 | | |
704 | 744 | | |
705 | 745 | | |
| 746 | + | |
706 | 747 | | |
707 | 748 | | |
708 | | - | |
709 | 749 | | |
710 | 750 | | |
711 | 751 | | |
| |||
Lines changed: 76 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
348 | | - | |
| 348 | + | |
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
| |||
361 | 361 | | |
362 | 362 | | |
363 | 363 | | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
369 | 370 | | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
374 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
375 | 412 | | |
376 | | - | |
377 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
378 | 442 | | |
0 commit comments