refactor(性能测试): 运行时默认监控资源池
This commit is contained in:
parent
cb652f431c
commit
847d7a57a5
|
@ -18,4 +18,9 @@ public class MetricQueryController {
|
|||
public List<MetricData> queryMetric(@PathVariable("id") String reportId) {
|
||||
return metricService.queryMetric(reportId);
|
||||
}
|
||||
|
||||
@GetMapping("/query/resource/{id}")
|
||||
public List<String> queryReportResource(@PathVariable("id") String reportId) {
|
||||
return metricService.queryReportResource(reportId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,17 +7,21 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import io.metersphere.base.domain.LoadTestReportWithBLOBs;
|
||||
import io.metersphere.base.domain.LoadTestWithBLOBs;
|
||||
import io.metersphere.base.domain.TestResource;
|
||||
import io.metersphere.base.mapper.LoadTestMapper;
|
||||
import io.metersphere.base.mapper.LoadTestReportMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.DateUtils;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.dto.NodeDTO;
|
||||
import io.metersphere.performance.base.ReportTimeInfo;
|
||||
import io.metersphere.performance.controller.request.MetricDataRequest;
|
||||
import io.metersphere.performance.controller.request.MetricQuery;
|
||||
import io.metersphere.performance.controller.request.MetricRequest;
|
||||
import io.metersphere.performance.dto.MetricData;
|
||||
import io.metersphere.performance.dto.Monitor;
|
||||
import io.metersphere.service.TestResourceService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -43,6 +47,10 @@ public class MetricQueryService {
|
|||
private LoadTestMapper loadTestMapper;
|
||||
@Resource
|
||||
private ReportService reportService;
|
||||
@Resource
|
||||
private ExtLoadTestReportMapper extLoadTestReportMapper;
|
||||
@Resource
|
||||
private TestResourceService testResourceService;
|
||||
|
||||
|
||||
public List<MetricData> queryMetricData(MetricRequest metricRequest) {
|
||||
|
@ -140,9 +148,22 @@ public class MetricQueryService {
|
|||
}
|
||||
|
||||
public List<MetricData> queryMetric(String reportId) {
|
||||
List<String> instances = new ArrayList<>();
|
||||
LoadTestReportWithBLOBs report = loadTestReportMapper.selectByPrimaryKey(reportId);
|
||||
String testId = report.getTestId();
|
||||
LoadTestWithBLOBs loadTestWithBLOBs = loadTestMapper.selectByPrimaryKey(testId);
|
||||
String poolId = loadTestWithBLOBs.getTestResourcePoolId();
|
||||
List<TestResource> resourceList = testResourceService.getTestResourceList(poolId);
|
||||
// 默认监控资源池下的节点
|
||||
if (CollectionUtils.isNotEmpty(resourceList)) {
|
||||
resourceList.forEach(resource -> {
|
||||
NodeDTO dto = JSON.parseObject(resource.getConfiguration(), NodeDTO.class);
|
||||
if (StringUtils.isNotBlank(dto.getIp())) {
|
||||
int port = dto.getMonitorPort() == null ? 9100 : dto.getMonitorPort();
|
||||
instances.add(dto.getIp() + ":" + port);
|
||||
}
|
||||
});
|
||||
}
|
||||
String advancedConfiguration = loadTestWithBLOBs.getAdvancedConfiguration();
|
||||
JSONObject jsonObject = JSON.parseObject(advancedConfiguration);
|
||||
JSONArray monitorParams = jsonObject.getJSONArray("monitorParams");
|
||||
|
@ -150,12 +171,19 @@ public class MetricQueryService {
|
|||
return new ArrayList<>();
|
||||
}
|
||||
List<MetricDataRequest> list = new ArrayList<>();
|
||||
// 加入高级设置中的监控配置
|
||||
for (int i = 0; i < monitorParams.size(); i++) {
|
||||
Monitor monitor = monitorParams.getObject(i, Monitor.class);
|
||||
String instance = monitor.getIp() + ":" + monitor.getPort();
|
||||
getRequest(instance, list);
|
||||
if (!instances.contains(instance)) {
|
||||
instances.add(instance);
|
||||
}
|
||||
}
|
||||
|
||||
instances.forEach(instance -> {
|
||||
getRequest(instance, list);
|
||||
});
|
||||
|
||||
ReportTimeInfo reportTimeInfo = reportService.getReportTimeInfo(reportId);
|
||||
MetricRequest metricRequest = new MetricRequest();
|
||||
metricRequest.setMetricDataQueries(list);
|
||||
|
@ -185,4 +213,47 @@ public class MetricQueryService {
|
|||
list.add(request);
|
||||
});
|
||||
}
|
||||
|
||||
public List<String> queryReportResource(String reportId) {
|
||||
List<String> result = new ArrayList<>();
|
||||
List<String> resourceIdAndIndexes = extLoadTestReportMapper.selectResourceId(reportId);
|
||||
resourceIdAndIndexes.forEach(resourceIdAndIndex -> {
|
||||
String[] split = org.apache.commons.lang3.StringUtils.split(resourceIdAndIndex, "_");
|
||||
String resourceId = split[0];
|
||||
TestResource testResource = testResourceService.getTestResource(resourceId);
|
||||
if (testResource == null) {
|
||||
return;
|
||||
}
|
||||
String configuration = testResource.getConfiguration();
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(configuration)) {
|
||||
return;
|
||||
}
|
||||
NodeDTO dto = JSON.parseObject(configuration, NodeDTO.class);
|
||||
if (StringUtils.isNotBlank(dto.getIp())) {
|
||||
Integer monitorPort = dto.getMonitorPort();
|
||||
int port = monitorPort == null ? 9100 : monitorPort;
|
||||
result.add(dto.getIp() + ":" + port);
|
||||
}
|
||||
});
|
||||
|
||||
LoadTestReportWithBLOBs report = loadTestReportMapper.selectByPrimaryKey(reportId);
|
||||
String testId = report.getTestId();
|
||||
LoadTestWithBLOBs loadTestWithBLOBs = loadTestMapper.selectByPrimaryKey(testId);
|
||||
String advancedConfiguration = loadTestWithBLOBs.getAdvancedConfiguration();
|
||||
JSONObject jsonObject = JSON.parseObject(advancedConfiguration);
|
||||
JSONArray monitorParams = jsonObject.getJSONArray("monitorParams");
|
||||
if (monitorParams == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
for (int i = 0; i < monitorParams.size(); i++) {
|
||||
Monitor monitor = monitorParams.getObject(i, Monitor.class);
|
||||
String instance = monitor.getIp() + ":" + monitor.getPort();
|
||||
if (!result.contains(instance)) {
|
||||
result.add(instance);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package io.metersphere.performance.service;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.*;
|
||||
import io.metersphere.base.mapper.ext.ExtLoadTestMapper;
|
||||
|
@ -19,13 +17,10 @@ import io.metersphere.controller.request.QueryScheduleRequest;
|
|||
import io.metersphere.controller.request.ScheduleRequest;
|
||||
import io.metersphere.dto.DashboardTestDTO;
|
||||
import io.metersphere.dto.LoadTestDTO;
|
||||
import io.metersphere.dto.NodeDTO;
|
||||
import io.metersphere.dto.ScheduleDao;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.job.sechedule.PerformanceTestJob;
|
||||
import io.metersphere.performance.base.MonitorStatus;
|
||||
import io.metersphere.performance.dto.LoadTestExportJmx;
|
||||
import io.metersphere.performance.dto.Monitor;
|
||||
import io.metersphere.performance.engine.Engine;
|
||||
import io.metersphere.performance.engine.EngineFactory;
|
||||
import io.metersphere.performance.engine.producer.LoadTestProducer;
|
||||
|
@ -49,7 +44,6 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
|
@ -87,8 +81,6 @@ public class PerformanceTestService {
|
|||
private TestResourcePoolMapper testResourcePoolMapper;
|
||||
@Resource
|
||||
private LoadTestProducer loadTestProducer;
|
||||
@Resource
|
||||
private TestResourceMapper testResourceMapper;
|
||||
|
||||
public List<LoadTestDTO> list(QueryTestPlanRequest request) {
|
||||
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
|
||||
|
@ -212,36 +204,6 @@ public class PerformanceTestService {
|
|||
}
|
||||
|
||||
final LoadTestWithBLOBs loadTest = new LoadTestWithBLOBs();
|
||||
|
||||
String poolId = request.getTestResourcePoolId();
|
||||
TestResourceExample testResourceExample = new TestResourceExample();
|
||||
testResourceExample.createCriteria().andTestResourcePoolIdEqualTo(poolId);
|
||||
List<TestResource> testResources = testResourceMapper.selectByExampleWithBLOBs(testResourceExample);
|
||||
String advancedConfiguration = request.getAdvancedConfiguration();
|
||||
JSONObject jsonObject = JSON.parseObject(advancedConfiguration);
|
||||
List<Monitor> list = new ArrayList<>();
|
||||
|
||||
if (!CollectionUtils.isEmpty(testResources)) {
|
||||
AtomicInteger index = new AtomicInteger(1);
|
||||
testResources.forEach(testResource -> {
|
||||
String configuration = testResource.getConfiguration();
|
||||
NodeDTO nodeDTO = JSON.parseObject(configuration, NodeDTO.class);
|
||||
Monitor monitor = new Monitor();
|
||||
monitor.setName("名称" + index.getAndIncrement());
|
||||
monitor.setDescription("默认生成");
|
||||
monitor.setIp(nodeDTO.getIp());
|
||||
monitor.setPort(9100);
|
||||
monitor.setMonitorStatus(MonitorStatus.NORMAL.name());
|
||||
list.add(monitor);
|
||||
});
|
||||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
jsonObject.put("monitorParams", list);
|
||||
}
|
||||
|
||||
advancedConfiguration = JSON.toJSONString(jsonObject);
|
||||
|
||||
loadTest.setUserId(SessionUtils.getUser().getId());
|
||||
loadTest.setId(UUID.randomUUID().toString());
|
||||
loadTest.setName(request.getName());
|
||||
|
@ -250,7 +212,7 @@ public class PerformanceTestService {
|
|||
loadTest.setUpdateTime(System.currentTimeMillis());
|
||||
loadTest.setTestResourcePoolId(request.getTestResourcePoolId());
|
||||
loadTest.setLoadConfiguration(request.getLoadConfiguration());
|
||||
loadTest.setAdvancedConfiguration(advancedConfiguration);
|
||||
loadTest.setAdvancedConfiguration(request.getAdvancedConfiguration());
|
||||
loadTest.setStatus(PerformanceTestStatus.Saved.name());
|
||||
loadTest.setNum(getNextNum(request.getProjectId()));
|
||||
loadTestMapper.insert(loadTest);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<div v-loading="result.loading">
|
||||
<el-tabs type="border-card" :stretch="true">
|
||||
<el-tab-pane v-for="item in instances" :key="item" :label="item" class="logging-content">
|
||||
<el-tab-pane v-for="(item,index) in instances" :key="index" :label="item" class="logging-content">
|
||||
<el-row>
|
||||
<el-col :span="10" :offset="2">
|
||||
<ms-chart ref="chart1" :options="getCpuOption(item)" :autoresize="true"></ms-chart>
|
||||
|
@ -38,8 +38,6 @@ export default {
|
|||
components: {MsChart},
|
||||
data() {
|
||||
return {
|
||||
resource: [],
|
||||
logContent: [],
|
||||
result: {},
|
||||
id: '',
|
||||
loading: false,
|
||||
|
@ -47,15 +45,19 @@ export default {
|
|||
data: []
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.data = [];
|
||||
this.instances = [];
|
||||
},
|
||||
methods: {
|
||||
getResource() {
|
||||
this.result = this.$get("/metric/query/resource/" + this.report.id, data => {
|
||||
this.instances = data.data;
|
||||
})
|
||||
|
||||
this.$get("/metric/query/" + this.report.id, result => {
|
||||
if (result) {
|
||||
let data = result.data;
|
||||
this.data = data;
|
||||
let set = new Set()
|
||||
data.map(d => set.add(d.instance));
|
||||
this.instances = Array.from(set);
|
||||
this.data = result.data;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -241,7 +243,7 @@ export default {
|
|||
if (status === "Completed" || status === "Running") {
|
||||
this.getResource();
|
||||
} else {
|
||||
this.resource = [];
|
||||
this.instances = [];
|
||||
}
|
||||
},
|
||||
deep: true
|
||||
|
|
|
@ -12,16 +12,6 @@
|
|||
<el-form-item :label="$t('commons.name')" prop="name">
|
||||
<el-input v-model="form.name" autocomplete="off"/>
|
||||
</el-form-item>
|
||||
<el-form-item label="所属环境">
|
||||
<el-select v-model="form.environmentId" placeholder="选择所属环境" @change="change">
|
||||
<el-option
|
||||
v-for="item in environments"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<h4 style="margin-left: 80px;">监控配置</h4>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
|
@ -74,12 +64,6 @@ export default {
|
|||
dialogVisible: false,
|
||||
rule: {},
|
||||
index: '',
|
||||
monitorList: [
|
||||
{
|
||||
indicator: '',
|
||||
expression: '',
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -112,8 +96,6 @@ export default {
|
|||
create() {
|
||||
this.$refs.monitorForm.validate(valid => {
|
||||
if (valid) {
|
||||
this.form.loadTestId = this.testId;
|
||||
this.form.authStatus = CONFIG_TYPE.NOT;
|
||||
this.form.monitorStatus = CONFIG_TYPE.NOT;
|
||||
this.list.push(this.form);
|
||||
this.$emit("update:list", this.list);
|
||||
|
@ -123,10 +105,6 @@ export default {
|
|||
})
|
||||
this.dialogVisible = false;
|
||||
},
|
||||
change(data) {
|
||||
let env = this.environments.find(env => env.id === data);
|
||||
this.form.environmentName = env ? env.name : "";
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -163,11 +163,11 @@
|
|||
prop="name"
|
||||
label="名称">
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
align="center"
|
||||
prop="environmentName"
|
||||
label="所属环境">
|
||||
</el-table-column>
|
||||
<!-- <el-table-column-->
|
||||
<!-- align="center"-->
|
||||
<!-- prop="environmentName"-->
|
||||
<!-- label="所属环境">-->
|
||||
<!-- </el-table-column>-->
|
||||
<!-- <el-table-column-->
|
||||
<!-- align="center"-->
|
||||
<!-- prop="authStatus"-->
|
||||
|
@ -242,7 +242,6 @@ export default {
|
|||
if (this.testId) {
|
||||
this.getAdvancedConfig();
|
||||
}
|
||||
this.getEnv();
|
||||
},
|
||||
computed: {
|
||||
envName(id) {
|
||||
|
@ -372,14 +371,6 @@ export default {
|
|||
refreshStatus() {
|
||||
|
||||
},
|
||||
getEnv() {
|
||||
let projectId = this.$store.state.projectId;
|
||||
this.result = this.$get('/api/environment/list/' + projectId, response => {
|
||||
if (response) {
|
||||
this.environments = response.data;
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue