From 071943c2806c0ed67b7bbac2933eb054b8155663 Mon Sep 17 00:00:00 2001 From: 1289220708 <1289220708@qq.com> Date: Sat, 15 Jun 2024 18:07:42 +0800 Subject: [PATCH] fix(server): support put/delete & when 512 length then log cut --- .../apache/hugegraph/api/filter/PathFilter.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/PathFilter.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/PathFilter.java index 0d3691a109..23722dc1c6 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/PathFilter.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/PathFilter.java @@ -39,6 +39,7 @@ public class PathFilter implements ContainerRequestFilter { public static final String REQUEST_TIME = "request_time"; public static final String REQUEST_PARAMS_JSON = "request_params_json"; + public static final int MAX_SLOW_LOG_BODY_LENGTH = 512; @Override public void filter(ContainerRequestContext context) throws IOException { @@ -46,18 +47,22 @@ public void filter(ContainerRequestContext context) throws IOException { context.setProperty(REQUEST_TIME, startTime); - recordRequestJson(context); + collectRequestParams(context); } - private void recordRequestJson(ContainerRequestContext context) throws IOException { + private void collectRequestParams(ContainerRequestContext context) throws IOException { String method = context.getMethod(); - if (method.equals(HttpMethod.POST)) { + if (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT) || + method.equals(HttpMethod.DELETE)) { BufferedInputStream bufferedStream = new BufferedInputStream(context.getEntityStream()); bufferedStream.mark(Integer.MAX_VALUE); + String body = IOUtils.toString(bufferedStream, + Charsets.toCharset(CHARSET)); + body = body.length() > MAX_SLOW_LOG_BODY_LENGTH ? + body.substring(0, MAX_SLOW_LOG_BODY_LENGTH) : body; - context.setProperty(REQUEST_PARAMS_JSON, - IOUtils.toString(bufferedStream, Charsets.toCharset(CHARSET))); + context.setProperty(REQUEST_PARAMS_JSON, body); bufferedStream.reset();