refactor(性能测试): 性能测试报告列表显示时间信息

This commit is contained in:
Captain.B 2021-05-18 18:30:38 +08:00 committed by 刘瑞斌
parent 16b227edbe
commit b7a5282bb1
14 changed files with 382 additions and 60 deletions

View File

@ -33,5 +33,11 @@ public class LoadTestReport implements Serializable {
private String testName;
private Long testStartTime;
private Long testEndTime;
private Long testDuration;
private static final long serialVersionUID = 1L;
}

View File

@ -1063,6 +1063,186 @@ public class LoadTestReportExample {
addCriterion("test_name not between", value1, value2, "testName");
return (Criteria) this;
}
public Criteria andTestStartTimeIsNull() {
addCriterion("test_start_time is null");
return (Criteria) this;
}
public Criteria andTestStartTimeIsNotNull() {
addCriterion("test_start_time is not null");
return (Criteria) this;
}
public Criteria andTestStartTimeEqualTo(Long value) {
addCriterion("test_start_time =", value, "testStartTime");
return (Criteria) this;
}
public Criteria andTestStartTimeNotEqualTo(Long value) {
addCriterion("test_start_time <>", value, "testStartTime");
return (Criteria) this;
}
public Criteria andTestStartTimeGreaterThan(Long value) {
addCriterion("test_start_time >", value, "testStartTime");
return (Criteria) this;
}
public Criteria andTestStartTimeGreaterThanOrEqualTo(Long value) {
addCriterion("test_start_time >=", value, "testStartTime");
return (Criteria) this;
}
public Criteria andTestStartTimeLessThan(Long value) {
addCriterion("test_start_time <", value, "testStartTime");
return (Criteria) this;
}
public Criteria andTestStartTimeLessThanOrEqualTo(Long value) {
addCriterion("test_start_time <=", value, "testStartTime");
return (Criteria) this;
}
public Criteria andTestStartTimeIn(List<Long> values) {
addCriterion("test_start_time in", values, "testStartTime");
return (Criteria) this;
}
public Criteria andTestStartTimeNotIn(List<Long> values) {
addCriterion("test_start_time not in", values, "testStartTime");
return (Criteria) this;
}
public Criteria andTestStartTimeBetween(Long value1, Long value2) {
addCriterion("test_start_time between", value1, value2, "testStartTime");
return (Criteria) this;
}
public Criteria andTestStartTimeNotBetween(Long value1, Long value2) {
addCriterion("test_start_time not between", value1, value2, "testStartTime");
return (Criteria) this;
}
public Criteria andTestEndTimeIsNull() {
addCriterion("test_end_time is null");
return (Criteria) this;
}
public Criteria andTestEndTimeIsNotNull() {
addCriterion("test_end_time is not null");
return (Criteria) this;
}
public Criteria andTestEndTimeEqualTo(Long value) {
addCriterion("test_end_time =", value, "testEndTime");
return (Criteria) this;
}
public Criteria andTestEndTimeNotEqualTo(Long value) {
addCriterion("test_end_time <>", value, "testEndTime");
return (Criteria) this;
}
public Criteria andTestEndTimeGreaterThan(Long value) {
addCriterion("test_end_time >", value, "testEndTime");
return (Criteria) this;
}
public Criteria andTestEndTimeGreaterThanOrEqualTo(Long value) {
addCriterion("test_end_time >=", value, "testEndTime");
return (Criteria) this;
}
public Criteria andTestEndTimeLessThan(Long value) {
addCriterion("test_end_time <", value, "testEndTime");
return (Criteria) this;
}
public Criteria andTestEndTimeLessThanOrEqualTo(Long value) {
addCriterion("test_end_time <=", value, "testEndTime");
return (Criteria) this;
}
public Criteria andTestEndTimeIn(List<Long> values) {
addCriterion("test_end_time in", values, "testEndTime");
return (Criteria) this;
}
public Criteria andTestEndTimeNotIn(List<Long> values) {
addCriterion("test_end_time not in", values, "testEndTime");
return (Criteria) this;
}
public Criteria andTestEndTimeBetween(Long value1, Long value2) {
addCriterion("test_end_time between", value1, value2, "testEndTime");
return (Criteria) this;
}
public Criteria andTestEndTimeNotBetween(Long value1, Long value2) {
addCriterion("test_end_time not between", value1, value2, "testEndTime");
return (Criteria) this;
}
public Criteria andTestDurationIsNull() {
addCriterion("test_duration is null");
return (Criteria) this;
}
public Criteria andTestDurationIsNotNull() {
addCriterion("test_duration is not null");
return (Criteria) this;
}
public Criteria andTestDurationEqualTo(Long value) {
addCriterion("test_duration =", value, "testDuration");
return (Criteria) this;
}
public Criteria andTestDurationNotEqualTo(Long value) {
addCriterion("test_duration <>", value, "testDuration");
return (Criteria) this;
}
public Criteria andTestDurationGreaterThan(Long value) {
addCriterion("test_duration >", value, "testDuration");
return (Criteria) this;
}
public Criteria andTestDurationGreaterThanOrEqualTo(Long value) {
addCriterion("test_duration >=", value, "testDuration");
return (Criteria) this;
}
public Criteria andTestDurationLessThan(Long value) {
addCriterion("test_duration <", value, "testDuration");
return (Criteria) this;
}
public Criteria andTestDurationLessThanOrEqualTo(Long value) {
addCriterion("test_duration <=", value, "testDuration");
return (Criteria) this;
}
public Criteria andTestDurationIn(List<Long> values) {
addCriterion("test_duration in", values, "testDuration");
return (Criteria) this;
}
public Criteria andTestDurationNotIn(List<Long> values) {
addCriterion("test_duration not in", values, "testDuration");
return (Criteria) this;
}
public Criteria andTestDurationBetween(Long value1, Long value2) {
addCriterion("test_duration between", value1, value2, "testDuration");
return (Criteria) this;
}
public Criteria andTestDurationNotBetween(Long value1, Long value2) {
addCriterion("test_duration not between", value1, value2, "testDuration");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -16,6 +16,9 @@
<result column="tps" jdbcType="VARCHAR" property="tps" />
<result column="project_id" jdbcType="VARCHAR" property="projectId" />
<result column="test_name" jdbcType="VARCHAR" property="testName" />
<result column="test_start_time" jdbcType="BIGINT" property="testStartTime" />
<result column="test_end_time" jdbcType="BIGINT" property="testEndTime" />
<result column="test_duration" jdbcType="BIGINT" property="testDuration" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.LoadTestReportWithBLOBs">
<result column="description" jdbcType="LONGVARCHAR" property="description" />
@ -82,7 +85,8 @@
</sql>
<sql id="Base_Column_List">
id, test_id, `name`, create_time, update_time, `status`, user_id, trigger_mode, file_id,
max_users, avg_response_time, tps, project_id, test_name
max_users, avg_response_time, tps, project_id, test_name, test_start_time, test_end_time,
test_duration
</sql>
<sql id="Blob_Column_List">
description, load_configuration, jmx_content
@ -140,13 +144,15 @@
create_time, update_time, `status`,
user_id, trigger_mode, file_id,
max_users, avg_response_time, tps,
project_id, test_name, description,
project_id, test_name, test_start_time,
test_end_time, test_duration, description,
load_configuration, jmx_content)
values (#{id,jdbcType=VARCHAR}, #{testId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{status,jdbcType=VARCHAR},
#{userId,jdbcType=VARCHAR}, #{triggerMode,jdbcType=VARCHAR}, #{fileId,jdbcType=VARCHAR},
#{maxUsers,jdbcType=VARCHAR}, #{avgResponseTime,jdbcType=VARCHAR}, #{tps,jdbcType=VARCHAR},
#{projectId,jdbcType=VARCHAR}, #{testName,jdbcType=VARCHAR}, #{description,jdbcType=LONGVARCHAR},
#{projectId,jdbcType=VARCHAR}, #{testName,jdbcType=VARCHAR}, #{testStartTime,jdbcType=BIGINT},
#{testEndTime,jdbcType=BIGINT}, #{testDuration,jdbcType=BIGINT}, #{description,jdbcType=LONGVARCHAR},
#{loadConfiguration,jdbcType=LONGVARCHAR}, #{jmxContent,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.LoadTestReportWithBLOBs">
@ -194,6 +200,15 @@
<if test="testName != null">
test_name,
</if>
<if test="testStartTime != null">
test_start_time,
</if>
<if test="testEndTime != null">
test_end_time,
</if>
<if test="testDuration != null">
test_duration,
</if>
<if test="description != null">
description,
</if>
@ -247,6 +262,15 @@
<if test="testName != null">
#{testName,jdbcType=VARCHAR},
</if>
<if test="testStartTime != null">
#{testStartTime,jdbcType=BIGINT},
</if>
<if test="testEndTime != null">
#{testEndTime,jdbcType=BIGINT},
</if>
<if test="testDuration != null">
#{testDuration,jdbcType=BIGINT},
</if>
<if test="description != null">
#{description,jdbcType=LONGVARCHAR},
</if>
@ -309,6 +333,15 @@
<if test="record.testName != null">
test_name = #{record.testName,jdbcType=VARCHAR},
</if>
<if test="record.testStartTime != null">
test_start_time = #{record.testStartTime,jdbcType=BIGINT},
</if>
<if test="record.testEndTime != null">
test_end_time = #{record.testEndTime,jdbcType=BIGINT},
</if>
<if test="record.testDuration != null">
test_duration = #{record.testDuration,jdbcType=BIGINT},
</if>
<if test="record.description != null">
description = #{record.description,jdbcType=LONGVARCHAR},
</if>
@ -339,6 +372,9 @@
tps = #{record.tps,jdbcType=VARCHAR},
project_id = #{record.projectId,jdbcType=VARCHAR},
test_name = #{record.testName,jdbcType=VARCHAR},
test_start_time = #{record.testStartTime,jdbcType=BIGINT},
test_end_time = #{record.testEndTime,jdbcType=BIGINT},
test_duration = #{record.testDuration,jdbcType=BIGINT},
description = #{record.description,jdbcType=LONGVARCHAR},
load_configuration = #{record.loadConfiguration,jdbcType=LONGVARCHAR},
jmx_content = #{record.jmxContent,jdbcType=LONGVARCHAR}
@ -361,7 +397,10 @@
avg_response_time = #{record.avgResponseTime,jdbcType=VARCHAR},
tps = #{record.tps,jdbcType=VARCHAR},
project_id = #{record.projectId,jdbcType=VARCHAR},
test_name = #{record.testName,jdbcType=VARCHAR}
test_name = #{record.testName,jdbcType=VARCHAR},
test_start_time = #{record.testStartTime,jdbcType=BIGINT},
test_end_time = #{record.testEndTime,jdbcType=BIGINT},
test_duration = #{record.testDuration,jdbcType=BIGINT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -408,6 +447,15 @@
<if test="testName != null">
test_name = #{testName,jdbcType=VARCHAR},
</if>
<if test="testStartTime != null">
test_start_time = #{testStartTime,jdbcType=BIGINT},
</if>
<if test="testEndTime != null">
test_end_time = #{testEndTime,jdbcType=BIGINT},
</if>
<if test="testDuration != null">
test_duration = #{testDuration,jdbcType=BIGINT},
</if>
<if test="description != null">
description = #{description,jdbcType=LONGVARCHAR},
</if>
@ -435,6 +483,9 @@
tps = #{tps,jdbcType=VARCHAR},
project_id = #{projectId,jdbcType=VARCHAR},
test_name = #{testName,jdbcType=VARCHAR},
test_start_time = #{testStartTime,jdbcType=BIGINT},
test_end_time = #{testEndTime,jdbcType=BIGINT},
test_duration = #{testDuration,jdbcType=BIGINT},
description = #{description,jdbcType=LONGVARCHAR},
load_configuration = #{loadConfiguration,jdbcType=LONGVARCHAR},
jmx_content = #{jmxContent,jdbcType=LONGVARCHAR}
@ -454,7 +505,10 @@
avg_response_time = #{avgResponseTime,jdbcType=VARCHAR},
tps = #{tps,jdbcType=VARCHAR},
project_id = #{projectId,jdbcType=VARCHAR},
test_name = #{testName,jdbcType=VARCHAR}
test_name = #{testName,jdbcType=VARCHAR},
test_start_time = #{testStartTime,jdbcType=BIGINT},
test_end_time = #{testEndTime,jdbcType=BIGINT},
test_duration = #{testDuration,jdbcType=BIGINT}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -66,7 +66,8 @@
<select id="getReportList" resultType="io.metersphere.dto.ReportDTO">
select ltr.id, ltr.name, ltr.test_id as testId, ltr.max_users maxUsers, ltr.avg_response_time avgResponseTime,
ltr.tps, ltr.description, user.name as userName, project.name as
ltr.tps, ltr.test_start_time as testStartTime, ltr.test_end_time as testEndTime, ltr.test_duration as testDuration,
ltr.description, user.name as userName, project.name as
projectName, ltr.trigger_mode,
ltr.create_time as createTime, ltr.update_time as updateTime, ltr.status as status, ltr.test_name as testName,
project.id as projectId

View File

@ -23,4 +23,7 @@ public class ReportDTO {
private String maxUsers;
private String avgResponseTime;
private String tps;
private long testStartTime;
private long testEndTime;
private long testDuration;
}

View File

@ -4,9 +4,7 @@ import lombok.Data;
@Data
public class ReportTimeInfo {
private String duration;
private String startTime;
private String endTime;
private long duration;
private long startTime;
private long endTime;
}

View File

@ -201,11 +201,8 @@ public class MetricQueryService {
MetricRequest metricRequest = new MetricRequest();
metricRequest.setMetricDataQueries(list);
try {
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date startTime = df.parse(reportTimeInfo.getStartTime());
Date endTime = df.parse(reportTimeInfo.getEndTime());
metricRequest.setStartTime(startTime.getTime());
metricRequest.setEndTime(endTime.getTime());
metricRequest.setStartTime(reportTimeInfo.getStartTime());
metricRequest.setEndTime(reportTimeInfo.getEndTime());
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
e.printStackTrace();

View File

@ -35,6 +35,7 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
@ -169,7 +170,25 @@ public class PerformanceReportService {
public ReportTimeInfo getReportTimeInfo(String id) {
checkReportStatus(id);
String content = getContent(id, ReportKeys.TimeInfo);
return JSON.parseObject(content, ReportTimeInfo.class);
try {
return JSON.parseObject(content, ReportTimeInfo.class);
} catch (Exception e) {
// 兼容字符串和数字
ReportTimeInfo reportTimeInfo = new ReportTimeInfo();
JSONObject jsonObject = JSONObject.parseObject(content);
String startTime = jsonObject.getString("startTime");
String endTime = jsonObject.getString("endTime");
String duration = jsonObject.getString("duration");
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
try {
reportTimeInfo.setStartTime(df.parse(startTime).getTime());
reportTimeInfo.setEndTime(df.parse(endTime).getTime());
reportTimeInfo.setDuration(Long.parseLong(duration));
} catch (Exception parseException) {
}
return reportTimeInfo;
}
}
public List<ChartsData> getLoadChartData(String id) {

View File

@ -59,3 +59,13 @@ ALTER TABLE test_case
UPDATE system_parameter
SET param_key = 'base.prometheus.host'
WHERE param_key = 'prometheus.host';
-- load_test_report
alter table load_test_report
add test_start_time BIGINT(13) null;
alter table load_test_report
add test_end_time BIGINT(13) null;
alter table load_test_report
add test_duration BIGINT(13) null;

View File

@ -44,13 +44,13 @@
{{ $t('report.test_duration', [this.minutes, this.seconds]) }}
</span>
<span class="ms-report-time-desc" v-if="startTime !== '0'">
{{ $t('report.test_start_time') }}{{ startTime }}
{{ $t('report.test_start_time') }}{{ startTime | timestampFormatDate }}
</span>
<span class="ms-report-time-desc" v-else>
{{ $t('report.test_start_time') }}-
</span>
<span class="ms-report-time-desc" v-if="report.status === 'Completed' && endTime !== '0'">
{{ $t('report.test_end_time') }}{{ endTime }}
{{ $t('report.test_end_time') }}{{ endTime | timestampFormatDate }}
</span>
<span class="ms-report-time-desc" v-else>
{{ $t('report.test_end_time') }}-

View File

@ -1,64 +1,85 @@
<template>
<ms-container>
<ms-main-container>
<el-card class="table-card" v-loading="result.loading">
<el-card class="table-card">
<template v-slot:header>
<ms-table-header :is-tester-permission="true" :condition.sync="condition" @search="search"
:title="$t('commons.report')"
:show-create="false"/>
</template>
<el-table border :data="tableData" class="adjust-table test-content"
<el-table v-loading="result.loading"
border :data="tableData" class="adjust-table test-content"
@select-all="handleSelectAll"
@select="handleSelect"
@sort-change="sort"
@filter-change="filter"
:height="screenHeight"
>
<el-table-column
type="selection"/>
type="selection"/>
<el-table-column width="40" :resizable="false" align="center">
<template v-slot:default="scope">
<show-more-btn v-tester :is-show="scope.row.showMore" :buttons="buttons" :size="selectRows.size"/>
</template>
</el-table-column>
<el-table-column
prop="testName"
:label="$t('report.test_name')"
show-overflow-tooltip>
prop="testName"
:label="$t('report.test_name')"
show-overflow-tooltip>
</el-table-column>
<el-table-column
prop="name"
:label="$t('commons.name')"
show-overflow-tooltip>
prop="name"
:label="$t('commons.name')"
show-overflow-tooltip>
<template v-slot:default="scope">
<span @click="handleView(scope.row)" style="cursor: pointer;">{{ scope.row.name }}</span>
</template>
</el-table-column>
<el-table-column
prop="userName"
:label="$t('report.user_name')"
show-overflow-tooltip>
prop="userName"
:label="$t('report.user_name')"
show-overflow-tooltip>
</el-table-column>
<el-table-column
prop="maxUsers"
:label="$t('report.max_users')">
prop="maxUsers"
width="65"
:label="$t('report.max_users')">
</el-table-column>
<el-table-column
width="150"
prop="avgResponseTime"
:label="$t('report.response_time')">
width="100"
prop="avgResponseTime"
:label="$t('report.response_time')">
</el-table-column>
<el-table-column
prop="tps"
label="TPS">
prop="tps"
label="TPS">
</el-table-column>
<el-table-column
width="200"
prop="createTime"
sortable
:label="$t('commons.create_time')">
width="100"
prop="testStartTime"
:label="$t('report.test_start_time') ">
<template v-slot:default="scope">
<span>{{ scope.row.createTime | timestampFormatDate }}</span>
<span v-if="scope.row.testStartTime > 0">{{ scope.row.testStartTime | timestampFormatDate }}</span>
</template>
</el-table-column>
<el-table-column
width="100"
prop="testEndTime"
:label="$t('report.test_end_time')">
<template v-slot:default="scope">
<span v-if="scope.row.status === 'Completed'">{{ scope.row.testEndTime | timestampFormatDate }}</span>
</template>
</el-table-column>
<el-table-column
width="90"
prop="testDuration"
:label="$t('report.test_execute_time')">
<template v-slot:default="scope">
<span v-if="scope.row.status === 'Completed'">
{{ scope.row.minutes }}{{ $t('schedule.cron.minutes') }}
{{ scope.row.seconds }}{{ $t('schedule.cron.seconds') }}
</span>
</template>
</el-table-column>
<el-table-column prop="triggerMode" :label="$t('test_track.report.list.trigger_mode')"
@ -69,17 +90,17 @@
</template>
</el-table-column>
<el-table-column
prop="status"
column-key="status"
:filters="statusFilters"
:label="$t('commons.status')">
prop="status"
column-key="status"
:filters="statusFilters"
:label="$t('commons.status')">
<template v-slot:default="{row}">
<ms-performance-report-status :row="row"/>
</template>
</el-table-column>
<el-table-column
width="180"
:label="$t('commons.operating')">
width="180"
:label="$t('commons.operating')">
<template v-slot:default="scope">
<ms-table-operator-button :tip="$t('test_track.module.rename')" icon="el-icon-edit"
@exec="handleRename(scope.row)" type="success"/>
@ -149,6 +170,7 @@ export default {
total: 0,
loading: false,
testId: null,
screenHeight: 'calc(100vh - 295px)',
statusFilters: [
{text: 'Starting', value: 'Starting'},
{text: 'Running', value: 'Running'},
@ -181,6 +203,44 @@ export default {
}
},
methods: {
handleTimeInfo(report) {
if (report.testStartTime) {
let duration = report.testDuration;
let minutes = Math.floor(duration / 60);
let seconds = duration % 60;
this.$set(report, 'minutes', minutes);
this.$set(report, 'seconds', seconds);
}
if (report.status === 'Completed' && !report.testStartTime) {
this.result = this.$get("/performance/report/content/report_time/" + report.id)
.then(res => {
let data = res.data.data;
if (data) {
let duration = data.duration;
let minutes = Math.floor(duration / 60);
let seconds = duration % 60;
this.$set(report, 'testStartTime', data.startTime);
this.$set(report, 'testEndTime', data.endTime);
this.$set(report, 'minutes', minutes);
this.$set(report, 'seconds', seconds);
}
}).catch(() => {
});
}
},
handleOverview(report) {
if (report.status === 'Completed' && !report.maxUsers) {
this.result = this.$get('/performance/report/content/testoverview/' + report.id)
.then(response => {
let data = response.data.data;
this.$set(report, 'maxUsers', data.maxUsers);
this.$set(report, 'avgResponseTime', data.avgResponseTime);
this.$set(report, 'tps', data.avgTransactions);
})
.catch(() => {
});
}
},
initTableData() {
if (this.testId !== 'all') {
this.condition.testId = this.testId;
@ -199,17 +259,8 @@ export default {
this.selectRows = new Set();
this.tableData.forEach(report => {
if (report.status === 'Completed' && !report.maxUsers) {
this.result = this.$get('/performance/report/content/testoverview/' + report.id)
.then(response => {
let data = response.data.data;
this.$set(report, 'maxUsers', data.maxUsers);
this.$set(report, 'avgResponseTime', data.avgResponseTime);
this.$set(report, 'tps', data.avgTransactions);
})
.catch(() => {
});
}
this.handleOverview(report);
this.handleTimeInfo(report);
});
});
},

View File

@ -488,6 +488,7 @@ export default {
test_monitor_details: 'Test Monitor Details',
test_details: 'Test Details',
test_duration: 'Execution Time{0} minutes {1} seconds',
test_execute_time: 'Execution Time',
test_start_time: 'Start Time',
test_end_time: 'End Time',
test_stop_now: 'Test Stop Now',

View File

@ -486,6 +486,7 @@ export default {
test_monitor_details: '监控详情',
test_details: '测试详情',
test_duration: '执行时长:{0} 分钟 {1} 秒',
test_execute_time: '执行时长',
test_start_time: '开始时间',
test_end_time: '结束时间',
test_stop_now: '立即停止',

View File

@ -486,6 +486,7 @@ export default {
test_monitor_details: '監控詳情',
test_details: '測試詳情',
test_duration: '執行時長:{0} 分鐘 {1} 秒',
test_execute_time: '執行時長',
test_start_time: '開始時間',
test_end_time: '結束時間',
test_stop_now: '立即停止',