From a20ae21e31598bd4596311c7530b0590e415967e Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Fri, 15 Sep 2023 17:28:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dk8s=E8=B5=84=E6=BA=90=E6=B1=A0=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E6=95=B0=E8=AE=BE=E7=BD=AE=E4=B8=8D=E7=94=9F=E6=95=88?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fit2-zhao --- .../metersphere/api/jmeter/JMeterService.java | 8 ++++---- .../api/jmeter/ResourcePoolCalculation.java | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java index bb2c898952..16ed9b8923 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java @@ -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(); diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/ResourcePoolCalculation.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/ResourcePoolCalculation.java index 41350d745c..85ff60f8e3 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/ResourcePoolCalculation.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/ResourcePoolCalculation.java @@ -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 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; + } + }