Skip to content

Commit

Permalink
Merge pull request #3330 from jsonwan/github_perf/log
Browse files Browse the repository at this point in the history
perf: 请求GSE等底层系统接口响应非200时打印Header中的关键信息 #3179
  • Loading branch information
wangyu096 authored Dec 13, 2024
2 parents d7ca973 + 742da39 commit ddd42f0
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public BkAIDevClient(MeterRegistry meterRegistry,
meterRegistry,
CommonMetricNames.BK_AI_DEV_API,
getBkAIDevUrlSafely(bkApiGatewayProperties),
HttpHelperFactory.getDefaultHttpHelper(
HttpHelperFactory.createHttpHelper(
httpClientBuilder -> httpClientBuilder.addInterceptorLast(getLogBkApiRequestIdInterceptor())
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public EsbIamClient(MeterRegistry meterRegistry,
meterRegistry,
IAM_API,
esbProperties.getService().getUrl(),
HttpHelperFactory.getDefaultHttpHelper(
HttpHelperFactory.createHttpHelper(
httpClientBuilder -> httpClientBuilder.addInterceptorLast(getLogBkApiRequestIdInterceptor())
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,28 @@ private static WatchableHttpHelper getWatchableExtHelper(HttpHelper httpHelper)
}

public static WatchableHttpHelper getDefaultHttpHelper() {
return getDefaultHttpHelper(null);
HttpHelper baseHttpHelper = new BaseHttpHelper(DEFAULT_HTTP_CLIENT);
return getWatchableExtHelper(baseHttpHelper);
}

@SuppressWarnings("unused")
public static WatchableHttpHelper getRetryableHttpHelper() {
HttpHelper baseHttpHelper = new BaseHttpHelper(RETRYABLE_HTTP_CLIENT);
return getWatchableExtHelper(baseHttpHelper);
}

public static WatchableHttpHelper getLongRetryableHttpHelper() {
HttpHelper baseHttpHelper = new BaseHttpHelper(LONG_RETRYABLE_HTTP_CLIENT);
return getWatchableExtHelper(baseHttpHelper);
}

public static WatchableHttpHelper getDefaultHttpHelper(JobHttpClientFactory.HttpClientCustomizer customizer) {
/**
* 创建自定义的HttpHelper,每创建一次都会生成一个常驻的连接驱逐线程,请在单例中使用,避免线程泄露
*
* @param customizer 自定义的HttpClient定制器
* @return 自定义的HttpHelper
*/
public static WatchableHttpHelper createHttpHelper(JobHttpClientFactory.HttpClientCustomizer customizer) {
HttpHelper baseHttpHelper = createHttpHelper(
15000,
15000,
Expand All @@ -80,17 +98,20 @@ public static WatchableHttpHelper getDefaultHttpHelper(JobHttpClientFactory.Http
return getWatchableExtHelper(baseHttpHelper);
}

@SuppressWarnings("unused")
public static WatchableHttpHelper getRetryableHttpHelper() {
HttpHelper baseHttpHelper = new BaseHttpHelper(RETRYABLE_HTTP_CLIENT);
return getWatchableExtHelper(baseHttpHelper);
}

public static WatchableHttpHelper getLongRetryableHttpHelper() {
HttpHelper baseHttpHelper = new BaseHttpHelper(LONG_RETRYABLE_HTTP_CLIENT);
return getWatchableExtHelper(baseHttpHelper);
}

/**
* 创建自定义的HttpHelper,每创建一次都会生成一个常驻的连接驱逐线程,请在单例中使用,避免线程泄露
*
* @param connRequestTimeout 连接请求超时时间,单位毫秒
* @param connTimeout 连接超时时间,单位毫秒
* @param socketTimeout socket读写超时时间,单位毫秒
* @param maxConnPerRoute 单个路由最大连接数
* @param maxConnTotal 总的最大连接数
* @param timeToLive 连接驱逐线程存活时间,单位秒
* @param allowRetry 是否允许重试
* @param retryHandler 重试策略
* @param customizer 自定义的HttpClient定制器
* @return 自定义的HttpHelper
*/
public static HttpHelper createHttpHelper(int connRequestTimeout,
int connTimeout,
int socketTimeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public BkNoticeClient(MeterRegistry meterRegistry,
meterRegistry,
CommonMetricNames.BK_NOTICE_API,
getBkNoticeUrlSafely(bkApiGatewayProperties),
HttpHelperFactory.getDefaultHttpHelper(
HttpHelperFactory.createHttpHelper(
httpClientBuilder -> httpClientBuilder.addInterceptorLast(getLogBkApiRequestIdInterceptor())
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public CmsiApiClient(EsbProperties esbProperties,
meterRegistry,
ESB_CMSI_API,
esbProperties.getService().getUrl(),
HttpHelperFactory.getDefaultHttpHelper(
HttpHelperFactory.createHttpHelper(
httpClientBuilder -> httpClientBuilder.addInterceptorLast(getLogBkApiRequestIdInterceptor())
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public StandardLoginClient(EsbProperties esbProperties, AppProperties appPropert
meterRegistry,
ESB_BK_LOGIN_API,
esbProperties.getService().getUrl(),
HttpHelperFactory.getDefaultHttpHelper(
HttpHelperFactory.createHttpHelper(
httpClientBuilder -> httpClientBuilder.addInterceptorLast(getLogBkApiRequestIdInterceptor())
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.tencent.bk.job.file.worker.config.WorkerConfig;
import com.tencent.bk.job.file.worker.state.event.WorkerEvent;
import com.tencent.bk.job.file.worker.state.event.WorkerEventService;
import com.tencent.bk.job.file.worker.task.heartbeat.HeartBeatTask;
import com.tencent.bk.job.file_gateway.consts.TaskCommandEnum;
import com.tencent.bk.job.file_gateway.model.req.inner.OffLineAndReDispatchReq;
import lombok.extern.slf4j.Slf4j;
Expand Down

0 comments on commit ddd42f0

Please sign in to comment.