diff --git a/fe/fe-core/src/main/java/com/starrocks/common/Config.java b/fe/fe-core/src/main/java/com/starrocks/common/Config.java index 3c75ca47fbff2..356a4a38664e6 100644 --- a/fe/fe-core/src/main/java/com/starrocks/common/Config.java +++ b/fe/fe-core/src/main/java/com/starrocks/common/Config.java @@ -609,6 +609,12 @@ public class Config extends ConfigBase { @ConfField public static int http_max_chunk_size = 8192; + /** + * If a request takes longer than the configured time, a log will be generated to trace it. + */ + @ConfField(mutable = true) + public static int http_slow_request_threshold_ms = 5000; + /** * When obtaining hardware information, some sensitive commands will be executed indirectly through * the oshi library, such as: getent passwd diff --git a/fe/fe-core/src/main/java/com/starrocks/http/rest/RestBaseAction.java b/fe/fe-core/src/main/java/com/starrocks/http/rest/RestBaseAction.java index defbe8df1f1e5..a5e9a2339e078 100644 --- a/fe/fe-core/src/main/java/com/starrocks/http/rest/RestBaseAction.java +++ b/fe/fe-core/src/main/java/com/starrocks/http/rest/RestBaseAction.java @@ -35,6 +35,7 @@ package com.starrocks.http.rest; import com.fasterxml.jackson.databind.ObjectMapper; +import com.starrocks.common.Config; import com.starrocks.common.DdlException; import com.starrocks.common.Pair; import com.starrocks.common.util.UUIDUtil; @@ -70,6 +71,7 @@ public RestBaseAction(ActionController controller) { @Override public void handleRequest(BaseRequest request) { LOG.info("receive http request. url={}", request.getRequest().uri()); + long startTime = System.currentTimeMillis(); BaseResponse response = new BaseResponse(); try { execute(request, response); @@ -90,6 +92,12 @@ public void handleRequest(BaseRequest request) { response.appendContent(new RestBaseResult(msg).toJson()); writeResponse(request, response, HttpResponseStatus.INTERNAL_SERVER_ERROR); } + long endTime = System.currentTimeMillis(); + long elapsedTime = endTime - startTime; + if (elapsedTime > Config.http_slow_request_threshold_ms) { + LOG.warn("Execution uri={} time exceeded {} ms and took {} ms.", request.getRequest().uri(), + Config.http_slow_request_threshold_ms, elapsedTime); + } } @Override diff --git a/fe/fe-core/src/test/java/com/starrocks/http/ShowDataActionTest.java b/fe/fe-core/src/test/java/com/starrocks/http/ShowDataActionTest.java index 5156ffcbcacdc..e7a67fde5f1a6 100644 --- a/fe/fe-core/src/test/java/com/starrocks/http/ShowDataActionTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/http/ShowDataActionTest.java @@ -16,6 +16,7 @@ import com.starrocks.catalog.Database; import com.starrocks.catalog.OlapTable; +import com.starrocks.common.Config; import com.starrocks.server.GlobalStateMgr; import okhttp3.Request; import okhttp3.Response; @@ -47,6 +48,7 @@ public void doSetUp() { @Test public void testGetShowData() throws IOException { + Config.http_slow_request_threshold_ms = 0; Request request = new Request.Builder() .get() .addHeader("Authorization", rootAuth)