diff --git a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/sdk/AbstractBkApiClient.java b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/sdk/AbstractBkApiClient.java index 879cce9883..1adc222cae 100644 --- a/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/sdk/AbstractBkApiClient.java +++ b/src/backend/commons/esb-sdk/src/main/java/com/tencent/bk/job/common/esb/sdk/AbstractBkApiClient.java @@ -32,6 +32,7 @@ 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; @@ -39,6 +40,8 @@ import org.slf4j.LoggerFactory; import org.springframework.http.HttpMethod; +import java.util.concurrent.TimeUnit; + /** * 蓝鲸API调用客户端 - for BK API Gateway */ @@ -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 String postForString(String uri, T body, ExtHttpHelper httpHelper) { - if (httpHelper == null) { httpHelper = defaultHttpHelper; } @@ -141,6 +152,8 @@ private EsbResp requestApiAndWrapResponse(HttpMethod httpMethod, String reqStr = JsonUtils.toJsonWithoutSkippedFields(apiContext.getReq()); EsbResp esbResp; String respStr = null; + String status = "ok"; + long start = System.currentTimeMillis(); try { respStr = requestApi(httpMethod, uri, reqBody, httpHelper); apiContext.setOriginResp(respStr); @@ -149,6 +162,7 @@ private EsbResp 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); } @@ -166,6 +180,7 @@ private EsbResp requestApiAndWrapResponse(HttpMethod httpMethod, reqStr, respStr ); + status = "error"; } if (esbResp.getData() == null) { log.warn( @@ -189,7 +204,12 @@ private EsbResp 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); } } diff --git a/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/constants/GseConstants.java b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/constants/GseConstants.java index 52b8e5470a..3e9fe1720e 100644 --- a/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/constants/GseConstants.java +++ b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/constants/GseConstants.java @@ -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依赖版本 */ diff --git a/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/v2/GseV2ApiClient.java b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/v2/GseV2ApiClient.java index 7970b407eb..6d9ab51f92 100644 --- a/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/v2/GseV2ApiClient.java +++ b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/v2/GseV2ApiClient.java @@ -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; @@ -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()); } diff --git a/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/v2/GseV2AutoConfiguration.java b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/v2/GseV2AutoConfiguration.java index cb575482b5..61a8eb2905 100644 --- a/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/v2/GseV2AutoConfiguration.java +++ b/src/backend/commons/gse-sdk/src/main/java/com/tencent/bk/job/common/gse/v2/GseV2AutoConfiguration.java @@ -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; @@ -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); } } diff --git a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebPermissionResourceImpl.java b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebPermissionResourceImpl.java index 1b3dc3beb8..91a3e923c5 100644 --- a/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebPermissionResourceImpl.java +++ b/src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/api/web/impl/WebPermissionResourceImpl.java @@ -234,10 +234,20 @@ private Response 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": diff --git a/src/frontend/src/domain/source/task-execute.js b/src/frontend/src/domain/source/task-execute.js index 4a5f9579cb..bb885fe076 100644 --- a/src/frontend/src/domain/source/task-execute.js +++ b/src/frontend/src/domain/source/task-execute.js @@ -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, }); diff --git a/src/frontend/src/views/executive-history/step-detail/components/execution-info/index.vue b/src/frontend/src/views/executive-history/step-detail/components/execution-info/index.vue index b34fb06c14..94daaaa7fb 100644 --- a/src/frontend/src/views/executive-history/step-detail/components/execution-info/index.vue +++ b/src/frontend/src/views/executive-history/step-detail/components/execution-info/index.vue @@ -286,7 +286,7 @@ handleDownload() { TaskExecuteService.fetchStepExecutionLogFile({ id: this.stepInstanceId, - ip: this.host.hostId, + hostId: this.host.hostId, }).then(() => { this.$bkMessage({ theme: 'success', diff --git a/src/frontend/src/views/executive-history/step-detail/index.vue b/src/frontend/src/views/executive-history/step-detail/index.vue index 1077b4c5c9..dfbe0a1ed9 100644 --- a/src/frontend/src/views/executive-history/step-detail/index.vue +++ b/src/frontend/src/views/executive-history/step-detail/index.vue @@ -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 开始强制终止 */