fix(性能测试): 修复报告中的压力配置和高级配置显示错误的问题

This commit is contained in:
CaptainB 2021-11-23 19:23:37 +08:00 committed by 刘瑞斌
parent e16ea43d2b
commit eaf9b6ff30
9 changed files with 117 additions and 48 deletions

View File

@ -163,7 +163,7 @@ public class ShareController {
@GetMapping("/performance/report/get-jmx-content/{shareId}/{reportId}")
public LoadTestExportJmx getJmxContent(@PathVariable String shareId, @PathVariable String reportId) {
return performanceReportService.getJmxContent(reportId);
return performanceReportService.getJmxContent(reportId).get(0);
}
@GetMapping("/performance/get-jmx-content/{shareId}/{testId}")

View File

@ -149,10 +149,20 @@ public class PerformanceReportController {
}
@GetMapping("get-jmx-content/{reportId}")
public LoadTestExportJmx getJmxContent(@PathVariable String reportId) {
public List<LoadTestExportJmx> getJmxContent(@PathVariable String reportId) {
return performanceReportService.getJmxContent(reportId);
}
@GetMapping("/get-load-config/{reportId}")
public String getLoadConfiguration(@PathVariable String reportId) {
return performanceReportService.getLoadConfiguration(reportId);
}
@GetMapping("/get-advanced-config/{reportId}")
public String getAdvancedConfiguration(@PathVariable String reportId) {
return performanceReportService.getAdvancedConfiguration(reportId);
}
@PostMapping("rename")
@MsAuditLog(module = "performance_test_report", type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#request.id)", title = "#request.name", content = "#msClass.getLogDetails(#request.id)", msClass = PerformanceReportService.class)
public void renameReport(@RequestBody RenameReportRequest request) {

View File

@ -43,9 +43,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Service
@ -377,12 +375,13 @@ public class PerformanceReportService {
return "";
}
public LoadTestExportJmx getJmxContent(String reportId) {
public List<LoadTestExportJmx> getJmxContent(String reportId) {
LoadTestReportWithBLOBs loadTestReportWithBLOBs = loadTestReportMapper.selectByPrimaryKey(reportId);
if (loadTestReportWithBLOBs == null) {
return null;
return new ArrayList<>();
}
return new LoadTestExportJmx(loadTestReportWithBLOBs.getTestName(), loadTestReportWithBLOBs.getJmxContent());
LoadTestExportJmx loadTestExportJmx = new LoadTestExportJmx(loadTestReportWithBLOBs.getTestName(), loadTestReportWithBLOBs.getJmxContent());
return Collections.singletonList(loadTestExportJmx);
}
public void renameReport(RenameReportRequest request) {
@ -432,4 +431,20 @@ public class PerformanceReportService {
return new ArrayList<>();
}
}
public String getLoadConfiguration(String reportId) {
LoadTestReportWithBLOBs loadTestReportWithBLOBs = loadTestReportMapper.selectByPrimaryKey(reportId);
if (loadTestReportWithBLOBs == null) {
return null;
}
return loadTestReportWithBLOBs.getLoadConfiguration();
}
public String getAdvancedConfiguration(String reportId) {
LoadTestReportWithBLOBs loadTestReportWithBLOBs = loadTestReportMapper.selectByPrimaryKey(reportId);
if (loadTestReportWithBLOBs == null) {
return null;
}
return loadTestReportWithBLOBs.getAdvancedConfiguration();
}
}

View File

@ -1632,9 +1632,9 @@ public class TestPlanService {
String loadConfiguration = performanceTestService.getLoadConfiguration(item.getId());
response.setFixLoadConfiguration(loadConfiguration);
}
LoadTestExportJmx jmxContent = performanceReportService.getJmxContent(reportId);
if (jmxContent != null) {
response.setJmxContent(JSONObject.toJSONString(jmxContent));
List<LoadTestExportJmx> jmxContent = performanceReportService.getJmxContent(reportId);
if (!CollectionUtils.isEmpty(jmxContent)) {
response.setJmxContent(JSONObject.toJSONString(jmxContent.get(0)));
}
List<LoadTestExportJmx> fixJmxContent = performanceTestService.getJmxContent(item.getId());
response.setFixJmxContent(fixJmxContent);

View File

@ -101,7 +101,7 @@
<monitor-card :report="report"/>
</el-tab-pane>
<el-tab-pane :label="$t('测试配置')">
<ms-test-configuration :report="report" :test="test" :test-id="testId"/>
<ms-test-configuration :test="test" :report-id="reportId"/>
</el-tab-pane>
</el-tabs>
</div>

View File

@ -1,10 +1,10 @@
<template>
<el-tabs>
<el-tab-pane :label="$t('load_test.pressure_config')">
<performance-pressure-config :is-read-only="true" :test="test" :test-id="testId"/>
<performance-pressure-config :is-read-only="true" :test="test" :report-id="reportId"/>
</el-tab-pane>
<el-tab-pane :label="$t('load_test.advanced_config')">
<performance-advanced-config :is-read-only="true" :test-id="testId"/>
<performance-advanced-config :is-read-only="true" :report-id="reportId"/>
</el-tab-pane>
</el-tabs>
</template>
@ -18,9 +18,9 @@ export default {
name: "TestConfiguration",
components: {PerformanceBasicConfig, PerformancePressureConfig, PerformanceAdvancedConfig},
props: {
report: Object,
test: Object,
testId: String,
reportId: String,
}
};
</script>

View File

@ -422,6 +422,9 @@ export default {
},
props: {
testId: String,
reportId: {
type: String
},
isReadOnly: {
type: Boolean,
default() {
@ -432,6 +435,8 @@ export default {
mounted() {
if (this.testId) {
this.getAdvancedConfig();
} else if (this.reportId) {
this.getAdvancedConfig('report');
}
},
watch: {
@ -450,8 +455,12 @@ export default {
}
},
methods: {
getAdvancedConfig() {
this.$get('/performance/get-advanced-config/' + this.testId, (response) => {
getAdvancedConfig(type) {
let url = '/performance/get-advanced-config/' + this.testId;
if (type) {
url = '/performance/report/get-advanced-config/' + this.reportId;
}
this.$get(url, (response) => {
if (response.data) {
let data = JSON.parse(response.data);
this.timeout = data.timeout;

View File

@ -6,11 +6,11 @@
<el-form-item :label="$t('load_test.select_resource_pool')">
<el-select v-model="resourcePool" size="mini" @change="resourcePoolChange">
<el-option
v-for="item in resourcePools"
:key="item.id"
:label="item.name"
:disabled="!item.performance"
:value="item.id">
v-for="item in resourcePools"
:key="item.id"
:label="item.name"
:disabled="!item.performance"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
@ -80,10 +80,10 @@
<el-form-item :label="$t('load_test.on_sample_error')">
<el-select v-model="threadGroup.onSampleError" size="mini">
<el-option
v-for="item in onSampleErrors"
:key="item.value"
:label="item.label"
:value="item.value">
v-for="item in onSampleErrors"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
@ -221,10 +221,10 @@
<el-form-item :label="$t('load_test.specify_resource')">
<el-select v-model="threadGroup.resourceNodeIndex" size="mini">
<el-option
v-for="(node, index) in resourceNodes"
:key="node.ip"
:label="node.ip"
:value="index">
v-for="(node, index) in resourceNodes"
:key="node.ip"
:label="node.ip"
:value="index">
</el-option>
</el-select>
</el-form-item>
@ -289,7 +289,7 @@ const RATIOS = "ratios";
const hexToRgb = function (hex) {
return 'rgb(' + parseInt('0x' + hex.slice(1, 3)) + ',' + parseInt('0x' + hex.slice(3, 5))
+ ',' + parseInt('0x' + hex.slice(5, 7)) + ')';
+ ',' + parseInt('0x' + hex.slice(5, 7)) + ')';
};
export default {
@ -302,6 +302,9 @@ export default {
testId: {
type: String
},
reportId: {
type: String
},
isReadOnly: {
type: Boolean,
default() {
@ -346,6 +349,8 @@ export default {
mounted() {
if (this.testId) {
this.getJmxContent();
} else if (this.reportId) {
this.getJmxContent();
} else {
this.calculateTotalChart();
}
@ -369,6 +374,14 @@ export default {
}
this.getResourcePools();
},
reportId() {
if (this.reportId) {
this.getJmxContent();
} else {
this.calculateTotalChart();
}
this.getResourcePools();
},
},
methods: {
getResourcePools() {
@ -383,7 +396,17 @@ export default {
});
},
getLoadConfig() {
this.$get('/performance/get-load-config/' + this.testId, (response) => {
let url = '';
if (this.testId) {
url = '/performance/get-load-config/' + this.testId;
}
if (this.reportId) {
url = '/performance/report/get-load-config/' + this.reportId;
}
if (!url) {
return;
}
this.$get(url, (response) => {
if (response.data) {
let data = JSON.parse(response.data);
for (let i = 0; i < this.threadGroups.length; i++) {
@ -396,6 +419,10 @@ export default {
break;
}
}
//
if (this.reportId) {
j = i;
}
data[j].forEach(item => {
switch (item.key) {
@ -496,20 +523,28 @@ export default {
});
},
getJmxContent() {
let url = '';
if (this.testId) {
let threadGroups = [];
this.$get('/performance/get-jmx-content/' + this.testId, (response) => {
response.data.forEach(d => {
threadGroups = threadGroups.concat(findThreadGroup(d.jmx, d.name));
threadGroups.forEach(tg => {
tg.options = {};
});
});
this.threadGroups = threadGroups;
this.$emit('fileChange', threadGroups);
this.getLoadConfig();
});
url = '/performance/get-jmx-content/' + this.testId;
}
if (this.reportId) {
url = '/performance/report/get-jmx-content/' + this.reportId;
}
if (!url) {
return;
}
let threadGroups = [];
this.$get(url, (response) => {
response.data.forEach(d => {
threadGroups = threadGroups.concat(findThreadGroup(d.jmx, d.name));
threadGroups.forEach(tg => {
tg.options = {};
});
});
this.threadGroups = threadGroups;
this.$emit('fileChange', threadGroups);
this.getLoadConfig();
});
},
resourcePoolChange() {
let result = this.resourcePools.filter(p => p.id === this.resourcePool);
@ -588,8 +623,8 @@ export default {
let tg = handler.threadGroups[i];
if (tg.enabled === 'false' ||
tg.deleted === 'true' ||
tg.threadType === 'ITERATION') {
tg.deleted === 'true' ||
tg.threadType === 'ITERATION') {
continue;
}
if (this.getDuration(tg) < tg.rampUpTime) {
@ -704,7 +739,7 @@ export default {
}
if (!tg.threadNumber || !tg.duration
|| !tg.rampUpTime || !tg.step || !tg.iterateNum) {
|| !tg.rampUpTime || !tg.step || !tg.iterateNum) {
this.$warning(this.$t('load_test.pressure_config_params_is_empty'));
this.$emit('changeActive', '1');
return false;

View File

@ -74,7 +74,7 @@
:share-id="shareId"/>
</el-tab-pane>
<el-tab-pane :label="$t('测试配置')">
<ms-test-configuration :report="report" :test="test" :test-id="testId"/>
<ms-test-configuration :report-id="reportId"/>
</el-tab-pane>
</el-tabs>
</div>