fix(接口测试): 修复k8s资源池并发数设置不生效问题

Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
fit2-zhao 2023-09-15 17:28:04 +08:00 committed by fit2-zhao
parent 29b297f3bc
commit a20ae21e31
2 changed files with 22 additions and 4 deletions

View File

@ -11,10 +11,7 @@ import io.metersphere.base.domain.TestResource;
import io.metersphere.commons.config.KafkaConfig;
import io.metersphere.commons.constants.ExtendedParameter;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.ApiFileUtil;
import io.metersphere.commons.utils.GenerateHashTreeUtil;
import io.metersphere.commons.utils.HashTreeUtil;
import io.metersphere.commons.utils.JSON;
import io.metersphere.commons.utils.*;
import io.metersphere.config.JmeterProperties;
import io.metersphere.dto.*;
import io.metersphere.engine.Engine;
@ -56,6 +53,8 @@ public class JMeterService {
private ApiPoolDebugService apiPoolDebugService;
@Resource
private PluginService pluginService;
@Resource
private ResourcePoolCalculation resourcePoolCalculation;
@PostConstruct
private void init() {
@ -106,6 +105,7 @@ public class JMeterService {
if (request.getHashTree() != null) {
this.fileProcessing(request);
}
request.setCorePoolSize(resourcePoolCalculation.k8sMaxCoreSize(request.getPoolId()));
LoggerUtil.info("开始发送请求[ " + request.getTestId() + " ] 到K8S节点执行", request.getReportId());
final Engine engine = EngineFactory.createApiEngine(request);
engine.start();

View File

@ -6,8 +6,11 @@ import io.metersphere.base.domain.TestResourcePool;
import io.metersphere.base.domain.TestResourcePoolExample;
import io.metersphere.base.mapper.TestResourceMapper;
import io.metersphere.base.mapper.TestResourcePoolMapper;
import io.metersphere.commons.utils.JSON;
import io.metersphere.dto.NodeDTO;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -36,4 +39,19 @@ public class ResourcePoolCalculation {
}
return new ArrayList<>();
}
public int k8sMaxCoreSize(String resourcePoolId) {
TestResourceExample resourceExample = new TestResourceExample();
resourceExample.createCriteria().andTestResourcePoolIdEqualTo(resourcePoolId);
List<TestResource> testResources = testResourceMapper.selectByExampleWithBLOBs(resourceExample);
if (CollectionUtils.isNotEmpty(testResources)) {
String configuration = testResources.get(0).getConfiguration();
if (StringUtils.isNotBlank(configuration)) {
NodeDTO node = JSON.parseObject(configuration, NodeDTO.class);
return node.getMaxConcurrency();
}
}
return 10;
}
}