fix(接口测试): 修复k8s资源池没有可用的pod无提示问题

--bug=1020710 --user=赵勇 【接口测试】K8S资源池异常时接口测试执行失败未正常处理 https://www.tapd.cn/55049933/s/1313865
This commit is contained in:
fit2-zhao 2022-12-07 15:27:46 +08:00 committed by fit2-zhao
parent 6204c6b8cd
commit e0309cbe2d
12 changed files with 60 additions and 5 deletions

View File

@ -2,12 +2,14 @@ package io.metersphere.api.exec.engine;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.metersphere.api.dto.MsgDTO;
import io.metersphere.base.domain.TestResource;
import io.metersphere.commons.constants.ApiRunMode;
import io.metersphere.commons.constants.ExtendedParameter;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.JSON;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.WebSocketUtil;
import io.metersphere.dto.JmeterRunRequestDTO;
import io.metersphere.utils.LoggerUtil;
import io.metersphere.xpack.resourcepool.engine.provider.ClientCredential;
@ -21,6 +23,7 @@ import java.util.Set;
public class KubernetesTestEngine extends AbstractEngine {
private JmeterRunRequestDTO runRequest;
private final String DEBUG_ERROR = "DEBUG_ERROR";
// 初始化API调用
public KubernetesTestEngine(JmeterRunRequestDTO runRequest) {
@ -77,6 +80,14 @@ public class KubernetesTestEngine extends AbstractEngine {
command.append(StringUtils.SPACE).append("http://127.0.0.1:8082/jmeter/").append(path);
KubernetesApiExec.newExecWatch(client, clientCredential.getNamespace(), pod.getMetadata().getName(), command.toString());
} catch (Exception e) {
MsgDTO dto = new MsgDTO();
dto.setExecEnd(false);
dto.setContent(DEBUG_ERROR);
dto.setReportId("send." + runRequest.getReportId());
dto.setToReport(runRequest.getReportId());
LoggerUtil.debug("send. " + runRequest.getReportId());
WebSocketUtil.sendMessageSingle(dto);
WebSocketUtil.onClose(runRequest.getReportId());
LoggerUtil.error("当前报告:【" + runRequest.getReportId() + "】资源:【" + runRequest.getTestId() + "】CURL失败", e);
MSException.throwException(e);
}

View File

@ -503,6 +503,14 @@ export default {
this.runningEvaluation(e.data);
this.sort(this.fullTreeNodes);
}
if (e && e.data === 'DEBUG_ERROR') {
this.$error(this.$t('api_definition.debug_pool_warning'));
this.messageWebSocket.close();
this.cleanHeartBeat();
this.$EventBus.$emit('hide', this.scenarioId);
this.$emit('refresh', this.debugResult);
}
if (e.data && e.data.indexOf('MS_TEST_END') !== -1) {
this.getReport();
this.messageWebSocket.close();

View File

@ -1233,6 +1233,11 @@ export default {
if (e && e.data === 'CONN_SUCCEEDED') {
this.run();
}
if (e && e.data === 'DEBUG_ERROR') {
this.$error(this.$t('api_definition.debug_pool_warning'));
this.messageWebSocket.close();
this.errorRefresh();
}
if (e.data && e.data.startsWith('result_')) {
let data = JSON.parse(e.data.substring(7));
this.reqTotal += 1;

View File

@ -292,6 +292,13 @@ export default {
if (e && e.data === 'CONN_SUCCEEDED') {
this.runDebug();
}
if (e && e.data === 'DEBUG_ERROR') {
this.$error(this.$t('api_definition.debug_pool_warning'));
this.loading = false;
this.node.expanded = true;
this.messageWebSocket.close();
this.reload();
}
if (e.data && e.data.startsWith('result_')) {
let data = JSON.parse(e.data.substring(7));
this.debugCode(data);

View File

@ -62,7 +62,11 @@ export default {
if (e && e.data === 'CONN_SUCCEEDED') {
this.run();
}
if (e && e.data === 'DEBUG_ERROR') {
this.$error(this.$t('api_definition.debug_pool_warning'));
this.websocket.close();
this.$emit('errorRefresh', '');
}
if (e.data && e.data.startsWith('result_')) {
try {
let data = e.data.substring(7);

View File

@ -53,6 +53,7 @@
:isStop="isStop"
:run-data="runData"
@runRefresh="runRefresh"
@errorRefresh="errorRefresh"
ref="runTest" />
</el-card>
<div v-if="scenario">
@ -188,11 +189,14 @@ export default {
this.reportId = getUUID().substring(0, 8);
},
runRefresh(data) {
this.responseData = data;
this.responseData = data || { type: 'DUBBO', responseResult: {}, subRequestResults: [] };
this.loading = false;
this.isStop = false;
this.$refs.debugResult.reload();
},
errorRefresh() {
this.runRefresh();
},
saveAsApi() {
let obj = { request: this.request };
obj.request.id = getUUID();

View File

@ -74,6 +74,7 @@
:isStop="isStop"
:run-data="runData"
@runRefresh="runRefresh"
@errorRefresh="errorRefresh"
ref="runTest" />
</div>
</el-card>
@ -240,13 +241,16 @@ export default {
this.$emit('refreshModule');
},
runRefresh(data) {
this.responseData = data;
this.responseData = data || { type: 'HTTP', responseResult: {}, subRequestResults: [] };
this.loading = false;
this.isStop = false;
if (this.$refs.debugResult) {
this.$refs.debugResult.reload();
}
},
errorRefresh() {
this.runRefresh();
},
saveAsApi() {
this.$refs['debugForm'].validate((valid) => {
if (valid) {

View File

@ -54,6 +54,7 @@
:isStop="isStop"
:run-data="runData"
@runRefresh="runRefresh"
@errorRefresh="errorRefresh"
ref="runTest" />
</el-card>
<div v-if="scenario">
@ -194,13 +195,16 @@ export default {
this.reportId = getUUID().substring(0, 8);
},
runRefresh(data) {
this.responseData = data;
this.responseData = data || { type: 'JDBC', responseResult: {}, subRequestResults: [] };
this.loading = false;
this.isStop = false;
if (this.$refs.debugResult) {
this.$refs.debugResult.reload();
}
},
errorRefresh() {
this.runRefresh();
},
saveAsApi() {
let obj = { request: this.request };
obj.request.id = getUUID();

View File

@ -56,6 +56,7 @@
:isStop="isStop"
:run-data="runData"
@runRefresh="runRefresh"
@errorRefresh="errorRefresh"
ref="runTest" />
</el-card>
<div v-if="scenario">
@ -193,13 +194,16 @@ export default {
this.reportId = getUUID().substring(0, 8);
},
runRefresh(data) {
this.responseData = data;
this.responseData = data || { type: 'TCP', responseResult: {}, subRequestResults: [] };
this.loading = false;
this.isStop = false;
if (this.$refs.debugResult) {
this.$refs.debugResult.reload();
}
},
errorRefresh() {
this.runRefresh();
},
saveAsApi() {
let obj = { request: this.request };
obj.request.id = getUUID();

View File

@ -7,6 +7,8 @@ const message = {
please_add_api_case: 'Please add api case',
},
api_definition: {
debug_pool_warning:
'Failed to call the resource pool, please check whether the configuration of the resource pool is normal',
document: {
name: 'name',
value: 'value',

View File

@ -7,6 +7,7 @@ const message = {
please_add_api_case: '请先添加接口用例',
},
api_definition: {
debug_pool_warning: '调用资源池执行失败,请检查资源池是否配置正常',
document: {
name: '名称',
value: '值',

View File

@ -7,6 +7,7 @@ const message = {
please_add_api_case: '请先添加接口用例',
},
api_definition: {
debug_pool_warning: '調用資源池執行失敗,請檢查資源池是否配置正常',
document: {
name: '名稱',
value: '值',