diff --git a/backend/src/main/java/io/metersphere/base/domain/LoadTestReportLog.java b/backend/src/main/java/io/metersphere/base/domain/LoadTestReportLog.java index d0630f1710..5f49329f18 100644 --- a/backend/src/main/java/io/metersphere/base/domain/LoadTestReportLog.java +++ b/backend/src/main/java/io/metersphere/base/domain/LoadTestReportLog.java @@ -3,12 +3,24 @@ package io.metersphere.base.domain; import java.io.Serializable; public class LoadTestReportLog implements Serializable { + private Long id; + private String reportId; + private String resourceId; + private String content; private static final long serialVersionUID = 1L; + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + public String getReportId() { return reportId; } @@ -17,6 +29,14 @@ public class LoadTestReportLog implements Serializable { this.reportId = reportId == null ? null : reportId.trim(); } + public String getResourceId() { + return resourceId; + } + + public void setResourceId(String resourceId) { + this.resourceId = resourceId == null ? null : resourceId.trim(); + } + public String getContent() { return content; } diff --git a/backend/src/main/java/io/metersphere/base/domain/LoadTestReportLogExample.java b/backend/src/main/java/io/metersphere/base/domain/LoadTestReportLogExample.java index 214e151a65..7826fbfbbd 100644 --- a/backend/src/main/java/io/metersphere/base/domain/LoadTestReportLogExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/LoadTestReportLogExample.java @@ -104,6 +104,66 @@ public class LoadTestReportLogExample { criteria.add(new Criterion(condition, value1, value2)); } + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(Long value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(Long value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(Long value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(Long value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(Long value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(Long value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(Long value1, Long value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(Long value1, Long value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + public Criteria andReportIdIsNull() { addCriterion("report_id is null"); return (Criteria) this; @@ -173,6 +233,76 @@ public class LoadTestReportLogExample { addCriterion("report_id not between", value1, value2, "reportId"); return (Criteria) this; } + + public Criteria andResourceIdIsNull() { + addCriterion("resource_id is null"); + return (Criteria) this; + } + + public Criteria andResourceIdIsNotNull() { + addCriterion("resource_id is not null"); + return (Criteria) this; + } + + public Criteria andResourceIdEqualTo(String value) { + addCriterion("resource_id =", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdNotEqualTo(String value) { + addCriterion("resource_id <>", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdGreaterThan(String value) { + addCriterion("resource_id >", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdGreaterThanOrEqualTo(String value) { + addCriterion("resource_id >=", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdLessThan(String value) { + addCriterion("resource_id <", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdLessThanOrEqualTo(String value) { + addCriterion("resource_id <=", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdLike(String value) { + addCriterion("resource_id like", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdNotLike(String value) { + addCriterion("resource_id not like", value, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdIn(List values) { + addCriterion("resource_id in", values, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdNotIn(List values) { + addCriterion("resource_id not in", values, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdBetween(String value1, String value2) { + addCriterion("resource_id between", value1, value2, "resourceId"); + return (Criteria) this; + } + + public Criteria andResourceIdNotBetween(String value1, String value2) { + addCriterion("resource_id not between", value1, value2, "resourceId"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/metersphere/base/mapper/LoadTestReportLogMapper.java b/backend/src/main/java/io/metersphere/base/mapper/LoadTestReportLogMapper.java index 561053703c..d4cf9a43c2 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/LoadTestReportLogMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/LoadTestReportLogMapper.java @@ -11,7 +11,7 @@ public interface LoadTestReportLogMapper { int deleteByExample(LoadTestReportLogExample example); - int deleteByPrimaryKey(String reportId); + int deleteByPrimaryKey(Long id); int insert(LoadTestReportLog record); @@ -21,7 +21,7 @@ public interface LoadTestReportLogMapper { List selectByExample(LoadTestReportLogExample example); - LoadTestReportLog selectByPrimaryKey(String reportId); + LoadTestReportLog selectByPrimaryKey(Long id); int updateByExampleSelective(@Param("record") LoadTestReportLog record, @Param("example") LoadTestReportLogExample example); @@ -32,4 +32,6 @@ public interface LoadTestReportLogMapper { int updateByPrimaryKeySelective(LoadTestReportLog record); int updateByPrimaryKeyWithBLOBs(LoadTestReportLog record); + + int updateByPrimaryKey(LoadTestReportLog record); } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/LoadTestReportLogMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/LoadTestReportLogMapper.xml index 9d5c8caa2c..8e65669499 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/LoadTestReportLogMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/LoadTestReportLogMapper.xml @@ -2,7 +2,9 @@ - + + + @@ -66,7 +68,7 @@ - report_id + id, report_id, resource_id content @@ -101,17 +103,17 @@ order by ${orderByClause} - select , from load_test_report_log - where report_id = #{reportId,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} - + delete from load_test_report_log - where report_id = #{reportId,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} delete from load_test_report_log @@ -120,23 +122,37 @@ - insert into load_test_report_log (report_id, content) - values (#{reportId,jdbcType=VARCHAR}, #{content,jdbcType=LONGVARCHAR}) + insert into load_test_report_log (id, report_id, resource_id, + content) + values (#{id,jdbcType=BIGINT}, #{reportId,jdbcType=VARCHAR}, #{resourceId,jdbcType=VARCHAR}, + #{content,jdbcType=LONGVARCHAR}) insert into load_test_report_log + + id, + report_id, + + resource_id, + content, + + #{id,jdbcType=BIGINT}, + #{reportId,jdbcType=VARCHAR}, + + #{resourceId,jdbcType=VARCHAR}, + #{content,jdbcType=LONGVARCHAR}, @@ -151,9 +167,15 @@ update load_test_report_log + + id = #{record.id,jdbcType=BIGINT}, + report_id = #{record.reportId,jdbcType=VARCHAR}, + + resource_id = #{record.resourceId,jdbcType=VARCHAR}, + content = #{record.content,jdbcType=LONGVARCHAR}, @@ -164,7 +186,9 @@ update load_test_report_log - set report_id = #{record.reportId,jdbcType=VARCHAR}, + set id = #{record.id,jdbcType=BIGINT}, + report_id = #{record.reportId,jdbcType=VARCHAR}, + resource_id = #{record.resourceId,jdbcType=VARCHAR}, content = #{record.content,jdbcType=LONGVARCHAR} @@ -172,7 +196,9 @@ update load_test_report_log - set report_id = #{record.reportId,jdbcType=VARCHAR} + set id = #{record.id,jdbcType=BIGINT}, + report_id = #{record.reportId,jdbcType=VARCHAR}, + resource_id = #{record.resourceId,jdbcType=VARCHAR} @@ -180,15 +206,29 @@ update load_test_report_log + + report_id = #{reportId,jdbcType=VARCHAR}, + + + resource_id = #{resourceId,jdbcType=VARCHAR}, + content = #{content,jdbcType=LONGVARCHAR}, - where report_id = #{reportId,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} update load_test_report_log - set content = #{content,jdbcType=LONGVARCHAR} - where report_id = #{reportId,jdbcType=VARCHAR} + set report_id = #{reportId,jdbcType=VARCHAR}, + resource_id = #{resourceId,jdbcType=VARCHAR}, + content = #{content,jdbcType=LONGVARCHAR} + where id = #{id,jdbcType=BIGINT} + + + update load_test_report_log + set report_id = #{reportId,jdbcType=VARCHAR}, + resource_id = #{resourceId,jdbcType=VARCHAR} + where id = #{id,jdbcType=BIGINT} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/controller/PerformanceReportController.java b/backend/src/main/java/io/metersphere/controller/PerformanceReportController.java index 3f03a49108..1446640802 100644 --- a/backend/src/main/java/io/metersphere/controller/PerformanceReportController.java +++ b/backend/src/main/java/io/metersphere/controller/PerformanceReportController.java @@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; +import java.util.Map; @RestController @RequestMapping(value = "performance/report") @@ -95,4 +96,8 @@ public class PerformanceReportController { return reportService.getLoadTestReport(reportId); } + @GetMapping("log/{reportId}") + public Map stop(@PathVariable String reportId) { + return reportService.log(reportId); + } } diff --git a/backend/src/main/java/io/metersphere/controller/PerformanceTestController.java b/backend/src/main/java/io/metersphere/controller/PerformanceTestController.java index 60b8c2c59e..a046035ed0 100644 --- a/backend/src/main/java/io/metersphere/controller/PerformanceTestController.java +++ b/backend/src/main/java/io/metersphere/controller/PerformanceTestController.java @@ -21,7 +21,6 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.util.List; -import java.util.Map; @RestController @RequestMapping(value = "performance") @@ -89,11 +88,6 @@ public class PerformanceTestController { performanceTestService.run(request); } - @GetMapping("/log/{testId}") - public Map stop(@PathVariable String testId) { - return performanceTestService.log(testId); - } - @GetMapping("/file/metadata/{testId}") public List getFileMetadata(@PathVariable String testId) { return fileService.getFileMetadataByTestId(testId); diff --git a/backend/src/main/java/io/metersphere/engine/EngineFactory.java b/backend/src/main/java/io/metersphere/engine/EngineFactory.java index b7a7f589ae..909bc95809 100644 --- a/backend/src/main/java/io/metersphere/engine/EngineFactory.java +++ b/backend/src/main/java/io/metersphere/engine/EngineFactory.java @@ -56,7 +56,7 @@ public class EngineFactory { return null; } - public static EngineContext createContext(LoadTestWithBLOBs loadTest, long threadNum, long startTime, String reportId) throws Exception { + public static EngineContext createContext(LoadTestWithBLOBs loadTest, String resourceId, long threadNum, long startTime, String reportId) throws Exception { final List fileMetadataList = fileService.getFileMetadataByTestId(loadTest.getId()); if (org.springframework.util.CollectionUtils.isEmpty(fileMetadataList)) { MSException.throwException(Translator.get("run_load_test_file_not_found") + loadTest.getId()); @@ -84,6 +84,7 @@ public class EngineFactory { put("BOOTSTRAP_SERVERS", kafkaProperties.getBootstrapServers()); put("LOG_TOPIC", kafkaProperties.getLog().getTopic()); put("REPORT_ID", reportId); + put("RESOURCE_ID", resourceId); }}; engineContext.setEnv(env); diff --git a/backend/src/main/java/io/metersphere/engine/docker/DockerTestEngine.java b/backend/src/main/java/io/metersphere/engine/docker/DockerTestEngine.java index c21f0c4646..a998e6ffbd 100644 --- a/backend/src/main/java/io/metersphere/engine/docker/DockerTestEngine.java +++ b/backend/src/main/java/io/metersphere/engine/docker/DockerTestEngine.java @@ -62,7 +62,7 @@ public class DockerTestEngine extends AbstractEngine { // todo 运行测试 EngineContext context = null; try { - context = EngineFactory.createContext(loadTest, realThreadNum, this.getStartTime(), this.getReportId()); + context = EngineFactory.createContext(loadTest, resource.getId(), realThreadNum, this.getStartTime(), this.getReportId()); } catch (Exception e) { MSException.throwException(e); } diff --git a/backend/src/main/java/io/metersphere/engine/kubernetes/KubernetesTestEngine.java b/backend/src/main/java/io/metersphere/engine/kubernetes/KubernetesTestEngine.java index eec1302b09..d40840e9ba 100644 --- a/backend/src/main/java/io/metersphere/engine/kubernetes/KubernetesTestEngine.java +++ b/backend/src/main/java/io/metersphere/engine/kubernetes/KubernetesTestEngine.java @@ -48,7 +48,7 @@ public class KubernetesTestEngine extends AbstractEngine { MSException.throwException(Translator.get("max_thread_insufficient")); } try { - EngineContext context = EngineFactory.createContext(loadTest, threadNum, this.getStartTime(), this.getReportId()); + EngineContext context = EngineFactory.createContext(loadTest, r.getId(), threadNum, this.getStartTime(), this.getReportId()); runTest(context, clientCredential); } catch (Exception e) { MSException.throwException(e); @@ -90,6 +90,7 @@ public class KubernetesTestEngine extends AbstractEngine { jmeter.setSpec(new JmeterSpec() {{ setReplicas(1); setImage(JMETER_IMAGE); + setEnv(context.getEnv()); }}); LogUtil.info("Load test started. " + context.getTestId()); kubernetesProvider.applyCustomResource(jmeter); diff --git a/backend/src/main/java/io/metersphere/engine/kubernetes/crds/jmeter/JmeterSpec.java b/backend/src/main/java/io/metersphere/engine/kubernetes/crds/jmeter/JmeterSpec.java index d2baaac44d..9ed26694e0 100644 --- a/backend/src/main/java/io/metersphere/engine/kubernetes/crds/jmeter/JmeterSpec.java +++ b/backend/src/main/java/io/metersphere/engine/kubernetes/crds/jmeter/JmeterSpec.java @@ -4,11 +4,15 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import io.fabric8.kubernetes.api.model.KubernetesResource; +import java.util.HashMap; +import java.util.Map; + @JsonDeserialize @JsonInclude(JsonInclude.Include.NON_EMPTY) public class JmeterSpec implements KubernetesResource { private int replicas = 1; private String image; + private Map env = new HashMap<>(); public int getReplicas() { return replicas; @@ -25,4 +29,12 @@ public class JmeterSpec implements KubernetesResource { public void setImage(String image) { this.image = image; } + + public Map getEnv() { + return env; + } + + public void setEnv(Map env) { + this.env = env; + } } diff --git a/backend/src/main/java/io/metersphere/service/PerformanceTestService.java b/backend/src/main/java/io/metersphere/service/PerformanceTestService.java index ac7a2adf63..b248667db0 100644 --- a/backend/src/main/java/io/metersphere/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/service/PerformanceTestService.java @@ -22,7 +22,6 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; @@ -50,6 +49,8 @@ public class PerformanceTestService { private ExtLoadTestReportDetailMapper extLoadTestReportDetailMapper; @Resource private LoadTestReportLogMapper loadTestReportLogMapper; + @Resource + private TestResourceService testResourceService; public List list(QueryTestPlanRequest request) { return extLoadTestMapper.list(request); @@ -201,10 +202,15 @@ public class PerformanceTestService { // append \n extLoadTestReportDetailMapper.appendLine(testReport.getId(), "\n"); // 保存 load_test_report_log - LoadTestReportLog record = new LoadTestReportLog(); - record.setReportId(testReport.getId()); - record.setContent(StringUtils.EMPTY); - loadTestReportLogMapper.insert(record); + String resourcePoolId = loadTest.getTestResourcePoolId(); + List testResourceList = testResourceService.getResourcesByPoolId(resourcePoolId); + testResourceList.forEach(r -> { + LoadTestReportLog record = new LoadTestReportLog(); + record.setReportId(testReport.getId()); + record.setResourceId(r.getId()); + record.setContent(StringUtils.EMPTY); + loadTestReportLogMapper.insert(record); + }); } catch (MSException e) { LogUtil.error(e); loadTest.setStatus(PerformanceTestStatus.Error.name()); @@ -214,23 +220,6 @@ public class PerformanceTestService { } } - public Map log(String testId) { - final LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(testId); - if (loadTest == null) { - MSException.throwException(Translator.get("test_not_found") + testId); - } - - if (!StringUtils.equals(loadTest.getStatus(), PerformanceTestStatus.Running.name())) { - MSException.throwException(Translator.get("test_not_running")); - } - - Engine engine = EngineFactory.createEngine(loadTest); - if (engine == null) { - MSException.throwException(String.format("Engine is null,test ID:%s", testId)); - } - return engine.log(); - } - public List recentTestPlans(QueryTestPlanRequest request) { // 查询最近的测试计划 request.setRecent(true); diff --git a/backend/src/main/java/io/metersphere/service/ReportService.java b/backend/src/main/java/io/metersphere/service/ReportService.java index 23478b0e67..8b304d5457 100644 --- a/backend/src/main/java/io/metersphere/service/ReportService.java +++ b/backend/src/main/java/io/metersphere/service/ReportService.java @@ -21,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; +import java.util.Map; @Service @Transactional(rollbackFor = Exception.class) @@ -147,4 +148,9 @@ public class ReportService { public LoadTestReport getLoadTestReport(String id) { return extLoadTestReportMapper.selectByPrimaryKey(id); } + + public Map log(String reportId) { + // todo 查询日志 + return null; + } } diff --git a/backend/src/main/resources/db/migration/V2__metersphere_ddl.sql b/backend/src/main/resources/db/migration/V2__metersphere_ddl.sql index 45ae183514..c67f00b42c 100644 --- a/backend/src/main/resources/db/migration/V2__metersphere_ddl.sql +++ b/backend/src/main/resources/db/migration/V2__metersphere_ddl.sql @@ -83,9 +83,12 @@ CREATE TABLE IF NOT EXISTS `load_test_report_result` ( COLLATE=utf8mb4_bin; CREATE TABLE IF NOT EXISTS `load_test_report_log` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, `report_id` varchar(50) NOT NULL, + `resource_id` varchar(50) DEFAULT NULL, `content` longtext, - PRIMARY KEY (`report_id`) + PRIMARY KEY (`id`), + KEY `load_test_report_log_report_id_resource_name_index` (`report_id`,`resource_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 diff --git a/frontend/src/business/components/performance/report/PerformanceReportView.vue b/frontend/src/business/components/performance/report/PerformanceReportView.vue index b739fca73c..6cc11bb93d 100644 --- a/frontend/src/business/components/performance/report/PerformanceReportView.vue +++ b/frontend/src/business/components/performance/report/PerformanceReportView.vue @@ -49,13 +49,6 @@ - - - - {{item}} - - - @@ -88,8 +81,6 @@ minutes: '0', seconds: '0', title: 'Logging', - testLogging: null, - showTestLogging: false, } }, methods: { @@ -119,11 +110,6 @@ }) } }, - getLog(testId) { - this.result = this.$get('/performance/log/' + testId, response => { - this.testLogging = response.data; - }) - } }, mounted() { this.reportId = this.$route.path.split('/')[4]; @@ -139,8 +125,6 @@ this.$info("报告生成中...."); break; case 'Running': - this.showTestLogging = true; - this.getLog(data.testId); break; default: break; @@ -190,9 +174,4 @@ color: #5C7878; } - .logging-content { - white-space: pre-line; - height: calc(100vh - 450px); - overflow: auto; - } diff --git a/frontend/src/business/components/performance/report/components/LogDetails.vue b/frontend/src/business/components/performance/report/components/LogDetails.vue index 10c7200afd..6ac7f3fcaf 100644 --- a/frontend/src/business/components/performance/report/components/LogDetails.vue +++ b/frontend/src/business/components/performance/report/components/LogDetails.vue @@ -1,15 +1,39 @@