diff --git a/backend/src/main/java/io/metersphere/controller/PerformanceReportController.java b/backend/src/main/java/io/metersphere/controller/PerformanceReportController.java index a45ee9fbc3..2976f36438 100644 --- a/backend/src/main/java/io/metersphere/controller/PerformanceReportController.java +++ b/backend/src/main/java/io/metersphere/controller/PerformanceReportController.java @@ -65,7 +65,7 @@ public class PerformanceReportController { } @GetMapping("/content/errors_top5/{reportId}") - public ErrorsTop5DTO getReportErrorsTop5(@PathVariable String reportId) { + public List getReportErrorsTop5(@PathVariable String reportId) { return reportService.getReportErrorsTOP5(reportId); } diff --git a/backend/src/main/java/io/metersphere/report/GenerateReport.java b/backend/src/main/java/io/metersphere/report/GenerateReport.java index 325e10a556..116e48afdb 100644 --- a/backend/src/main/java/io/metersphere/report/GenerateReport.java +++ b/backend/src/main/java/io/metersphere/report/GenerateReport.java @@ -7,7 +7,9 @@ import io.metersphere.report.base.*; import io.metersphere.report.dto.ErrorsTop5DTO; import io.metersphere.report.parse.ResultDataParse; import org.apache.commons.lang3.StringUtils; +import org.apache.jmeter.report.processor.ErrorsSummaryConsumer; import org.apache.jmeter.report.processor.StatisticsSummaryConsumer; +import org.apache.jmeter.report.processor.Top5ErrorsBySamplerConsumer; import org.apache.jmeter.report.processor.graph.impl.ActiveThreadsGraphConsumer; import org.apache.jmeter.report.processor.graph.impl.HitsPerSecondGraphConsumer; import org.apache.jmeter.report.processor.graph.impl.ResponseTimeOverTimeGraphConsumer; @@ -47,104 +49,25 @@ public class GenerateReport { return null; } - public static List getErrorsList(String jtlString) { - List totalMetricList = resolver(jtlString); - List errorsList = new ArrayList<>(); - DecimalFormat decimalFormat = new DecimalFormat("0.00"); + Map statisticsDataMap = ResultDataParse.getSummryDataMap(jtlString, new ErrorsSummaryConsumer()); + return ResultDataParse.summaryMapParsing(statisticsDataMap, Errors.class); + } - List falseList = new ArrayList<>(); - for (Metric metric : totalMetricList) { - if (StringUtils.equals("false", metric.getSuccess())) { - falseList.add(metric); - } - } - - Map> jtlMap = falseList.stream().collect(Collectors.groupingBy(GenerateReport::getResponseCodeAndFailureMessage)); - - for (Map.Entry> next : jtlMap.entrySet()) { - String key = next.getKey(); - List metricList = next.getValue(); - Errors errors = new Errors(); - errors.setErrorType(key); - errors.setErrorNumber(String.valueOf(metricList.size())); - int errorSize = metricList.size(); - int errorAllSize = falseList.size(); - int allSamples = totalMetricList.size(); - errors.setPrecentOfErrors(decimalFormat.format((double) errorSize / errorAllSize * 100) + "%"); - errors.setPrecentOfAllSamples(decimalFormat.format((double) errorSize / allSamples * 100) + "%"); - errorsList.add(errors); - } - - return errorsList; + public static List getErrorsTop5List(String jtlString) { + Map statisticsDataMap = ResultDataParse.getSummryDataMap(jtlString, new Top5ErrorsBySamplerConsumer()); + return ResultDataParse.summaryMapParsing(statisticsDataMap, ErrorsTop5.class); } public static List getRequestStatistics(String jtlString) { Map statisticsDataMap = ResultDataParse.getSummryDataMap(jtlString, new StatisticsSummaryConsumer()); - return ResultDataParse.summaryMapParsing(statisticsDataMap); + return ResultDataParse.summaryMapParsing(statisticsDataMap, Statistics.class); } private static String getResponseCodeAndFailureMessage(Metric metric) { return metric.getResponseCode() + "/" + metric.getResponseMessage(); } - public static ErrorsTop5DTO getErrorsTop5DTO(String jtlString) { - List totalMetricList = resolver(jtlString); - ErrorsTop5DTO top5DTO = new ErrorsTop5DTO(); - List errorsTop5s = new ArrayList<>(); - - List falseList = Objects.requireNonNull(totalMetricList).stream() - .filter(metric -> StringUtils.equals("false", metric.getSuccess())) - .collect(Collectors.toList()); - - Map> collect = falseList.stream() - .collect(Collectors.groupingBy(GenerateReport::getResponseCodeAndFailureMessage)); - - for (Map.Entry> next : collect.entrySet()) { - String key = next.getKey(); - List metricList = next.getValue(); - List list = new ArrayList<>(); - for (Metric metric : totalMetricList) { - if (StringUtils.equals(metric.getLabel(), metricList.get(0).getLabel())) { - list.add(metric); - } - } - - ErrorsTop5 errorsTop5 = new ErrorsTop5(); - errorsTop5.setSamples(String.valueOf(list.size())); - errorsTop5.setSample(metricList.get(0).getLabel()); - errorsTop5.setErrors(String.valueOf(metricList.size())); - errorsTop5.setErrorsAllSize(metricList.size()); - errorsTop5.setError(key); - errorsTop5s.add(errorsTop5); - } - - errorsTop5s.sort((t0, t1) -> t1.getErrorsAllSize().compareTo(t0.getErrorsAllSize())); - - if (errorsTop5s.size() >= ERRORS_TOP_SIZE) { - errorsTop5s = errorsTop5s.subList(0, ERRORS_TOP_SIZE); - } - - top5DTO.setLabel("Total"); - top5DTO.setErrorsTop5List(errorsTop5s); - top5DTO.setTotalSamples(String.valueOf(totalMetricList.size())); - top5DTO.setTotalErrors(String.valueOf(falseList.size())); - int size = errorsTop5s.size(); - // Total行 信息 - top5DTO.setError1(size > 0 ? errorsTop5s.get(0).getError() : null); - top5DTO.setError1Size(size > 0 ? errorsTop5s.get(0).getErrors() : null); - top5DTO.setError2(size > 1 ? errorsTop5s.get(1).getError() : null); - top5DTO.setError2Size(size > 1 ? errorsTop5s.get(1).getErrors() : null); - top5DTO.setError3(size > 2 ? errorsTop5s.get(2).getError() : null); - top5DTO.setError3Size(size > 2 ? errorsTop5s.get(2).getErrors() : null); - top5DTO.setError4(size > 3 ? errorsTop5s.get(3).getError() : null); - top5DTO.setError4Size(size > 3 ? errorsTop5s.get(3).getErrors() : null); - top5DTO.setError5(size > 4 ? errorsTop5s.get(4).getError() : null); - top5DTO.setError5Size(size > 4 ? errorsTop5s.get(4).getErrors() : null); - - return top5DTO; - } - public static TestOverview getTestOverview(String jtlString) { TestOverview testOverview = new TestOverview(); DecimalFormat decimalFormat = new DecimalFormat("0.00"); diff --git a/backend/src/main/java/io/metersphere/report/base/ErrorsTop5.java b/backend/src/main/java/io/metersphere/report/base/ErrorsTop5.java index 311e1112fc..9e3ac456c5 100644 --- a/backend/src/main/java/io/metersphere/report/base/ErrorsTop5.java +++ b/backend/src/main/java/io/metersphere/report/base/ErrorsTop5.java @@ -4,9 +4,17 @@ public class ErrorsTop5 { private String sample; private String samples; - private Integer errorsAllSize; - private String error; - private String errors; + private String errorsAllSize; + private String error1; + private String error1Size; + private String error2; + private String error2Size; + private String error3; + private String error3Size; + private String error4; + private String error4Size; + private String error5; + private String error5Size; public String getSample() { return sample; @@ -24,27 +32,91 @@ public class ErrorsTop5 { this.samples = samples; } - public Integer getErrorsAllSize() { + public String getErrorsAllSize() { return errorsAllSize; } - public void setErrorsAllSize(Integer errorsAllSize) { + public void setErrorsAllSize(String errorsAllSize) { this.errorsAllSize = errorsAllSize; } - public String getError() { - return error; + public String getError1() { + return error1; } - public void setError(String error) { - this.error = error; + public void setError1(String error1) { + this.error1 = error1; } - public String getErrors() { - return errors; + public String getError1Size() { + return error1Size; } - public void setErrors(String errors) { - this.errors = errors; + public void setError1Size(String error1Size) { + this.error1Size = error1Size; + } + + public String getError2() { + return error2; + } + + public void setError2(String error2) { + this.error2 = error2; + } + + public String getError2Size() { + return error2Size; + } + + public void setError2Size(String error2Size) { + this.error2Size = error2Size; + } + + public String getError3() { + return error3; + } + + public void setError3(String error3) { + this.error3 = error3; + } + + public String getError3Size() { + return error3Size; + } + + public void setError3Size(String error3Size) { + this.error3Size = error3Size; + } + + public String getError4() { + return error4; + } + + public void setError4(String error4) { + this.error4 = error4; + } + + public String getError4Size() { + return error4Size; + } + + public void setError4Size(String error4Size) { + this.error4Size = error4Size; + } + + public String getError5() { + return error5; + } + + public void setError5(String error5) { + this.error5 = error5; + } + + public String getError5Size() { + return error5Size; + } + + public void setError5Size(String error5Size) { + this.error5Size = error5Size; } } diff --git a/backend/src/main/java/io/metersphere/report/parse/ResultDataParse.java b/backend/src/main/java/io/metersphere/report/parse/ResultDataParse.java index 99301006f2..d52e992b9c 100644 --- a/backend/src/main/java/io/metersphere/report/parse/ResultDataParse.java +++ b/backend/src/main/java/io/metersphere/report/parse/ResultDataParse.java @@ -1,16 +1,12 @@ package io.metersphere.report.parse; -import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.MsJMeterUtils; import io.metersphere.report.base.ChartsData; -import io.metersphere.report.base.Statistics; -import io.metersphere.report.base.SummaryData; import org.apache.jmeter.report.core.Sample; import org.apache.jmeter.report.core.SampleMetadata; import org.apache.jmeter.report.dashboard.JsonizerVisitor; import org.apache.jmeter.report.processor.*; import org.apache.jmeter.report.processor.graph.AbstractOverTimeGraphConsumer; - import java.lang.reflect.Field; import java.math.BigDecimal; import java.text.ParseException; @@ -26,8 +22,8 @@ public class ResultDataParse { private static final String DATE_TIME_PATTERN = "yyyy/MM/dd HH:mm:ss"; private static final String TIME_PATTERN = "HH:mm:ss"; - public static List summaryMapParsing(Map map) { - List statisticsList = new ArrayList<>(); + public static List summaryMapParsing(Map map, Class clazz) { + List list = new ArrayList<>(); for (String key : map.keySet()) { MapResultData mapResultData = (MapResultData) map.get(key); ListResultData items = (ListResultData) mapResultData.getResult("items"); @@ -39,21 +35,24 @@ public class ResultDataParse { String[] strArray = new String[size]; for (int j = 0; j < size; j++) { ValueResultData valueResultData = (ValueResultData) data.get(j); - String accept = valueResultData.accept(new JsonizerVisitor()); - strArray[j] = accept.replace("\\", ""); + if (valueResultData.getValue() == null) { + strArray[j] = ""; + } else { + String accept = valueResultData.accept(new JsonizerVisitor()); + strArray[j] = accept.replace("\\", ""); + } } - Statistics statistics = null; + T t = null; try { - statistics = setParam(Statistics.class, strArray); + t = setParam(clazz, strArray); } catch (Exception e) { e.printStackTrace(); } - statisticsList.add(statistics); + list.add(t); } - } } - return statisticsList; + return list; } public static List graphMapParsing(Map map, String seriesName) { diff --git a/backend/src/main/java/io/metersphere/service/ReportService.java b/backend/src/main/java/io/metersphere/service/ReportService.java index 601554c7b4..7ebe07725c 100644 --- a/backend/src/main/java/io/metersphere/service/ReportService.java +++ b/backend/src/main/java/io/metersphere/service/ReportService.java @@ -96,12 +96,12 @@ public class ReportService { return errors; } - public ErrorsTop5DTO getReportErrorsTOP5(String id) { + public List getReportErrorsTOP5(String id) { checkReportStatus(id); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); String content = loadTestReport.getContent(); - ErrorsTop5DTO errors = GenerateReport.getErrorsTop5DTO(content); - return errors; + List errorsTop5 = GenerateReport.getErrorsTop5List(content); + return errorsTop5; } public TestOverview getTestOverview(String id) { diff --git a/frontend/src/business/components/performance/report/components/ErrorLog.vue b/frontend/src/business/components/performance/report/components/ErrorLog.vue index 31b5140719..2691b0c3e9 100644 --- a/frontend/src/business/components/performance/report/components/ErrorLog.vue +++ b/frontend/src/business/components/performance/report/components/ErrorLog.vue @@ -39,7 +39,6 @@ stripe style="width: 100%" show-summary - :summary-method="getSummaries" > + + + @@ -128,22 +130,7 @@ name: "ErrorLog", data() { return { - tableData: [{},{},{},{},{}], - errorTotal: { - label: '', - totalSamples: '', - totalErrors: '', - error1: '', - error1Size: '', - error2: '', - error2Size: '', - error3: '', - error3Size: '', - error4: '', - error4Size: '', - error5: '', - error5Size: '' - }, + tableData: [], errorTop5: [] } }, @@ -153,33 +140,14 @@ this.tableData = res.data; }) this.$get("/performance/report/content/errors_top5/" + this.id, res => { - this.errorTotal = res.data - this.errorTop5 = res.data.errorsTop5List; + this.errorTop5 = res.data; }) - }, - getSummaries () { - const sums = [] - sums[0] = this.errorTotal.label; - sums[1] = this.errorTotal.totalSamples; - sums[2] = this.errorTotal.totalErrors; - sums[3] = this.errorTotal.error1; - sums[4] = this.errorTotal.error1Size; - sums[5] = this.errorTotal.error2; - sums[6] = this.errorTotal.error2Size; - sums[7] = this.errorTotal.error3; - sums[8] = this.errorTotal.error3Size; - sums[9] = this.errorTotal.error4; - sums[10] = this.errorTotal.error4Size; - sums[11] = this.errorTotal.error5; - sums[12] = this.errorTotal.error5Size; - return sums; } }, watch: { status() { if ("Completed" === this.status) { this.initTableData() - this.getSummaries() } } },