Merge branch 'dev' of github.com:fit2cloudrd/metersphere-server into dev

This commit is contained in:
Captain.B 2020-04-09 16:25:50 +08:00
commit bccd0cc317
7 changed files with 99 additions and 7 deletions

View File

@ -10,6 +10,7 @@ import io.metersphere.controller.request.ReportRequest;
import io.metersphere.dto.ReportDTO; import io.metersphere.dto.ReportDTO;
import io.metersphere.report.base.ChartsData; import io.metersphere.report.base.ChartsData;
import io.metersphere.report.base.Errors; import io.metersphere.report.base.Errors;
import io.metersphere.report.base.ReportTimeInfo;
import io.metersphere.report.base.TestOverview; import io.metersphere.report.base.TestOverview;
import io.metersphere.report.dto.ErrorsTop5DTO; import io.metersphere.report.dto.ErrorsTop5DTO;
import io.metersphere.report.dto.RequestStatisticsDTO; import io.metersphere.report.dto.RequestStatisticsDTO;
@ -77,6 +78,11 @@ public class PerformanceReportController {
return reportService.getTestOverview(reportId); return reportService.getTestOverview(reportId);
} }
@GetMapping("/content/report_time/{reportId}")
public ReportTimeInfo getReportTimeInfo(@PathVariable String reportId) {
return reportService.getReportTimeInfo(reportId);
}
@GetMapping("/content/load_chart/{reportId}") @GetMapping("/content/load_chart/{reportId}")
public List<ChartsData> getLoadChartData(@PathVariable String reportId) { public List<ChartsData> getLoadChartData(@PathVariable String reportId) {
return reportService.getLoadChartData(reportId); return reportService.getLoadChartData(reportId);

View File

@ -406,6 +406,28 @@ public class JtlResolver {
return chartsDataList; return chartsDataList;
} }
public static ReportTimeInfo getReportTimeInfo(String jtlString) {
ReportTimeInfo reportTimeInfo = new ReportTimeInfo();
List<Metric> 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) { private static String stampToDate(String timeStamp) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long lt = Long.parseLong(timeStamp); long lt = Long.parseLong(timeStamp);

View File

@ -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;
}
}

View File

@ -3,9 +3,9 @@ package io.metersphere.report.base;
public class TestOverview { public class TestOverview {
private String maxUsers; private String maxUsers;
private String avgThroughput; // Hits/s private String avgThroughput;
private String errors; private String errors;
private String avgResponseTime; // s private String avgResponseTime;
private String responseTime90; private String responseTime90;
private String avgBandwidth; private String avgBandwidth;

View File

@ -12,6 +12,7 @@ import io.metersphere.dto.ReportDTO;
import io.metersphere.report.JtlResolver; import io.metersphere.report.JtlResolver;
import io.metersphere.report.base.ChartsData; import io.metersphere.report.base.ChartsData;
import io.metersphere.report.base.Errors; import io.metersphere.report.base.Errors;
import io.metersphere.report.base.ReportTimeInfo;
import io.metersphere.report.base.TestOverview; import io.metersphere.report.base.TestOverview;
import io.metersphere.report.dto.ErrorsTop5DTO; import io.metersphere.report.dto.ErrorsTop5DTO;
import io.metersphere.report.dto.RequestStatisticsDTO; import io.metersphere.report.dto.RequestStatisticsDTO;
@ -84,6 +85,14 @@ public class ReportService {
return testOverview; 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<ChartsData> getLoadChartData(String id) { public List<ChartsData> getLoadChartData(String id) {
checkReportStatus(id); checkReportStatus(id);
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id);

View File

@ -20,13 +20,13 @@
</el-col> </el-col>
<el-col :span="8"> <el-col :span="8">
<span class="ms-report-time-desc"> <span class="ms-report-time-desc">
持续时间 30 分钟 持续时间 {{duration}} 分钟
</span> </span>
<span class="ms-report-time-desc"> <span class="ms-report-time-desc">
开始时间 2020-3-10 12:00:00 开始时间 {{startTime}}
</span> </span>
<span class="ms-report-time-desc"> <span class="ms-report-time-desc">
结束时间 2020-3-10 12:30:00 结束时间 {{endTime}}
</span> </span>
</el-col> </el-col>
</el-row> </el-row>
@ -75,7 +75,10 @@
status: '', status: '',
reportName: '', reportName: '',
testName: '', testName: '',
projectName: '' projectName: '',
startTime: '0',
endTime: '0',
duration: '0'
} }
}, },
methods: { 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() { mounted() {
@ -110,6 +125,7 @@
} }
}) })
this.initBreadcrumb(); this.initBreadcrumb();
this.initReportTimeInfo();
}, },
watch: { watch: {
'$route'(to) { '$route'(to) {
@ -123,6 +139,14 @@
this.projectName = data.projectName; 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(); window.location.reload();
} }
} }

View File

@ -460,7 +460,6 @@
data() { data() {
return { return {
result: {}, result: {},
loading: false,
createVisible: false, createVisible: false,
updateVisible: false, updateVisible: false,
memberVisible: false, memberVisible: false,