Skip to content

Commit

Permalink
[Enhancement][Cherry-Pick] Add logs for slow interfaces (#34021)
Browse files Browse the repository at this point in the history
Signed-off-by: Astralidea <[email protected]>
  • Loading branch information
Astralidea authored Oct 31, 2023
1 parent 4d61cff commit 71be687
Show file tree
Hide file tree
Showing 2 changed files with 14 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 @@ -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
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) throws Exception {
LOG.info("receive http request. url={}", request.getRequest().uri());
long startTime = System.currentTimeMillis();
BaseResponse response = new BaseResponse();
try {
execute(request, response);
Expand All @@ -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
Expand Down

0 comments on commit 71be687

Please sign in to comment.