From 0f48e155bdcd781c83fa07f8ee8d5c9675ef744e Mon Sep 17 00:00:00 2001 From: Felix Li Date: Tue, 31 Oct 2023 13:56:35 +0800 Subject: [PATCH] [Enhancement] Add logs for slow interfaces (#33908) Signed-off-by: Astralidea (cherry picked from commit 6488726958751765dd4164af137d9c63993e9ec9) # Conflicts: # fe/fe-core/src/test/java/com/starrocks/http/ShowDataActionTest.java --- fe/fe-core/src/main/java/com/starrocks/common/Config.java | 6 ++++++ .../main/java/com/starrocks/http/rest/RestBaseAction.java | 8 ++++++++ .../test/java/com/starrocks/http/ShowDataActionTest.java | 5 +++++ 3 files changed, 19 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 1258ae74db193..8fc344d95c1c0 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 @@ -569,6 +569,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 b2052b0238a37..8ef481ecb0f43 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; @@ -68,6 +69,7 @@ public RestBaseAction(ActionController controller) { @Override public void handleRequest(BaseRequest request) throws Exception { LOG.info("receive http request. url={}", request.getRequest().uri()); + long startTime = System.currentTimeMillis(); BaseResponse response = new BaseResponse(); try { execute(request, response); @@ -81,6 +83,12 @@ public void handleRequest(BaseRequest request) throws Exception { sendResult(request, response, new RestBaseResult(e.getMessage())); } } + 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 bba1a3eea86a3..e95c42e2327b4 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,7 +48,11 @@ public void doSetUp() { @Test public void testGetShowData() throws IOException { +<<<<<<< HEAD String baseUri = "http://localhost:" + String.valueOf(HTTP_PORT); +======= + Config.http_slow_request_threshold_ms = 0; +>>>>>>> 6488726958 ([Enhancement] Add logs for slow interfaces (#33908)) Request request = new Request.Builder() .get() .addHeader("Authorization", rootAuth)