修复oom问题,查看报告获取日志改为滚动分页,不再一次获取
This commit is contained in:
parent
00c60388f1
commit
9a97f53ae4
|
@ -17,4 +17,6 @@ public interface ExtLoadTestReportMapper {
|
||||||
LoadTestReport selectByPrimaryKey(String id);
|
LoadTestReport selectByPrimaryKey(String id);
|
||||||
|
|
||||||
List<DashboardTestDTO> selectDashboardTests(@Param("workspaceId") String workspaceId, @Param("startTimestamp") long startTimestamp);
|
List<DashboardTestDTO> selectDashboardTests(@Param("workspaceId") String workspaceId, @Param("startTimestamp") long startTimestamp);
|
||||||
|
|
||||||
|
List<String> selectResourceId(@Param("reportId") String reportId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,4 +62,11 @@
|
||||||
GROUP BY x
|
GROUP BY x
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectResourceId" resultType="string">
|
||||||
|
SELECT resource_id
|
||||||
|
FROM load_test_report_log
|
||||||
|
WHERE report_id = #{reportId}
|
||||||
|
GROUP BY resource_id
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
|
@ -3,6 +3,7 @@ package io.metersphere.performance.controller;
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import io.metersphere.base.domain.LoadTestReport;
|
import io.metersphere.base.domain.LoadTestReport;
|
||||||
|
import io.metersphere.base.domain.LoadTestReportLog;
|
||||||
import io.metersphere.commons.constants.RoleConstants;
|
import io.metersphere.commons.constants.RoleConstants;
|
||||||
import io.metersphere.commons.utils.PageUtils;
|
import io.metersphere.commons.utils.PageUtils;
|
||||||
import io.metersphere.commons.utils.Pager;
|
import io.metersphere.commons.utils.Pager;
|
||||||
|
@ -19,9 +20,10 @@ import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value = "performance/report")
|
@RequestMapping(value = "performance/report")
|
||||||
public class PerformanceReportController {
|
public class PerformanceReportController {
|
||||||
|
@ -99,9 +101,15 @@ public class PerformanceReportController {
|
||||||
return reportService.getLoadTestReport(reportId);
|
return reportService.getLoadTestReport(reportId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("log/{reportId}")
|
@GetMapping("log/resource/{reportId}")
|
||||||
public List<LogDetailDTO> logs(@PathVariable String reportId) {
|
public List<LogDetailDTO> getResourceIds(@PathVariable String reportId) {
|
||||||
return reportService.logs(reportId);
|
return reportService.getReportLogResource(reportId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("log/{reportId}/{resourceId}/{goPage}")
|
||||||
|
public Pager<List<LoadTestReportLog>> logs(@PathVariable String reportId, @PathVariable String resourceId, @PathVariable int goPage) {
|
||||||
|
Page<Object> page = PageHelper.startPage(goPage, 10, true);
|
||||||
|
return PageUtils.setPageInfo(page, reportService.getReportLogs(reportId, resourceId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("log/download/{reportId}/{resourceId}")
|
@GetMapping("log/download/{reportId}/{resourceId}")
|
||||||
|
|
|
@ -23,11 +23,10 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@ -159,21 +158,13 @@ public class ReportService {
|
||||||
return extLoadTestReportMapper.selectByPrimaryKey(id);
|
return extLoadTestReportMapper.selectByPrimaryKey(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LogDetailDTO> logs(String reportId) {
|
public List<LogDetailDTO> getReportLogResource(String reportId) {
|
||||||
LoadTestReportLogExample example = new LoadTestReportLogExample();
|
|
||||||
example.createCriteria().andReportIdEqualTo(reportId);
|
|
||||||
example.setOrderByClause("part");
|
|
||||||
List<LoadTestReportLog> loadTestReportLogs = loadTestReportLogMapper.selectByExampleWithBLOBs(example);
|
|
||||||
Map<String, List<LoadTestReportLog>> reportLogs = loadTestReportLogs.stream().collect(Collectors.groupingBy(LoadTestReportLog::getResourceId));
|
|
||||||
List<LogDetailDTO> result = new ArrayList<>();
|
List<LogDetailDTO> result = new ArrayList<>();
|
||||||
reportLogs.forEach((resourceId, resourceLogs) -> {
|
List<String> resourceIds = extLoadTestReportMapper.selectResourceId(reportId);
|
||||||
|
resourceIds.forEach(resourceId -> {
|
||||||
LogDetailDTO detailDTO = new LogDetailDTO();
|
LogDetailDTO detailDTO = new LogDetailDTO();
|
||||||
TestResource testResource = testResourceService.getTestResource(resourceId);
|
TestResource testResource = testResourceService.getTestResource(resourceId);
|
||||||
String content = resourceLogs.stream().map(LoadTestReportLog::getContent).reduce("", (a, b) -> a + b);
|
|
||||||
// 显示前 2048
|
|
||||||
content = StringUtils.substring(content, 0, 2048);
|
|
||||||
detailDTO.setResourceId(resourceId);
|
detailDTO.setResourceId(resourceId);
|
||||||
detailDTO.setContent(content);
|
|
||||||
if (testResource == null) {
|
if (testResource == null) {
|
||||||
detailDTO.setResourceName(resourceId);
|
detailDTO.setResourceName(resourceId);
|
||||||
result.add(detailDTO);
|
result.add(detailDTO);
|
||||||
|
@ -199,6 +190,12 @@ public class ReportService {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<LoadTestReportLog> getReportLogs(String reportId, String resourceId) {
|
||||||
|
LoadTestReportLogExample example = new LoadTestReportLogExample();
|
||||||
|
example.createCriteria().andReportIdEqualTo(reportId).andResourceIdEqualTo(resourceId);
|
||||||
|
example.setOrderByClause("part desc");
|
||||||
|
return loadTestReportLogMapper.selectByExampleWithBLOBs(example);
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] downloadLog(String reportId, String resourceId) {
|
public byte[] downloadLog(String reportId, String resourceId) {
|
||||||
LoadTestReportLogExample example = new LoadTestReportLogExample();
|
LoadTestReportLogExample example = new LoadTestReportLogExample();
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
<template>
|
<template>
|
||||||
<div v-loading="result.loading">
|
<div v-loading="result.loading">
|
||||||
<el-tabs type="border-card" :stretch="true">
|
<el-tabs type="border-card" :stretch="true">
|
||||||
<el-tab-pane v-for="item in logContent" :key="item.resourceId" :label="item.resourceName" class="logging-content">
|
<el-tab-pane v-for="item in resource" :key="item.resourceId" :label="item.resourceName" class="logging-content">
|
||||||
{{item.content}}...
|
<ul class="infinite-list" v-infinite-scroll="load(item.resourceId)" infinite-scroll-disabled="disabled">
|
||||||
|
<li class="infinite-list-item" v-for="log in logContent" :key="log.id">{{ log.content }}</li>
|
||||||
|
</ul>
|
||||||
<el-link type="primary" @click="downloadLogFile(item)">{{$t('load_test.download_log_file')}}</el-link>
|
<el-link type="primary" @click="downloadLogFile(item)">{{$t('load_test.download_log_file')}}</el-link>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
</el-tabs>
|
</el-tabs>
|
||||||
|
@ -14,17 +16,40 @@
|
||||||
name: "LogDetails",
|
name: "LogDetails",
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
logContent: null,
|
resource: [],
|
||||||
|
logContent: [],
|
||||||
result: {},
|
result: {},
|
||||||
id: ''
|
id: '',
|
||||||
|
page: 1,
|
||||||
|
pageCount: 1,
|
||||||
|
loading: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
disabled() {
|
||||||
|
return this.loading || this.page > this.pageCount;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
initTableData() {
|
getResource() {
|
||||||
this.result = this.$get("/performance/report/log/" + this.id).then(res => {
|
this.result = this.$get("/performance/report/log/resource/" + this.id, data => {
|
||||||
this.logContent = res.data.data;
|
this.resource = data.data;
|
||||||
}).catch(() => {
|
})
|
||||||
this.logContent = null;
|
},
|
||||||
|
load(resourceId) {
|
||||||
|
if (this.loading || this.page > this.pageCount) return;
|
||||||
|
this.loading = true;
|
||||||
|
let url = "/performance/report/log/" + this.id + "/" + resourceId + "/" + this.page;
|
||||||
|
this.$get(url, res => {
|
||||||
|
let data = res.data;
|
||||||
|
this.pageCount = data.pageCount;
|
||||||
|
data.listObject.forEach(log => {
|
||||||
|
this.logContent.push(log);
|
||||||
|
})
|
||||||
|
this.page++;
|
||||||
|
this.loading = false;
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
downloadLogFile(item) {
|
downloadLogFile(item) {
|
||||||
|
@ -53,16 +78,16 @@
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
report: {
|
report: {
|
||||||
handler(val){
|
handler(val) {
|
||||||
let status = val.status;
|
let status = val.status;
|
||||||
this.id = val.id;
|
this.id = val.id;
|
||||||
if (status === "Completed") {
|
if (status === "Completed") {
|
||||||
this.initTableData();
|
this.getResource();
|
||||||
} else {
|
} else {
|
||||||
this.logContent = null;
|
this.resource = [];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
deep:true
|
deep: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
props: ['report']
|
props: ['report']
|
||||||
|
@ -75,4 +100,16 @@
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.infinite-list {
|
||||||
|
height: 500px;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
list-style: none;
|
||||||
|
overflow: auto
|
||||||
|
}
|
||||||
|
|
||||||
|
.infinite-list-item {
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue