Skip to content

Commit

Permalink
[Enhancement] Add logs for slow interfaces (#33908)
Browse files Browse the repository at this point in the history
Signed-off-by: Astralidea <[email protected]>
(cherry picked from commit 6488726)
  • Loading branch information
Astralidea authored and wanpengfei-git committed Oct 31, 2023
1 parent c87e43c commit 5b536f8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/common/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,6 +69,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);
Expand All @@ -88,6 +90,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5b536f8

Please sign in to comment.