From f1d96ccd199891989f0c2a15a6f6561a3ccae3ad Mon Sep 17 00:00:00 2001 From: Astralidea Date: Mon, 30 Oct 2023 14:53:32 +0800 Subject: [PATCH 1/2] Add logs for slow interfaces Signed-off-by: Astralidea --- fe/fe-core/src/main/java/com/starrocks/common/Config.java | 7 +++++++ .../main/java/com/starrocks/http/rest/RestBaseAction.java | 8 ++++++++ 2 files changed, 15 insertions(+) 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 da0c076c0c62e..40451df69869e 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,13 @@ public class Config extends ConfigBase { @ConfField public static int http_max_chunk_size = 8192; + /** + * If this time is exceeded when requesting the http service, a log will be output to remind you to determine + * the problem. Normally, the execution time of the metrics interface should not exceed 5 seconds. + */ + @ConfField(mutable = true) + public static int http_execution_time_ms_slowdown_threshold = 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..abbb4c46ce29c 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_execution_time_ms_slowdown_threshold) { + LOG.warn("Execution uri={} time exceeded {} ms and took {} ms.", request.getRequest().uri(), + Config.http_execution_time_ms_slowdown_threshold, elapsedTime); + } } @Override From b40f7795e020ce996b26b5ca3af237c9a3feceeb Mon Sep 17 00:00:00 2001 From: Astralidea Date: Tue, 31 Oct 2023 10:53:26 +0800 Subject: [PATCH 2/2] Opt. Signed-off-by: Astralidea --- fe/fe-core/src/main/java/com/starrocks/common/Config.java | 5 ++--- .../main/java/com/starrocks/http/rest/RestBaseAction.java | 4 ++-- .../src/test/java/com/starrocks/http/ShowDataActionTest.java | 2 ++ 3 files changed, 6 insertions(+), 5 deletions(-) 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 40451df69869e..adfdd6dcd1b1d 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 @@ -610,11 +610,10 @@ public class Config extends ConfigBase { public static int http_max_chunk_size = 8192; /** - * If this time is exceeded when requesting the http service, a log will be output to remind you to determine - * the problem. Normally, the execution time of the metrics interface should not exceed 5 seconds. + * If a request takes longer than the configured time, a log will be generated to trace it. */ @ConfField(mutable = true) - public static int http_execution_time_ms_slowdown_threshold = 5000; + public static int http_slow_request_threshold_ms = 5000; /** * When obtaining hardware information, some sensitive commands will be executed indirectly through 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 abbb4c46ce29c..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 @@ -94,9 +94,9 @@ public void handleRequest(BaseRequest request) { } long endTime = System.currentTimeMillis(); long elapsedTime = endTime - startTime; - if (elapsedTime > Config.http_execution_time_ms_slowdown_threshold) { + if (elapsedTime > Config.http_slow_request_threshold_ms) { LOG.warn("Execution uri={} time exceeded {} ms and took {} ms.", request.getRequest().uri(), - Config.http_execution_time_ms_slowdown_threshold, elapsedTime); + Config.http_slow_request_threshold_ms, elapsedTime); } } 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)