From 231d9c4859472f20ca34f3549654f6d1161a6b9c Mon Sep 17 00:00:00 2001 From: metersphere-bot <78466014+metersphere-bot@users.noreply.github.com> Date: Wed, 27 Oct 2021 13:51:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=87=AA=E5=AE=9A=E4=B9=89=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=9B=BE=E8=A1=A8bug=20(#7187)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: 修复性能测试自定义监控显示图表bug --- .../service/MetricQueryService.java | 35 +++++--- .../report/components/MonitorCard.vue | 90 ++++++++++--------- 2 files changed, 73 insertions(+), 52 deletions(-) diff --git a/backend/src/main/java/io/metersphere/performance/service/MetricQueryService.java b/backend/src/main/java/io/metersphere/performance/service/MetricQueryService.java index 4f9dfc8735..7158e98e56 100644 --- a/backend/src/main/java/io/metersphere/performance/service/MetricQueryService.java +++ b/backend/src/main/java/io/metersphere/performance/service/MetricQueryService.java @@ -32,6 +32,7 @@ import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; import java.text.DecimalFormat; import java.util.*; +import java.util.stream.Collectors; @Service @Transactional(rollbackFor = Exception.class) @@ -216,17 +217,29 @@ public class MetricQueryService { private void getRequest(Monitor monitor, List list) { if (CollectionUtils.isNotEmpty(monitor.getMonitorConfig())) { - monitor.getMonitorConfig().forEach(c -> { - if (StringUtils.isBlank(c.getValue())) { - return; - } - MetricDataRequest request = new MetricDataRequest(); - String promQL = c.getValue(); - request.setPromQL(promQL); - request.setSeriesName(c.getName()); - request.setInstance(monitor.getIp() + ":" + monitor.getPort()); - list.add(request); - }); + List collect = monitor.getMonitorConfig().stream() + .filter(c -> StringUtils.isNotBlank(c.getValue())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(collect)) { + collect.forEach(c -> { + MetricDataRequest request = new MetricDataRequest(); + String promQL = c.getValue(); + request.setPromQL(promQL); + request.setSeriesName(c.getName()); + request.setInstance(monitor.getIp() + ":" + monitor.getPort()); + list.add(request); + }); + } else { + Map map = MetricQuery.getMetricQueryMap(); + Set set = map.keySet(); + set.forEach(s -> { + MetricDataRequest request = new MetricDataRequest(); + String promQL = map.get(s); + request.setPromQL(promQL); + request.setSeriesName(s); + request.setInstance(monitor.getIp() + ":" + monitor.getPort()); + list.add(request); + }); + } } else { Map map = MetricQuery.getMetricQueryMap(); Set set = map.keySet(); diff --git a/frontend/src/business/components/performance/report/components/MonitorCard.vue b/frontend/src/business/components/performance/report/components/MonitorCard.vue index 3bb4039ca0..5b35f10343 100644 --- a/frontend/src/business/components/performance/report/components/MonitorCard.vue +++ b/frontend/src/business/components/performance/report/components/MonitorCard.vue @@ -4,11 +4,11 @@
+ @change="getResource(currentInstance)"> + v-for="item in instances" + :key="item.ip+item.port" + :value="item.ip+':'+item.port"> {{ item.ip }} {{ item.name }} @@ -35,47 +35,47 @@ + :data="tableData" + stripe + border + style="width: 100%"> + prop="label" + label="Label" + sortable> @@ -173,20 +173,22 @@ export default { this.getResource(); }, methods: { - getResource() { + getResource(currentInstance) { // this.init = true; if (this.planReportTemplate) { this.instances = this.planReportTemplate.reportResource; - this.currentInstance = this.instances[0].ip + ":" + this.instances[0].port; + this.currentInstance = currentInstance || this.instances[0].ip + ":" + this.instances[0].port; this.data = this.planReportTemplate.metricData; this.totalOption = this.getOption(this.currentInstance); } else if (this.isShare) { getSharePerformanceMetricQueryResource(this.shareId, this.id).then(response => { this.instances = response.data.data; - if (!this.currentInstance) { - this.currentInstance = this.instances[0].ip + ":" + this.instances[0].port; - this.handleChecked(this.currentInstance); + if (currentInstance) { + this.currentInstance = currentInstance; + } else { + this.currentInstance = this.currentInstance || this.instances[0].ip + ":" + this.instances[0].port; } + this.handleChecked(this.currentInstance); getSharePerformanceMetricQuery(this.shareId, this.id).then(result => { if (result) { this.data = result.data.data; @@ -198,10 +200,12 @@ export default { } else { getPerformanceMetricQueryResource(this.id).then(response => { this.instances = response.data.data; - if (!this.currentInstance) { - this.currentInstance = this.instances[0].ip + ":" + this.instances[0].port; - this.handleChecked(this.currentInstance); + if (currentInstance) { + this.currentInstance = currentInstance; + } else { + this.currentInstance = this.currentInstance || this.instances[0].ip + ":" + this.instances[0].port; } + this.handleChecked(this.currentInstance); getPerformanceMetricQuery(this.id).then(result => { if (result) { this.data = result.data.data; @@ -219,10 +223,14 @@ export default { if (curr.monitorConfig) { this.checkList = []; this.checkOptions = curr.monitorConfig.filter(mc => mc.value && mc.name) - .map(mc => { - this.checkList.push(mc.name); - return {key: mc.name, label: mc.name,}; - }); + .map(mc => { + this.checkList.push(mc.name); + return {key: mc.name, label: mc.name,}; + }); + if (this.checkList.length === 0) { + this.checkList = checkList; + this.checkOptions = checkOptions; + } } else { this.checkOptions = checkOptions; this.checkList = checkList;