Skip to content

Commit

Permalink
Merge pull request #1147 from jsonwan/github_perf/sla
Browse files Browse the repository at this point in the history
perf: 增加快速执行、执行引擎、定时任务等SLI指标实现 #1101
  • Loading branch information
jsonwan authored Jul 27, 2022
2 parents 0dddcb4 + db64504 commit 6deb730
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
*
* License for BK-JOB蓝鲸智云作业平台:
* --------------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.common.esb.metrics;

public class EsbMetricTags {
/**
* API名称
*/
public static final String KEY_API_NAME = "api_name";
/**
* 接口调用状态
*/
public static final String KEY_STATUS = "status";
/**
* 接口调用状态:初始值
*/
public static final String VALUE_STATUS_NONE = "none";
/**
* 接口调用状态:成功
*/
public static final String VALUE_STATUS_SUCCESS = "success";
/**
* 接口调用状态:失败
*/
public static final String VALUE_STATUS_FAIL = "fail";
/**
* 接口调用状态:超频
*/
public static final String VALUE_STATUS_OVER_RATE = "over_rate";
/**
* 接口调用状态:错误
*/
public static final String VALUE_STATUS_ERROR = "error";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
*
* License for BK-JOB蓝鲸智云作业平台:
* --------------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.common.esb;

import com.fasterxml.jackson.core.type.TypeReference;
import com.tencent.bk.job.common.esb.model.EsbResp;
import com.tencent.bk.job.common.util.json.JsonUtils;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;

public class EsbRespTest {

@Test
public void testDeserialize() {
String respStr = "{\"message\": \"message\", \"code\": \"00\", \"data\": {\"msg_id\": " +
"\"test\"}, \"result\": true, \"request_id\": \"test\"}";
EsbResp<Object> esbResp = JsonUtils.fromJson(
respStr,
new TypeReference<EsbResp<Object>>() {
}
);
assertThat(esbResp).isNotNull();
respStr = "{\"message\": \"message\", \"code\": \"00\", \"data\": [\"test\"], \"result\": true, " +
"\"request_id\": \"test\"}";
esbResp = JsonUtils.fromJson(
respStr,
new TypeReference<EsbResp<Object>>() {
}
);
assertThat(esbResp).isNotNull();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
*
* License for BK-JOB蓝鲸智云作业平台:
* --------------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.common.paas.metrics;

public class PaaSMetricTags {
/**
* 消息通知接口的消息类型
*/
public static final String KEY_MSG_TYPE = "msg_type";
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.tencent.bk.job.common.constant.ErrorCode;
import com.tencent.bk.job.common.esb.metrics.EsbMetricTags;
import com.tencent.bk.job.common.esb.model.EsbResp;
import com.tencent.bk.job.common.esb.sdk.AbstractEsbSdkClient;
import com.tencent.bk.job.common.exception.InternalException;
import com.tencent.bk.job.common.metrics.CommonMetricNames;
import com.tencent.bk.job.common.model.dto.BkUserDTO;
import com.tencent.bk.job.common.paas.metrics.PaaSMetricTags;
import com.tencent.bk.job.common.paas.model.EsbListUsersResult;
import com.tencent.bk.job.common.paas.model.EsbNotifyChannelDTO;
import com.tencent.bk.job.common.paas.model.GetEsbNotifyChannelReq;
Expand Down Expand Up @@ -98,7 +100,7 @@ public List<BkUserDTO> getUserList(String fields,

HttpMetricUtil.setHttpMetricName(CommonMetricNames.ESB_USER_MANAGE_API_HTTP);
HttpMetricUtil.addTagForCurrentMetric(
Tag.of("api_name", API_GET_USER_LIST)
Tag.of(EsbMetricTags.KEY_API_NAME, API_GET_USER_LIST)
);
EsbResp<List<EsbListUsersResult>> esbResp = getEsbRespByReq(
HttpGet.METHOD_NAME,
Expand Down Expand Up @@ -152,7 +154,7 @@ public List<EsbNotifyChannelDTO> getNotifyChannelList(String uin) {
try {
HttpMetricUtil.setHttpMetricName(CommonMetricNames.ESB_CMSI_API_HTTP);
HttpMetricUtil.addTagForCurrentMetric(
Tag.of("api_name", API_GET_NOTIFY_CHANNEL_LIST)
Tag.of(EsbMetricTags.KEY_API_NAME, API_GET_NOTIFY_CHANNEL_LIST)
);
EsbResp<List<EsbNotifyChannelDTO>> esbResp = getEsbRespByReq(
HttpGet.METHOD_NAME,
Expand All @@ -177,43 +179,53 @@ public boolean sendMsg(
) {
PostSendMsgReq req = buildSendMsgReq(msgType, sender, receivers, title, content);
long start = System.nanoTime();
String status = "none";
String status = EsbMetricTags.VALUE_STATUS_NONE;
String uri = API_POST_SEND_MSG;
try {
HttpMetricUtil.setHttpMetricName(CommonMetricNames.ESB_CMSI_API_HTTP);
HttpMetricUtil.addTagForCurrentMetric(Tag.of("api_name", uri));
EsbResp<List<Boolean>> esbResp = getEsbRespByReq(
HttpMetricUtil.addTagForCurrentMetric(Tag.of(EsbMetricTags.KEY_API_NAME, uri));
EsbResp<Object> esbResp = getEsbRespByReq(
HttpPost.METHOD_NAME,
uri,
req,
new TypeReference<EsbResp<List<Boolean>>>() {
new TypeReference<EsbResp<Object>>() {
}
);

if (esbResp.getCode() != 0) {
Integer code = esbResp.getCode();
log.warn("{}|requestId={}|code={}|msg={}|esbResp.getCode() != 0",
uri, esbResp.getRequestId(), esbResp.getCode(), esbResp.getMessage());
if (code.equals(ESB_CODE_RATE_LIMIT_RESTRICTION_BY_STAGE)
|| code.equals(ESB_CODE_RATE_LIMIT_RESTRICTION_BY_RESOURCE)) {
status = "over_rate";
} else {
status = "fail";
}
if (esbResp.getResult() == null || !esbResp.getResult() || esbResp.getCode() != 0) {
status = checkRespAndGetStatus(uri, esbResp);
return false;
}
status = "success";
status = EsbMetricTags.VALUE_STATUS_SUCCESS;
return true;
} catch (Exception e) {
log.error("Fail to request {}", uri, e);
status = "error";
status = EsbMetricTags.VALUE_STATUS_ERROR;
return false;
} finally {
HttpMetricUtil.clearHttpMetric();
recordMetrics(start, status, msgType);
}
}

private String checkRespAndGetStatus(String uri, EsbResp<?> esbResp) {
Integer code = esbResp.getCode();
log.warn(
"{}|requestId={}|result={}|code={}|msg={}|esbResp.getCode() != 0",
uri,
esbResp.getRequestId(),
esbResp.getResult(),
esbResp.getCode(),
esbResp.getMessage()
);
if (code.equals(ESB_CODE_RATE_LIMIT_RESTRICTION_BY_STAGE)
|| code.equals(ESB_CODE_RATE_LIMIT_RESTRICTION_BY_RESOURCE)) {
return EsbMetricTags.VALUE_STATUS_OVER_RATE;
} else {
return EsbMetricTags.VALUE_STATUS_FAIL;
}
}

private PostSendMsgReq buildSendMsgReq(String msgType,
String sender,
Set<String> receivers,
Expand All @@ -235,9 +247,9 @@ private void recordMetrics(long startTimeNanos, String status, String msgType) {
long end = System.nanoTime();
meterRegistry.timer(
CommonMetricNames.ESB_CMSI_API,
"api_name", API_POST_SEND_MSG,
"status", status,
"msg_type", msgType
EsbMetricTags.KEY_API_NAME, API_POST_SEND_MSG,
EsbMetricTags.KEY_STATUS, status,
PaaSMetricTags.KEY_MSG_TYPE, msgType
).record(end - startTimeNanos, TimeUnit.NANOSECONDS);
String key = "today.msg." + msgType + "." + status;
AtomicInteger valueWrapper = todayMsgStatisticsMap.computeIfAbsent(key,
Expand Down
4 changes: 2 additions & 2 deletions support-files/kubernetes/charts/bk-job/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: "bk-job"
description: The BK-JOB is a ops script management and execution system with the capability of dealing with multiple tasks simultaneously.
type: application
version: 0.3.0-rc.7
appVersion: "3.6.0-rc.7"
version: 0.3.0-rc.8
appVersion: "3.6.0-rc.8"

dependencies:
- name: common
Expand Down
22 changes: 11 additions & 11 deletions support-files/kubernetes/charts/bk-job/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ gatewayConfig:
image:
registry: hub.bktencent.com
repository: blueking/job-gateway
tag: 3.6.0-rc.7
tag: 3.6.0-rc.8
pullPolicy: IfNotPresent
pullSecrets: []
replicaCount: 1
Expand Down Expand Up @@ -733,7 +733,7 @@ manageConfig:
image:
registry: hub.bktencent.com
repository: blueking/job-manage
tag: 3.6.0-rc.7
tag: 3.6.0-rc.8
pullPolicy: IfNotPresent
pullSecrets: []
replicaCount: 1
Expand Down Expand Up @@ -791,7 +791,7 @@ executeConfig:
image:
registry: hub.bktencent.com
repository: blueking/job-execute
tag: 3.6.0-rc.7
tag: 3.6.0-rc.8
pullPolicy: IfNotPresent
pullSecrets: []
replicaCount: 1
Expand Down Expand Up @@ -842,7 +842,7 @@ crontabConfig:
image:
registry: hub.bktencent.com
repository: blueking/job-crontab
tag: 3.6.0-rc.7
tag: 3.6.0-rc.8
pullPolicy: IfNotPresent
pullSecrets: []
replicaCount: 1
Expand Down Expand Up @@ -902,7 +902,7 @@ logsvrConfig:
image:
registry: hub.bktencent.com
repository: blueking/job-logsvr
tag: 3.6.0-rc.7
tag: 3.6.0-rc.8
pullPolicy: IfNotPresent
pullSecrets: []
replicaCount: 1
Expand Down Expand Up @@ -957,7 +957,7 @@ backupConfig:
image:
registry: hub.bktencent.com
repository: blueking/job-backup
tag: 3.6.0-rc.7
tag: 3.6.0-rc.8
pullPolicy: IfNotPresent
pullSecrets: []
replicaCount: 1
Expand Down Expand Up @@ -1007,7 +1007,7 @@ analysisConfig:
image:
registry: hub.bktencent.com
repository: blueking/job-analysis
tag: 3.6.0-rc.7
tag: 3.6.0-rc.8
pullPolicy: IfNotPresent
pullSecrets: []
replicaCount: 1
Expand Down Expand Up @@ -1057,7 +1057,7 @@ fileGatewayConfig:
image:
registry: hub.bktencent.com
repository: blueking/job-file-gateway
tag: 3.6.0-rc.7
tag: 3.6.0-rc.8
pullPolicy: IfNotPresent
pullSecrets: []
replicaCount: 1
Expand Down Expand Up @@ -1107,7 +1107,7 @@ fileWorkerConfig:
image:
registry: hub.bktencent.com
repository: blueking/job-file-worker
tag: 3.6.0-rc.7
tag: 3.6.0-rc.8
pullPolicy: IfNotPresent
pullSecrets: []
replicaCount: 1
Expand Down Expand Up @@ -1180,7 +1180,7 @@ frontendConfig:
image:
registry: hub.bktencent.com
repository: blueking/job-frontend
tag: 3.6.0-rc.7
tag: 3.6.0-rc.8
pullPolicy: IfNotPresent
pullSecrets: []
replicaCount: 1
Expand Down Expand Up @@ -1241,7 +1241,7 @@ migration:
# 镜像拉取仓库组织与镜像名称
repository: "blueking/job-migration"
# 镜像标签
tag: 3.6.0-rc.7
tag: 3.6.0-rc.8
# 镜像拉取策略
pullPolicy: IfNotPresent

Expand Down

0 comments on commit 6deb730

Please sign in to comment.