optimize(api): add warning logs for load-based request rejection#2972
optimize(api): add warning logs for load-based request rejection#2972contrueCT wants to merge 4 commits intoapache:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds operator-visible warning logs when LoadDetectFilter rejects requests due to high worker load or low free memory (503s), and introduces unit tests to cover the new rejection behavior plus whitelist/healthy pass-through.
Changes:
- Add
WARNlogging for worker-load and low-memory request rejections inLoadDetectFilter. - Add
LoadDetectFilterTestunit coverage for whitelist bypass, busy rejection, low-memory rejection, and healthy requests. - Register the new unit test in
UnitTestSuite.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/LoadDetectFilter.java | Adds rejection WARN logs and minor refactor (captures current load). |
| hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/filter/LoadDetectFilterTest.java | New unit tests for whitelist/busy/low-memory/healthy scenarios. |
| hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java | Adds LoadDetectFilterTest to the unit suite. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...aph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/LoadDetectFilter.java
Outdated
Show resolved
Hide resolved
.../hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/filter/LoadDetectFilterTest.java
Outdated
Show resolved
Hide resolved
...aph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/LoadDetectFilter.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.../hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/filter/LoadDetectFilterTest.java
Show resolved
Hide resolved
...aph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/LoadDetectFilter.java
Outdated
Show resolved
Hide resolved
...aph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/LoadDetectFilter.java
Outdated
Show resolved
Hide resolved
.../hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/filter/LoadDetectFilterTest.java
Show resolved
Hide resolved
VGalaxies
left a comment
There was a problem hiding this comment.
Thanks for the update. I left two small review comments; CI looks green on my side, but I think these are still worth addressing.
...aph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/LoadDetectFilter.java
Outdated
Show resolved
Hide resolved
.../hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/filter/LoadDetectFilterTest.java
Show resolved
Hide resolved
Changes made:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private static final Logger TEST_LOGGER = | ||
| (Logger) LogManager.getLogger(LoadDetectFilter.class); | ||
|
|
There was a problem hiding this comment.
TEST_LOGGER is obtained by casting LogManager.getLogger(LoadDetectFilter.class) to org.apache.logging.log4j.core.Logger. With the test log4j2.xml using <AsyncLogger name="org.apache.hugegraph" ...>, this logger instance can be an AsyncLogger, so this cast (and addAppender/removeAppender) can fail with ClassCastException or not attach the appender as intended. Consider attaching the TestAppender via LoggerContext/Configuration/LoggerConfig (e.g., config.getLoggerConfig(loggerName).addAppender(...) + ctx.updateLoggers()), and remove it the same way in teardown.
| boolean gcTriggered = this.gcIfNeeded(); | ||
| long allocatedMemAfterCheck = Runtime.getRuntime().totalMemory() - | ||
| Runtime.getRuntime().freeMemory(); | ||
| long recheckedFreeMem = (Runtime.getRuntime().maxMemory() - | ||
| allocatedMemAfterCheck) / Bytes.MB; | ||
| this.logRejectWarning("Rejected request due to low free memory, method={}, path={}, " + | ||
| "presumableFreeMemMB={}, recheckedFreeMemMB={}, gcTriggered={}, " + | ||
| "minFreeMemoryMB={}", | ||
| context.getMethod(), context.getUriInfo().getPath(), | ||
| presumableFreeMem, recheckedFreeMem, gcTriggered, | ||
| minFreeMemory); |
There was a problem hiding this comment.
In the low-free-memory rejection path, allocatedMemAfterCheck / recheckedFreeMem are computed on every rejected request, even when the reject log is suppressed by REJECT_LOG_RATE_LIMITER (since allowRejectLog() is only checked inside logRejectWarning()). To keep the rate-limiting effective under overload/low-memory conditions, consider checking allowRejectLog() first (or having logRejectWarning() return a boolean) and only doing the recheck computations when a log will actually be emitted.
Purpose of the PR
Main Changes
Log busy-worker and low-memory rejections in LoadDetectFilter before returning ServiceUnavailableException so operators can diagnose 503 responses from server-side logs.
Add unit coverage for whitelist bypass, busy rejection,
low-memory rejection, and healthy request pass-through, and register the new test in UnitTestSuite.
Verifying these changes
Does this PR potentially affect the following parts?
Documentation Status
Doc - TODODoc - DoneDoc - No Need