From 55d7a806fd3eb61a96c1e43010b3fea663eac292 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 24 Mar 2020 14:37:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E5=91=8A-=E8=AF=B7=E6=B1=82=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E8=A1=A8=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReportController.java | 6 ++ .../io/metersphere/report/JtlResolver.java | 13 ++-- .../io/metersphere/service/ReportService.java | 9 ++- .../src/test/java/io/metersphere/JtlTest.java | 4 +- .../report/PerformanceReportView.vue | 2 +- .../report/components/RequestStatistics.vue | 64 ++++++++++++------- 6 files changed, 66 insertions(+), 32 deletions(-) diff --git a/backend/src/main/java/io/metersphere/controller/ReportController.java b/backend/src/main/java/io/metersphere/controller/ReportController.java index 57fc4275e5..10f8cb563b 100644 --- a/backend/src/main/java/io/metersphere/controller/ReportController.java +++ b/backend/src/main/java/io/metersphere/controller/ReportController.java @@ -8,6 +8,7 @@ import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; import io.metersphere.controller.request.ReportRequest; import io.metersphere.dto.ReportDTO; +import io.metersphere.report.base.RequestStatistics; import io.metersphere.service.ReportService; import io.metersphere.user.SessionUtils; import org.apache.shiro.authz.annotation.Logical; @@ -52,5 +53,10 @@ public class ReportController { return reportService.getReportTestAndProInfo(reportId); } + @GetMapping("/content/{reportId}") + public List getReportContent(@PathVariable String reportId) { + return reportService.getReport(reportId); + } + } diff --git a/backend/src/main/java/io/metersphere/report/JtlResolver.java b/backend/src/main/java/io/metersphere/report/JtlResolver.java index e8e7fa5abb..05706d1588 100644 --- a/backend/src/main/java/io/metersphere/report/JtlResolver.java +++ b/backend/src/main/java/io/metersphere/report/JtlResolver.java @@ -9,12 +9,13 @@ import io.metersphere.report.base.RequestStatistics; import java.io.Reader; import java.io.StringReader; +import java.text.DecimalFormat; import java.util.*; import java.util.stream.Collectors; public class JtlResolver { - private List resolver(String jtlString) { + private static List resolver(String jtlString) { HeaderColumnNameMappingStrategy ms = new HeaderColumnNameMappingStrategy<>(); ms.setType(Metric.class); try (Reader reader = new StringReader(jtlString)) { @@ -32,7 +33,7 @@ public class JtlResolver { return null; } - private List getOneRpsResult(Map> map){ + private static List getOneRpsResult(Map> map){ List requestStatisticsList = new ArrayList<>(); Iterator>> iterator = map.entrySet().iterator(); while (iterator.hasNext()) { @@ -45,7 +46,7 @@ public class JtlResolver { int sumElapsed=0; Integer failSize = 0; Integer totalBytes = 0; - List elapsedList = new ArrayList(); + List elapsedList = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { try { @@ -84,7 +85,9 @@ public class JtlResolver { RequestStatistics requestStatistics = new RequestStatistics(); requestStatistics.setRequestLabel(label); requestStatistics.setSamples(index+""); - requestStatistics.setAverage(sumElapsed/index+""); + DecimalFormat df = new DecimalFormat("0.00"); + String s = df.format((float)sumElapsed/index); + requestStatistics.setAverage(s+""); /** * TP90的计算 * 1,把一段时间内全部的请求的响应时间,从小到大排序,获得序列A @@ -104,7 +107,7 @@ public class JtlResolver { return requestStatisticsList; } - public List getRequestStatistics(String jtlString) { + public static List getRequestStatistics(String jtlString) { List totalLines = resolver(jtlString); Map> map = totalLines.stream().collect(Collectors.groupingBy(Metric::getLabel)); return getOneRpsResult(map); diff --git a/backend/src/main/java/io/metersphere/service/ReportService.java b/backend/src/main/java/io/metersphere/service/ReportService.java index 1a2b984e7e..029f45e84e 100644 --- a/backend/src/main/java/io/metersphere/service/ReportService.java +++ b/backend/src/main/java/io/metersphere/service/ReportService.java @@ -6,6 +6,8 @@ import io.metersphere.base.mapper.LoadTestReportMapper; import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper; import io.metersphere.controller.request.ReportRequest; import io.metersphere.dto.ReportDTO; +import io.metersphere.report.JtlResolver; +import io.metersphere.report.base.RequestStatistics; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -42,7 +44,10 @@ public class ReportService { return extLoadTestReportMapper.getReportTestAndProInfo(reportId); } - public LoadTestReport getReport(String id) { - return loadTestReportMapper.selectByPrimaryKey(id); + public List getReport(String id) { + LoadTestReport loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); + String content = loadTestReport.getContent(); + List requestStatistics = JtlResolver.getRequestStatistics(content); + return requestStatistics; } } diff --git a/backend/src/test/java/io/metersphere/JtlTest.java b/backend/src/test/java/io/metersphere/JtlTest.java index 104280bf32..7d21dbea3a 100644 --- a/backend/src/test/java/io/metersphere/JtlTest.java +++ b/backend/src/test/java/io/metersphere/JtlTest.java @@ -199,6 +199,7 @@ public class JtlTest { "1584602504095,65,https://rddev2.fit2cloud.com/auth/realms/cmp/login-actions/authenticate?session_code=YWUneSay4qlQuHRZsD4kPaZDIIR50KJLaNpW7uhsD-Q&execution=c7620733-54ab-46b2-802b-66764e42682b&client_id=cmp-client&tab_id=S8xOQPgCmhQ,400,Bad Request,Thread Group 1-7,text,false,,4469,1745,3,3,https://rddev2.fit2cloud.com/auth/realms/cmp/login-actions/authenticate,65,0,4\n" + "1584602504200,12,https://rddev2.fit2cloud.com/dashboard/web-public/project/html/notification-menus.html?_t=1577351137654,200,OK,Thread Group 1-3,text,true,,1570,582,2,2,https://rddev2.fit2cloud.com/dashboard/web-public/project/html/notification-menus.html?_t=1577351137654,12,0,0\n"; List metrics = beanBuilderExample(jtlString); + // 根据label分组,label作为map的key Map> map = metrics.stream().collect(Collectors.groupingBy(Metric::getLabel)); getOneRpsResult(map); } @@ -215,7 +216,8 @@ public class JtlTest { int sumElapsed=0; Integer failSize = 0; Integer totalBytes = 0; - List elapsedList = new ArrayList(); + // 响应时间的列表排序之后 用于计算90%line、95%line、99line + List elapsedList = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { try { diff --git a/frontend/src/business/components/performance/report/PerformanceReportView.vue b/frontend/src/business/components/performance/report/PerformanceReportView.vue index 72c4c7b6b8..cdfbb3e034 100644 --- a/frontend/src/business/components/performance/report/PerformanceReportView.vue +++ b/frontend/src/business/components/performance/report/PerformanceReportView.vue @@ -38,7 +38,7 @@ - + diff --git a/frontend/src/business/components/performance/report/components/RequestStatistics.vue b/frontend/src/business/components/performance/report/components/RequestStatistics.vue index 55a26e0c58..c2c266d208 100644 --- a/frontend/src/business/components/performance/report/components/RequestStatistics.vue +++ b/frontend/src/business/components/performance/report/components/RequestStatistics.vue @@ -4,14 +4,14 @@ :data="tableData" border style="width: 100%" - :default-sort = "{prop: 'elementLabel'}" + :default-sort = "{prop: 'samples'}" > + width="450" + > + > + > + > + > + > + > + > + > + > @@ -83,11 +83,29 @@ name: "RequestStatistics", data() { return { - tableData: [{},{},{},{},{}] + tableData: [{},{},{},{},{}], } }, methods: { - + initTableData() { + this.$get("/report/content/" + this.id, res => { + this.tableData = res.data; + }) + } + }, + created() { + this.initTableData() + }, + props: ['id'], + watch: { + '$route'(to) { + let reportId = to.path.split('/')[4]; + if(reportId){ + this.$get("/report/content/" + reportId, res => { + this.tableData = res.data; + }) + } + } } }