diff --git a/backend/src/main/java/io/metersphere/base/domain/TestResourcePool.java b/backend/src/main/java/io/metersphere/base/domain/TestResourcePool.java index c614b58d81..d62c6de146 100644 --- a/backend/src/main/java/io/metersphere/base/domain/TestResourcePool.java +++ b/backend/src/main/java/io/metersphere/base/domain/TestResourcePool.java @@ -1,7 +1,6 @@ package io.metersphere.base.domain; import java.io.Serializable; - import lombok.Data; @Data @@ -32,5 +31,7 @@ public class TestResourcePool implements Serializable { private Boolean performance; + private Boolean backendListener; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/TestResourcePoolExample.java b/backend/src/main/java/io/metersphere/base/domain/TestResourcePoolExample.java index fea8212f82..bf7d0f35d5 100644 --- a/backend/src/main/java/io/metersphere/base/domain/TestResourcePoolExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/TestResourcePoolExample.java @@ -973,6 +973,66 @@ public class TestResourcePoolExample { addCriterion("performance not between", value1, value2, "performance"); return (Criteria) this; } + + public Criteria andBackendListenerIsNull() { + addCriterion("backend_listener is null"); + return (Criteria) this; + } + + public Criteria andBackendListenerIsNotNull() { + addCriterion("backend_listener is not null"); + return (Criteria) this; + } + + public Criteria andBackendListenerEqualTo(Boolean value) { + addCriterion("backend_listener =", value, "backendListener"); + return (Criteria) this; + } + + public Criteria andBackendListenerNotEqualTo(Boolean value) { + addCriterion("backend_listener <>", value, "backendListener"); + return (Criteria) this; + } + + public Criteria andBackendListenerGreaterThan(Boolean value) { + addCriterion("backend_listener >", value, "backendListener"); + return (Criteria) this; + } + + public Criteria andBackendListenerGreaterThanOrEqualTo(Boolean value) { + addCriterion("backend_listener >=", value, "backendListener"); + return (Criteria) this; + } + + public Criteria andBackendListenerLessThan(Boolean value) { + addCriterion("backend_listener <", value, "backendListener"); + return (Criteria) this; + } + + public Criteria andBackendListenerLessThanOrEqualTo(Boolean value) { + addCriterion("backend_listener <=", value, "backendListener"); + return (Criteria) this; + } + + public Criteria andBackendListenerIn(List values) { + addCriterion("backend_listener in", values, "backendListener"); + return (Criteria) this; + } + + public Criteria andBackendListenerNotIn(List values) { + addCriterion("backend_listener not in", values, "backendListener"); + return (Criteria) this; + } + + public Criteria andBackendListenerBetween(Boolean value1, Boolean value2) { + addCriterion("backend_listener between", value1, value2, "backendListener"); + return (Criteria) this; + } + + public Criteria andBackendListenerNotBetween(Boolean value1, Boolean value2) { + addCriterion("backend_listener not between", value1, value2, "backendListener"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestResourcePoolMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/TestResourcePoolMapper.xml index 7809f174ce..d7abec5995 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/TestResourcePoolMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/TestResourcePoolMapper.xml @@ -15,6 +15,7 @@ + @@ -76,7 +77,7 @@ id, `name`, `type`, description, `status`, create_time, update_time, image, `heap`, - gc_algo, create_user, api, performance + gc_algo, create_user, api, performance, backend_listener @@ -253,6 +260,9 @@ performance = #{record.performance,jdbcType=BIT}, + + backend_listener = #{record.backendListener,jdbcType=BIT}, + @@ -272,7 +282,8 @@ gc_algo = #{record.gcAlgo,jdbcType=VARCHAR}, create_user = #{record.createUser,jdbcType=VARCHAR}, api = #{record.api,jdbcType=BIT}, - performance = #{record.performance,jdbcType=BIT} + performance = #{record.performance,jdbcType=BIT}, + backend_listener = #{record.backendListener,jdbcType=BIT} @@ -316,6 +327,9 @@ performance = #{performance,jdbcType=BIT}, + + backend_listener = #{backendListener,jdbcType=BIT}, + where id = #{id,jdbcType=VARCHAR} @@ -332,7 +346,8 @@ gc_algo = #{gcAlgo,jdbcType=VARCHAR}, create_user = #{createUser,jdbcType=VARCHAR}, api = #{api,jdbcType=BIT}, - performance = #{performance,jdbcType=BIT} + performance = #{performance,jdbcType=BIT}, + backend_listener = #{backendListener,jdbcType=BIT} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/performance/engine/AbstractEngine.java b/backend/src/main/java/io/metersphere/performance/engine/AbstractEngine.java index 3476c87552..b7cf5e605b 100644 --- a/backend/src/main/java/io/metersphere/performance/engine/AbstractEngine.java +++ b/backend/src/main/java/io/metersphere/performance/engine/AbstractEngine.java @@ -33,6 +33,7 @@ public abstract class AbstractEngine implements Engine { protected PerformanceTestService performanceTestService; protected Integer threadNum; protected List resourceList; + protected TestResourcePool resourcePool; private final TestResourcePoolService testResourcePoolService; private final TestResourceService testResourceService; @@ -45,9 +46,10 @@ public abstract class AbstractEngine implements Engine { this.startTime = System.currentTimeMillis(); this.reportId = UUID.randomUUID().toString(); } + protected void initApiConfig(RunRequest runRequest) { String resourcePoolId = runRequest.getPoolId(); - TestResourcePool resourcePool = testResourcePoolService.getResourcePool(resourcePoolId); + resourcePool = testResourcePoolService.getResourcePool(resourcePoolId); if (resourcePool == null || StringUtils.equals(resourcePool.getStatus(), ResourceStatusEnum.DELETE.name())) { MSException.throwException("Resource Pool is empty"); } @@ -78,6 +80,7 @@ public abstract class AbstractEngine implements Engine { MSException.throwException("Test Resource is empty"); } } + protected void init(LoadTestWithBLOBs loadTest) { if (loadTest == null) { MSException.throwException("LoadTest is null."); @@ -91,7 +94,7 @@ public abstract class AbstractEngine implements Engine { if (StringUtils.isBlank(resourcePoolId)) { MSException.throwException("Resource Pool ID is empty"); } - TestResourcePool resourcePool = testResourcePoolService.getResourcePool(resourcePoolId); + resourcePool = testResourcePoolService.getResourcePool(resourcePoolId); if (resourcePool == null || StringUtils.equals(resourcePool.getStatus(), ResourceStatusEnum.DELETE.name())) { MSException.throwException("Resource Pool is empty"); } diff --git a/backend/src/main/java/io/metersphere/performance/engine/docker/DockerTestEngine.java b/backend/src/main/java/io/metersphere/performance/engine/docker/DockerTestEngine.java index bb7d4219b3..e6c21108c7 100644 --- a/backend/src/main/java/io/metersphere/performance/engine/docker/DockerTestEngine.java +++ b/backend/src/main/java/io/metersphere/performance/engine/docker/DockerTestEngine.java @@ -96,6 +96,7 @@ public class DockerTestEngine extends AbstractEngine { env.put("HEAP", HEAP); env.put("GC_ALGO", GC_ALGO); env.put("GRANULARITY", performanceTestService.getGranularity(this.getReportId()).toString()); + env.put("BACKEND_LISTENER", resourcePool.getBackendListener().toString()); StartTestRequest startTestRequest = new StartTestRequest(); diff --git a/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java b/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java index 6ebd87ac17..71aa22b6bf 100644 --- a/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java +++ b/backend/src/main/java/io/metersphere/performance/parse/xml/reader/jmx/JmeterDocumentParser.java @@ -2,6 +2,7 @@ package io.metersphere.performance.parse.xml.reader.jmx; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import io.metersphere.base.domain.TestResourcePool; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.config.KafkaProperties; @@ -9,6 +10,7 @@ import io.metersphere.i18n.Translator; import io.metersphere.jmeter.utils.ScriptEngineUtils; import io.metersphere.performance.engine.EngineContext; import io.metersphere.performance.parse.xml.reader.DocumentParser; +import io.metersphere.service.TestResourcePoolService; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.w3c.dom.Document; @@ -587,6 +589,11 @@ public class JmeterDocumentParser implements DocumentParser { } private void processBackendListener(Element backendListener) { + String resourcePoolId = context.getResourcePoolId(); + TestResourcePool resourcePool = CommonBeanFactory.getBean(TestResourcePoolService.class).getResourcePool(resourcePoolId); + if (!BooleanUtils.toBoolean(resourcePool.getBackendListener())) { + return; + } KafkaProperties kafkaProperties = CommonBeanFactory.getBean(KafkaProperties.class); Document document = backendListener.getOwnerDocument(); // 清空child @@ -647,6 +654,12 @@ public class JmeterDocumentParser implements DocumentParser { } private void processCheckoutBackendListener(Element element) { + String resourcePoolId = context.getResourcePoolId(); + TestResourcePool resourcePool = CommonBeanFactory.getBean(TestResourcePoolService.class).getResourcePool(resourcePoolId); + if (!BooleanUtils.toBoolean(resourcePool.getBackendListener())) { + return; + } + Document document = element.getOwnerDocument(); Node listenerParent = element.getNextSibling(); diff --git a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java index 2537df88ac..1dac9534dd 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -2,7 +2,6 @@ package io.metersphere.performance.service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.TypeReference; import io.metersphere.api.dto.JmxInfoDTO; import io.metersphere.api.dto.automation.ApiScenarioBatchRequest; import io.metersphere.api.dto.automation.ApiScenrioExportJmx; @@ -16,7 +15,6 @@ import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper; import io.metersphere.commons.constants.*; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.*; -import io.metersphere.config.JmeterProperties; import io.metersphere.config.KafkaProperties; import io.metersphere.controller.request.OrderRequest; import io.metersphere.controller.request.QueryScheduleRequest; @@ -30,7 +28,6 @@ import io.metersphere.log.utils.ReflexObjectUtil; import io.metersphere.log.vo.DetailColumn; import io.metersphere.log.vo.OperatingLogDetails; import io.metersphere.log.vo.performance.PerformanceReference; -import io.metersphere.performance.base.GranularityData; import io.metersphere.performance.dto.LoadTestExportJmx; import io.metersphere.performance.engine.Engine; import io.metersphere.performance.engine.EngineFactory; @@ -60,7 +57,6 @@ import java.nio.charset.StandardCharsets; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.*; -import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @Service @@ -356,11 +352,7 @@ public class PerformanceTestService { } // 启动测试 try { - engine.start(); - // 启动正常修改状态 starting - loadTest.setStatus(PerformanceTestStatus.Starting.name()); - loadTestMapper.updateByPrimaryKeySelective(loadTest); - // 启动正常插入 report + // 启动插入 report testReport.setLoadConfiguration(loadTest.getLoadConfiguration()); testReport.setAdvancedConfiguration(loadTest.getAdvancedConfiguration()); testReport.setStatus(PerformanceTestStatus.Starting.name()); @@ -369,6 +361,11 @@ public class PerformanceTestService { testReport.setTestName(loadTest.getName()); loadTestReportMapper.insertSelective(testReport); + engine.start(); + // 启动正常修改状态 starting + loadTest.setStatus(PerformanceTestStatus.Starting.name()); + loadTestMapper.updateByPrimaryKeySelective(loadTest); + LoadTestReportDetail reportDetail = new LoadTestReportDetail(); reportDetail.setContent(HEADERS); reportDetail.setReportId(testReport.getId()); @@ -788,42 +785,16 @@ public class PerformanceTestService { } public Integer getGranularity(String reportId) { - Integer granularity = CommonBeanFactory.getBean(JmeterProperties.class).getReport().getGranularity(); try { LoadTestReportWithBLOBs report = loadTestReportMapper.selectByPrimaryKey(reportId); LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(report.getTestId()); JSONObject advancedConfig = JSON.parseObject(loadTest.getAdvancedConfiguration()); if (advancedConfig.getInteger("granularity") != null) { - granularity = advancedConfig.getInteger("granularity"); - return granularity * 1000; // 单位是ms + return advancedConfig.getInteger("granularity") * 1000;// 单位是ms } - AtomicReference maxDuration = new AtomicReference<>(0); - List> pressureConfigLists = JSON.parseObject(loadTest.getLoadConfiguration(), new TypeReference>>() { - }); - // 按照最长的执行时间来确定 - pressureConfigLists.forEach(pcList -> { - - Optional maxOp = pcList.stream() - .filter(pressureConfig -> StringUtils.equalsAnyIgnoreCase(pressureConfig.getString("key"), "hold", "duration")) - .map(pressureConfig -> pressureConfig.getInteger("value")) - .max(Comparator.naturalOrder()); - Integer max = maxOp.orElse(0); - if (maxDuration.get() < max) { - maxDuration.set(max); - } - }); - Optional dataOptional = GranularityData.dataList.stream() - .filter(data -> maxDuration.get() >= data.getStart() && maxDuration.get() <= data.getEnd()) - .findFirst(); - - if (dataOptional.isPresent()) { - GranularityData.Data data = dataOptional.get(); - granularity = data.getGranularity(); - } - } catch (Exception e) { LogUtil.error(e); } - return granularity; + return -1; // 表示计算报告自己决定 } } diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index 5b06224daf..7acb44cc61 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit 5b06224daf6b4232613a96c58d03a7f6831f4789 +Subproject commit 7acb44cc610bbaf08b510c35849c04e4871e223a diff --git a/backend/src/main/resources/db/migration/V93__v1.12_release.sql b/backend/src/main/resources/db/migration/V93__v1.12_release.sql index fb9193720d..a767aff568 100644 --- a/backend/src/main/resources/db/migration/V93__v1.12_release.sql +++ b/backend/src/main/resources/db/migration/V93__v1.12_release.sql @@ -1,4 +1,3 @@ - -- 接口定义增加全局运行环境选择 CREATE TABLE IF NOT EXISTS `api_definition_env` ( `id` varchar(50) NOT NULL COMMENT 'ID', @@ -8,3 +7,19 @@ CREATE TABLE IF NOT EXISTS `api_definition_env` ( update_time bigint(13) null, PRIMARY KEY (`id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE utf8mb4_general_ci; + +-- load_test_report_result_part +CREATE TABLE `load_test_report_result_part` +( + `report_id` VARCHAR(50) NOT NULL, + `report_key` VARCHAR(64) NOT NULL, + `resource_index` INT NOT NULL, + `report_value` LONGTEXT, + PRIMARY KEY `load_test_report_result_report_id_report_key_index` (`report_id`, `report_key`, `resource_index`) +) + ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE utf8mb4_general_ci; + +ALTER TABLE test_resource_pool + ADD backend_listener TINYINT(1) DEFAULT 1; diff --git a/frontend/src/business/components/performance/report/components/LogDetails.vue b/frontend/src/business/components/performance/report/components/LogDetails.vue index 11634b48dc..3e49988119 100644 --- a/frontend/src/business/components/performance/report/components/LogDetails.vue +++ b/frontend/src/business/components/performance/report/components/LogDetails.vue @@ -146,7 +146,7 @@ export default { } .infinite-list { - height: calc(100vh - 390px); + height: calc(100vh - 295px); padding: 0; margin: 0; list-style: none; diff --git a/frontend/src/business/components/performance/report/components/RequestStatistics.vue b/frontend/src/business/components/performance/report/components/RequestStatistics.vue index a293a23df0..0c04b42756 100644 --- a/frontend/src/business/components/performance/report/components/RequestStatistics.vue +++ b/frontend/src/business/components/performance/report/components/RequestStatistics.vue @@ -4,6 +4,7 @@ :data="tableData" stripe border + height="calc(100vh - 235px)" style="width: 100%" > diff --git a/frontend/src/business/components/performance/report/components/TestDetails.vue b/frontend/src/business/components/performance/report/components/TestDetails.vue index 2de92763e5..de4a53f124 100644 --- a/frontend/src/business/components/performance/report/components/TestDetails.vue +++ b/frontend/src/business/components/performance/report/components/TestDetails.vue @@ -715,7 +715,7 @@ export default { } .test-detail { - height: calc(100vh - 345px); + height: calc(100vh - 285px); overflow: auto; } diff --git a/frontend/src/business/components/settings/system/TestResourcePool.vue b/frontend/src/business/components/settings/system/TestResourcePool.vue index 90ed59c536..59e751e52a 100644 --- a/frontend/src/business/components/settings/system/TestResourcePool.vue +++ b/frontend/src/business/components/settings/system/TestResourcePool.vue @@ -53,13 +53,13 @@
- + + + + @@ -161,33 +164,33 @@ + align="center" + prop="ip" + label="IP"> + align="center" + prop="port" + label="Port"> + align="center" + prop="monitorPort" + label="Monitor"> + align="center" + prop="maxConcurrency" + :label="$t('test_resource_pool.max_threads')">