fix(diagnostics): cap section budget and wait by the remaining total timeout #8030
The rounding is what makes this correct, and it is the part most likely to be broken later, so the inline comment earns its place: budgetMs is rounded up against budgetNanos, which guarantees future.get(budgetMs) cannot return before the total deadline. That is exactly why timeoutReason can trust "deadline already passed" to mean "the total budget capped this section" instead of mislabelling it a plain section timeout.
Consistent with the rest of the change:
DiagnosticBudget now receives the capped value, so the collector's own internal accounting stops at the same point the wait does — otherwise a section could report success after the wait had already given up.Math.max(1L, budgetMs) keeps a positive sub-millisecond remainder usable instead of collapsing to 0, which would have meant an unbounded get(0, ...).One small doc gap: with this change sectionTimeoutMs = 0 yields a 1 ms section budget rather than "no per-section limit". That is not a regression — get(0, MILLISECONDS) already timed out immediately before — but setSectionTimeoutMs is a natural place to say so, since the value now flows into two places (the budget and the wait) instead of one.
Approving.
@imDwAaY This PR is approved, but 7 checks are red: build (shenyu-integrated-test-http), build (shenyu-integrated-test-rewrite), build (shenyu-integrated-test-tracing), build (shenyu-integrated-test-https) (+3 more).
I inspected these lanes today and they fail for infrastructure reasons rather than on the diff — the integrated-test jobs die while starting their containers (Elasticsearch /_cat/health returning 000 until the job is cancelled), and the http lane also hits the known CachePluginTest.testMemoryModle / testRedisModle flake. The same jobs are red on master and on unrelated PRs right now.
Please rebase onto master and push (or ask for a re-run) so the checks execute again. If a case is still failing on a fresh run, paste the test name and I'll look properly.
Rebased onto master (b7cea28e0) and force-pushed; the branch is now a single commit d05c93f45.
Also addressed the doc gap you pointed out: setSectionTimeoutMs now documents that the value bounds both the collector budget and the wait for its result, and that values below one millisecond (including zero) still allow a one millisecond attempt rather than meaning "no per-section limit".
Local verification after the rebase:
./mvnw -pl shenyu-web -am test -Dtest='Diagnostic*' # 19 tests, 0 failures (JDK 17)
./mvnw -pl shenyu-web checkstyle:check # pass
Thanks for checking the integrated-test lanes — I'll keep an eye on this run and report back if anything fails on the new checks rather than on the known infrastructure/CachePluginTest flakes.
Approved. Capping each diagnostic section's wait to the remaining total deadline via sectionBudgetMs(deadlineNanos) prevents one slow section from over-running the overall timeout, and the rounding/boundary handling is sound. Tests cover the budget math. (The remaining 'shenyu-integrated-test-rewrite' failure is the known-flaky rewrite job, unrelated to this change.)
Aias00
imDwAaY
Fixes #8022.
Problem
DiagnosticBundleService.collect()computes a total deadline, butrunCollectorthen hands each collector the fullsectionTimeoutMsand waits for its result with the same full timeout. A section that starts just before the total deadline can therefore extend collection by another complete section timeout, so the advertisedtotalTimeoutMsis not enforced.Fix
min(sectionTimeoutMs, remaining total time), and theFuture.getwait uses that same capped value.TimeoutExceptionnow distinguishestotal budget exhaustedfromsection timeout, so consumers can tell which bound actually stopped collection. Sections that are never attempted are still reported asSKIPPEDwithtotal budget exhausted, and an active section is cancelled when the total deadline passes.DiagnosticProperties.getTotalTimeoutMs()documents what the bound covers: it bounds starting and waiting for collectors, not manifest identity lookup or archive assembly.Tests
Added to
DiagnosticBundleServiceTest:totalBudgetCapsSectionWait—totalTimeoutMs=50,sectionTimeoutMs=5000, blocking collector: the section fails withtotal budget exhaustedand collection returns in well under the full section timeout.laterCollectorCannotRestartFullSectionAllowance— after the first section exhausts the total budget, the next collector isSKIPPEDinstead of receiving a fresh section allowance.Local verification:
Note: the full
shenyu-websuite has pre-existing Mockito inline-mock errors under JDK 25 on this machine; the diagnostics package has no Mockito dependency and passes.