diff --git a/backend/src/main/java/io/metersphere/controller/PerformanceReportController.java b/backend/src/main/java/io/metersphere/controller/PerformanceReportController.java index 8ac311802d..9c6dde50fa 100644 --- a/backend/src/main/java/io/metersphere/controller/PerformanceReportController.java +++ b/backend/src/main/java/io/metersphere/controller/PerformanceReportController.java @@ -10,6 +10,7 @@ import io.metersphere.controller.request.ReportRequest; import io.metersphere.dto.ReportDTO; import io.metersphere.report.base.ChartsData; import io.metersphere.report.base.Errors; +import io.metersphere.report.base.ReportTimeInfo; import io.metersphere.report.base.TestOverview; import io.metersphere.report.dto.ErrorsTop5DTO; import io.metersphere.report.dto.RequestStatisticsDTO; @@ -77,6 +78,11 @@ public class PerformanceReportController { return reportService.getTestOverview(reportId); } + @GetMapping("/content/report_time/{reportId}") + public ReportTimeInfo getReportTimeInfo(@PathVariable String reportId) { + return reportService.getReportTimeInfo(reportId); + } + @GetMapping("/content/load_chart/{reportId}") public List getLoadChartData(@PathVariable String reportId) { return reportService.getLoadChartData(reportId); diff --git a/backend/src/main/java/io/metersphere/report/JtlResolver.java b/backend/src/main/java/io/metersphere/report/JtlResolver.java index 4ff52f0dd3..a26b8535e4 100644 --- a/backend/src/main/java/io/metersphere/report/JtlResolver.java +++ b/backend/src/main/java/io/metersphere/report/JtlResolver.java @@ -406,6 +406,28 @@ public class JtlResolver { return chartsDataList; } + public static ReportTimeInfo getReportTimeInfo(String jtlString) { + ReportTimeInfo reportTimeInfo = new ReportTimeInfo(); + List totalLineList = JtlResolver.resolver(jtlString); + + totalLineList.sort(Comparator.comparing(t0 -> Long.valueOf(t0.getTimestamp()))); + + String startTimeStamp = totalLineList.get(0).getTimestamp(); + String endTimeStamp = totalLineList.get(totalLineList.size()-1).getTimestamp(); + String startTime = stampToDate(startTimeStamp); + String endTime = stampToDate(endTimeStamp); + reportTimeInfo.setStartTime(startTime); + reportTimeInfo.setEndTime(endTime); + + Date startDate = new Date(Long.parseLong(startTimeStamp)); + Date endDate = new Date(Long.parseLong(endTimeStamp)); + long timestamp = endDate.getTime() - startDate.getTime(); + reportTimeInfo.setDuration(String.valueOf(timestamp*1.0 / 1000 / 60)); + + + return reportTimeInfo; + } + private static String stampToDate(String timeStamp) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); long lt = Long.parseLong(timeStamp); diff --git a/backend/src/main/java/io/metersphere/report/base/ReportTimeInfo.java b/backend/src/main/java/io/metersphere/report/base/ReportTimeInfo.java new file mode 100644 index 0000000000..ecb9e587af --- /dev/null +++ b/backend/src/main/java/io/metersphere/report/base/ReportTimeInfo.java @@ -0,0 +1,32 @@ +package io.metersphere.report.base; + +public class ReportTimeInfo { + + private String duration; + private String startTime; + private String endTime; + + public String getDuration() { + return duration; + } + + public void setDuration(String duration) { + this.duration = duration; + } + + public String getStartTime() { + return startTime; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + public String getEndTime() { + return endTime; + } + + public void setEndTime(String endTime) { + this.endTime = endTime; + } +} diff --git a/backend/src/main/java/io/metersphere/report/base/TestOverview.java b/backend/src/main/java/io/metersphere/report/base/TestOverview.java index 9ef2b2c3dc..d478761674 100644 --- a/backend/src/main/java/io/metersphere/report/base/TestOverview.java +++ b/backend/src/main/java/io/metersphere/report/base/TestOverview.java @@ -3,9 +3,9 @@ package io.metersphere.report.base; public class TestOverview { private String maxUsers; - private String avgThroughput; // Hits/s + private String avgThroughput; private String errors; - private String avgResponseTime; // s + private String avgResponseTime; private String responseTime90; private String avgBandwidth; diff --git a/backend/src/main/java/io/metersphere/service/ReportService.java b/backend/src/main/java/io/metersphere/service/ReportService.java index 5ca591a00f..890bfc133c 100644 --- a/backend/src/main/java/io/metersphere/service/ReportService.java +++ b/backend/src/main/java/io/metersphere/service/ReportService.java @@ -12,6 +12,7 @@ import io.metersphere.dto.ReportDTO; import io.metersphere.report.JtlResolver; import io.metersphere.report.base.ChartsData; import io.metersphere.report.base.Errors; +import io.metersphere.report.base.ReportTimeInfo; import io.metersphere.report.base.TestOverview; import io.metersphere.report.dto.ErrorsTop5DTO; import io.metersphere.report.dto.RequestStatisticsDTO; @@ -84,6 +85,14 @@ public class ReportService { return testOverview; } + public ReportTimeInfo getReportTimeInfo(String id) { + checkReportStatus(id); + LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); + String content = loadTestReport.getContent(); + ReportTimeInfo reportTimeInfo = JtlResolver.getReportTimeInfo(content); + return reportTimeInfo; + } + public List getLoadChartData(String id) { checkReportStatus(id); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); diff --git a/frontend/src/business/components/performance/report/PerformanceReportView.vue b/frontend/src/business/components/performance/report/PerformanceReportView.vue index 00a4a4f7df..aed096cb2d 100644 --- a/frontend/src/business/components/performance/report/PerformanceReportView.vue +++ b/frontend/src/business/components/performance/report/PerformanceReportView.vue @@ -20,13 +20,13 @@ - 持续时间: 30 分钟 + 持续时间: {{duration}} 分钟 - 开始时间: 2020-3-10 12:00:00 + 开始时间: {{startTime}} - 结束时间: 2020-3-10 12:30:00 + 结束时间: {{endTime}} @@ -75,7 +75,10 @@ status: '', reportName: '', testName: '', - projectName: '' + projectName: '', + startTime: '0', + endTime: '0', + duration: '0' } }, methods: { @@ -90,6 +93,18 @@ } }) } + }, + initReportTimeInfo() { + if(this.reportId){ + this.result = this.$get("/performance/report/content/report_time/" + this.reportId, res => { + let data = res.data; + if(data){ + this.startTime = data.startTime; + this.endTime = data.endTime; + this.duration = data.duration; + } + }) + } } }, mounted() { @@ -110,6 +125,7 @@ } }) this.initBreadcrumb(); + this.initReportTimeInfo(); }, watch: { '$route'(to) { @@ -123,6 +139,14 @@ this.projectName = data.projectName; } }); + this.result = this.$get("/performance/report/content/report_time/" + this.reportId, res => { + let data = res.data; + if(data){ + this.startTime = data.startTime; + this.endTime = data.endTime; + this.duration = data.duration; + } + }) window.location.reload(); } } diff --git a/frontend/src/business/components/settings/system/SystemWorkspace.vue b/frontend/src/business/components/settings/system/SystemWorkspace.vue index eb269dbf12..a551043ccb 100644 --- a/frontend/src/business/components/settings/system/SystemWorkspace.vue +++ b/frontend/src/business/components/settings/system/SystemWorkspace.vue @@ -460,7 +460,6 @@ data() { return { result: {}, - loading: false, createVisible: false, updateVisible: false, memberVisible: false,