修复oom问题,查看报告获取日志改为滚动分页,不再一次获取
This commit is contained in:
parent
00c60388f1
commit
9a97f53ae4
|
@ -17,4 +17,6 @@ public interface ExtLoadTestReportMapper {
|
|||
LoadTestReport selectByPrimaryKey(String id);
|
||||
|
||||
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
|
||||
</select>
|
||||
|
||||
<select id="selectResourceId" resultType="string">
|
||||
SELECT resource_id
|
||||
FROM load_test_report_log
|
||||
WHERE report_id = #{reportId}
|
||||
GROUP BY resource_id
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -3,6 +3,7 @@ package io.metersphere.performance.controller;
|
|||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.base.domain.LoadTestReport;
|
||||
import io.metersphere.base.domain.LoadTestReportLog;
|
||||
import io.metersphere.commons.constants.RoleConstants;
|
||||
import io.metersphere.commons.utils.PageUtils;
|
||||
import io.metersphere.commons.utils.Pager;
|
||||
|
@ -19,9 +20,10 @@ import org.springframework.http.MediaType;
|
|||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "performance/report")
|
||||
public class PerformanceReportController {
|
||||
|
@ -99,9 +101,15 @@ public class PerformanceReportController {
|
|||
return reportService.getLoadTestReport(reportId);
|
||||
}
|
||||
|
||||
@GetMapping("log/{reportId}")
|
||||
public List<LogDetailDTO> logs(@PathVariable String reportId) {
|
||||
return reportService.logs(reportId);
|
||||
@GetMapping("log/resource/{reportId}")
|
||||
public List<LogDetailDTO> getResourceIds(@PathVariable String 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}")
|
||||
|
|
|
@ -23,11 +23,10 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
|
@ -159,21 +158,13 @@ public class ReportService {
|
|||
return extLoadTestReportMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public List<LogDetailDTO> logs(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));
|
||||
public List<LogDetailDTO> getReportLogResource(String reportId) {
|
||||
List<LogDetailDTO> result = new ArrayList<>();
|
||||
reportLogs.forEach((resourceId, resourceLogs) -> {
|
||||
List<String> resourceIds = extLoadTestReportMapper.selectResourceId(reportId);
|
||||
resourceIds.forEach(resourceId -> {
|
||||
LogDetailDTO detailDTO = new LogDetailDTO();
|
||||
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.setContent(content);
|
||||
if (testResource == null) {
|
||||
detailDTO.setResourceName(resourceId);
|
||||
result.add(detailDTO);
|
||||
|
@ -199,6 +190,12 @@ public class ReportService {
|
|||
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) {
|
||||
LoadTestReportLogExample example = new LoadTestReportLogExample();
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
<template>
|
||||
<div v-loading="result.loading">
|
||||
<el-tabs type="border-card" :stretch="true">
|
||||
<el-tab-pane v-for="item in logContent" :key="item.resourceId" :label="item.resourceName" class="logging-content">
|
||||
{{item.content}}...
|
||||
<el-tab-pane v-for="item in resource" :key="item.resourceId" :label="item.resourceName" class="logging-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-tab-pane>
|
||||
</el-tabs>
|
||||
|
@ -14,17 +16,40 @@
|
|||
name: "LogDetails",
|
||||
data() {
|
||||
return {
|
||||
logContent: null,
|
||||
resource: [],
|
||||
logContent: [],
|
||||
result: {},
|
||||
id: ''
|
||||
id: '',
|
||||
page: 1,
|
||||
pageCount: 1,
|
||||
loading: false,
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
disabled() {
|
||||
return this.loading || this.page > this.pageCount;
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
initTableData() {
|
||||
this.result = this.$get("/performance/report/log/" + this.id).then(res => {
|
||||
this.logContent = res.data.data;
|
||||
}).catch(() => {
|
||||
this.logContent = null;
|
||||
getResource() {
|
||||
this.result = this.$get("/performance/report/log/resource/" + this.id, data => {
|
||||
this.resource = data.data;
|
||||
})
|
||||
},
|
||||
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) {
|
||||
|
@ -57,9 +82,9 @@
|
|||
let status = val.status;
|
||||
this.id = val.id;
|
||||
if (status === "Completed") {
|
||||
this.initTableData();
|
||||
this.getResource();
|
||||
} else {
|
||||
this.logContent = null;
|
||||
this.resource = [];
|
||||
}
|
||||
},
|
||||
deep: true
|
||||
|
@ -75,4 +100,16 @@
|
|||
overflow: auto;
|
||||
}
|
||||
|
||||
.infinite-list {
|
||||
height: 500px;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
list-style: none;
|
||||
overflow: auto
|
||||
}
|
||||
|
||||
.infinite-list-item {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
|
Loading…
Reference in New Issue