Skip to content

Commit

Permalink
Merge pull request #2456 from jsonwan/3.8.x
Browse files Browse the repository at this point in the history
Merge: 3.7.x->3.8.x
  • Loading branch information
jsonwan authored Sep 15, 2023
2 parents 1d68c2c + 2650656 commit 935de87
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
import com.tencent.bk.job.common.util.http.ExtHttpHelper;
import com.tencent.bk.job.common.util.http.HttpHelperFactory;
import com.tencent.bk.job.common.util.json.JsonUtils;
import io.micrometer.core.instrument.MeterRegistry;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.apache.http.message.BasicHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;

import java.util.concurrent.TimeUnit;

/**
* 蓝鲸API调用客户端 - for BK API Gateway
*/
Expand All @@ -48,17 +51,25 @@ public abstract class AbstractBkApiClient {
private final String appSecret;
private final String appCode;
private final ExtHttpHelper defaultHttpHelper = HttpHelperFactory.getDefaultHttpHelper();

public AbstractBkApiClient(String bkApiGatewayUrl,
private final MeterRegistry meterRegistry;
/**
* API调用度量指标名称
*/
private final String metricName;

public AbstractBkApiClient(MeterRegistry meterRegistry,
String metricName,
String bkApiGatewayUrl,
String appCode,
String appSecret) {
this.meterRegistry = meterRegistry;
this.metricName = metricName;
this.bkApiGatewayUrl = bkApiGatewayUrl;
this.appCode = appCode;
this.appSecret = appSecret;
}

private <T> String postForString(String uri, T body, ExtHttpHelper httpHelper) {

if (httpHelper == null) {
httpHelper = defaultHttpHelper;
}
Expand Down Expand Up @@ -141,6 +152,8 @@ private <T, R> EsbResp<R> requestApiAndWrapResponse(HttpMethod httpMethod,
String reqStr = JsonUtils.toJsonWithoutSkippedFields(apiContext.getReq());
EsbResp<R> esbResp;
String respStr = null;
String status = "ok";
long start = System.currentTimeMillis();
try {
respStr = requestApi(httpMethod, uri, reqBody, httpHelper);
apiContext.setOriginResp(respStr);
Expand All @@ -149,6 +162,7 @@ private <T, R> EsbResp<R> requestApiAndWrapResponse(HttpMethod httpMethod,
String errorMsg = "[AbstractBkApiClient] " + httpMethod.name() + " "
+ uri + ", error: " + "Response is blank";
log.error(errorMsg);
status = "error";
throw new InternalException(errorMsg, ErrorCode.API_ERROR);
}

Expand All @@ -166,6 +180,7 @@ private <T, R> EsbResp<R> requestApiAndWrapResponse(HttpMethod httpMethod,
reqStr,
respStr
);
status = "error";
}
if (esbResp.getData() == null) {
log.warn(
Expand All @@ -189,7 +204,12 @@ private <T, R> EsbResp<R> requestApiAndWrapResponse(HttpMethod httpMethod,
+ "|respStr=" + respStr;
log.error(errorMsg, e);
apiContext.setSuccess(false);
status = "error";
throw new InternalException("Fail to request bk api", e, ErrorCode.API_ERROR);
} finally {
long end = System.currentTimeMillis();
meterRegistry.timer(metricName, "api_name", uri,
"status", status).record(end - start, TimeUnit.MILLISECONDS);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public interface GseConstants {
*/
String GSE_API_METRICS_NAME_PREFIX = "job.client.gse.api";

/**
* GSE V2 API 度量指标名称前缀
*/
String GSE_V2_API_METRICS_NAME_PREFIX = "job.client.gse.v2.api";

/**
* GSE 获取文件任务执行结果协议版本V2 - 解除valuekey依赖版本
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.tencent.bk.job.common.gse.v2.model.resp.AgentState;
import com.tencent.bk.job.common.util.StringUtil;
import com.tencent.bk.job.common.util.json.JsonUtils;
import io.micrometer.core.instrument.MeterRegistry;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
Expand All @@ -37,8 +38,14 @@ public class GseV2ApiClient extends AbstractBkApiClient implements IGseClient {
private static final String URI_ASYNC_TRANSFER_FILE = "/api/v2/task/async_transfer_file";
private static final String URI_GET_TRANSFER_FILE_RESULT = "/api/v2/task/async/get_transfer_file_result";

public GseV2ApiClient(AppProperties appProperties, BkApiGatewayProperties bkApiGatewayProperties) {
super(bkApiGatewayProperties.getGse().getUrl(), appProperties.getCode(), appProperties.getSecret());
public GseV2ApiClient(MeterRegistry meterRegistry,
AppProperties appProperties,
BkApiGatewayProperties bkApiGatewayProperties) {
super(meterRegistry,
GseConstants.GSE_V2_API_METRICS_NAME_PREFIX,
bkApiGatewayProperties.getGse().getUrl(),
appProperties.getCode(),
appProperties.getSecret());
log.info("Init GseV2ApiClient, bkGseApiGatewayUrl: {}, appCode: {}",
bkApiGatewayProperties.getGse().getUrl(), appProperties.getCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.tencent.bk.job.common.esb.config.AppProperties;
import com.tencent.bk.job.common.esb.config.BkApiGatewayProperties;
import com.tencent.bk.job.common.gse.config.GseV2Properties;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
Expand All @@ -38,8 +39,9 @@
public class GseV2AutoConfiguration {

@Bean("gseV2ApiClient")
public GseV2ApiClient gseV2ApiClient(AppProperties appProperties,
public GseV2ApiClient gseV2ApiClient(MeterRegistry meterRegistry,
AppProperties appProperties,
BkApiGatewayProperties bkApiGatewayProperties) {
return new GseV2ApiClient(appProperties, bkApiGatewayProperties);
return new GseV2ApiClient(meterRegistry, appProperties, bkApiGatewayProperties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,20 @@ private Response<AuthResultVO> checkJobTemplateOperationPermission(
);
case "edit":
templateId = Long.parseLong(resourceId);
AuthResult authEditResult = templateAuthService.authEditJobTemplate(
username,
appResourceScope,
templateId
);
AuthResult authViewResult = templateAuthService.authViewJobTemplate(
username,
appResourceScope,
templateId
);
return Response.buildSuccessResp(
webAuthService.toAuthResultVO(
isReturnApplyUrl,
templateAuthService.authEditJobTemplate(username, appResourceScope, templateId)
authEditResult.mergeAuthResult(authViewResult)
)
);
case "delete":
Expand Down
9 changes: 5 additions & 4 deletions src/frontend/src/domain/source/task-execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,11 @@ class TaskExecute extends ModuleBase {

// 下载执行日志文件
getLogFile(payload) {
const params = {};
if (payload.ip) {
params.ip = payload.ip;
}
const params = {
...payload,
};
delete params.id;

return Request.download(`${this.path}/step-execution-result/${payload.id}/log-file/download`, {
params,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
handleDownload() {
TaskExecuteService.fetchStepExecutionLogFile({
id: this.stepInstanceId,
ip: this.host.hostId,
hostId: this.host.hostId,
}).then(() => {
this.$bkMessage({
theme: 'success',
Expand Down
13 changes: 0 additions & 13 deletions src/frontend/src/views/executive-history/step-detail/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -551,19 +551,6 @@
execCopy(fieldDataList.join('\n'), successMessage);
});
},
/**
* @desc 导出脚本执行日志
*/
handleExportExecutionLog() {
TaskExecuteService.fetchStepExecutionLogFile({
id: this.params.id,
}).then(() => {
this.$bkMessage({
theme: 'success',
message: I18n.t('history.导出日志操作成功'),
});
});
},
/**
* @desc 开始强制终止
*/
Expand Down

0 comments on commit 935de87

Please sign in to comment.