imbajin commented on code in PR #3177:
URL: https://github.com/apache/hugegraph/pull/3177#discussion_r3889230520
##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AccessLogFilter.java:
##########
@@ -161,6 +226,48 @@ public void filter(ContainerRequestContext requestContext,
}
}
+ private static boolean mayHaveBody(String method) {
+ // DELETE endpoints take path/query params only, so there is no body
to record
+ return HttpMethod.POST.equals(method) || HttpMethod.PUT.equals(method);
+ }
+
+ private boolean decodesEntity() {
+ Method method = this.resourceInfo == null ? null :
this.resourceInfo.getResourceMethod();
+ return method != null && method.isAnnotationPresent(Decompress.class);
+ }
+
+ private static String preview(byte[] bytes, int length, int limit) {
+ boolean truncated = length > limit;
+ int size = Math.min(length, limit);
+ CharsetDecoder decoder = CHARSET.newDecoder()
Review Comment:
⚠️ Important: The preview decoder is hard-coded to API.CHARSET (UTF-8),
while the String message provider used by GremlinAPI and CypherAPI honors the
request media type charset. A valid request such as application/json;
charset=UTF-16 can therefore be decoded correctly by the resource but logged as
replacement or garbled text here. Derive the preview charset from
requestContext.getMediaType() with UTF-8 fallback, and add non-UTF-8 coverage,
so the slow-query body matches the executed query.
##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/AccessLogFilter.java:
##########
@@ -100,6 +126,43 @@ private static String
normalizePath(ContainerRequestContext requestContext) {
return newPath;
}
+ /**
+ * Keep a bounded preview of the request body for the slow query log.
+ * Only the first {@link ServerOptions#SLOW_QUERY_LOG_BODY_LIMIT} bytes are
+ * read, and they are replayed in front of the untouched remainder of the
+ * entity stream, so the resource method still receives the whole body.
+ *
+ * @param requestContext requestContext
+ */
+ @Override
+ public void filter(ContainerRequestContext requestContext) throws
IOException {
Review Comment:
⚠️ Important: This global request filter has no explicit priority, as does
the dynamically registered RedirectFilter. On @RedirectMasterRole jobs/gremlin
requests, RedirectFilter may run first, call abortWith(), and stop the
remaining request-filter chain before this code records REQUEST_BODY; the
response filter then logs body=null for a slow redirect. Assign an explicit
priority that guarantees capture before redirect, or preserve the preview
through the redirect, and cover this path with an integration test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]