fix(性能测试): 修复性能测试删除之后报告页面查询监控报错

This commit is contained in:
Captain.B 2021-05-19 14:31:45 +08:00 committed by 刘瑞斌
parent 494cc22505
commit 8d02d26879
8 changed files with 144 additions and 24 deletions

View File

@ -33,5 +33,7 @@ public class LoadTestReport implements Serializable {
private String testName;
private String testResourcePoolId;
private static final long serialVersionUID = 1L;
}

View File

@ -1063,6 +1063,76 @@ public class LoadTestReportExample {
addCriterion("test_name not between", value1, value2, "testName");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdIsNull() {
addCriterion("test_resource_pool_id is null");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdIsNotNull() {
addCriterion("test_resource_pool_id is not null");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdEqualTo(String value) {
addCriterion("test_resource_pool_id =", value, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdNotEqualTo(String value) {
addCriterion("test_resource_pool_id <>", value, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdGreaterThan(String value) {
addCriterion("test_resource_pool_id >", value, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdGreaterThanOrEqualTo(String value) {
addCriterion("test_resource_pool_id >=", value, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdLessThan(String value) {
addCriterion("test_resource_pool_id <", value, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdLessThanOrEqualTo(String value) {
addCriterion("test_resource_pool_id <=", value, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdLike(String value) {
addCriterion("test_resource_pool_id like", value, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdNotLike(String value) {
addCriterion("test_resource_pool_id not like", value, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdIn(List<String> values) {
addCriterion("test_resource_pool_id in", values, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdNotIn(List<String> values) {
addCriterion("test_resource_pool_id not in", values, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdBetween(String value1, String value2) {
addCriterion("test_resource_pool_id between", value1, value2, "testResourcePoolId");
return (Criteria) this;
}
public Criteria andTestResourcePoolIdNotBetween(String value1, String value2) {
addCriterion("test_resource_pool_id not between", value1, value2, "testResourcePoolId");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

View File

@ -15,5 +15,7 @@ public class LoadTestReportWithBLOBs extends LoadTestReport implements Serializa
private String jmxContent;
private String advancedConfiguration;
private static final long serialVersionUID = 1L;
}

View File

@ -16,11 +16,13 @@
<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_resource_pool_id" jdbcType="VARCHAR" property="testResourcePoolId" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.LoadTestReportWithBLOBs">
<result column="description" jdbcType="LONGVARCHAR" property="description" />
<result column="load_configuration" jdbcType="LONGVARCHAR" property="loadConfiguration" />
<result column="jmx_content" jdbcType="LONGVARCHAR" property="jmxContent" />
<result column="advanced_configuration" jdbcType="LONGVARCHAR" property="advancedConfiguration" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -82,10 +84,10 @@
</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_resource_pool_id
</sql>
<sql id="Blob_Column_List">
description, load_configuration, jmx_content
description, load_configuration, jmx_content, advanced_configuration
</sql>
<select id="selectByExampleWithBLOBs" parameterType="io.metersphere.base.domain.LoadTestReportExample" resultMap="ResultMapWithBLOBs">
select
@ -140,14 +142,18 @@
create_time, update_time, `status`,
user_id, trigger_mode, file_id,
max_users, avg_response_time, tps,
project_id, test_name, description,
load_configuration, jmx_content)
project_id, test_name, test_resource_pool_id,
description, load_configuration,
jmx_content, advanced_configuration
)
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},
#{loadConfiguration,jdbcType=LONGVARCHAR}, #{jmxContent,jdbcType=LONGVARCHAR})
#{projectId,jdbcType=VARCHAR}, #{testName,jdbcType=VARCHAR}, #{testResourcePoolId,jdbcType=VARCHAR},
#{description,jdbcType=LONGVARCHAR}, #{loadConfiguration,jdbcType=LONGVARCHAR},
#{jmxContent,jdbcType=LONGVARCHAR}, #{advancedConfiguration,jdbcType=LONGVARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.LoadTestReportWithBLOBs">
insert into load_test_report
@ -194,6 +200,9 @@
<if test="testName != null">
test_name,
</if>
<if test="testResourcePoolId != null">
test_resource_pool_id,
</if>
<if test="description != null">
description,
</if>
@ -203,6 +212,9 @@
<if test="jmxContent != null">
jmx_content,
</if>
<if test="advancedConfiguration != null">
advanced_configuration,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -247,6 +259,9 @@
<if test="testName != null">
#{testName,jdbcType=VARCHAR},
</if>
<if test="testResourcePoolId != null">
#{testResourcePoolId,jdbcType=VARCHAR},
</if>
<if test="description != null">
#{description,jdbcType=LONGVARCHAR},
</if>
@ -256,6 +271,9 @@
<if test="jmxContent != null">
#{jmxContent,jdbcType=LONGVARCHAR},
</if>
<if test="advancedConfiguration != null">
#{advancedConfiguration,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.LoadTestReportExample" resultType="java.lang.Long">
@ -309,6 +327,9 @@
<if test="record.testName != null">
test_name = #{record.testName,jdbcType=VARCHAR},
</if>
<if test="record.testResourcePoolId != null">
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR},
</if>
<if test="record.description != null">
description = #{record.description,jdbcType=LONGVARCHAR},
</if>
@ -318,6 +339,9 @@
<if test="record.jmxContent != null">
jmx_content = #{record.jmxContent,jdbcType=LONGVARCHAR},
</if>
<if test="record.advancedConfiguration != null">
advanced_configuration = #{record.advancedConfiguration,jdbcType=LONGVARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -339,9 +363,11 @@
tps = #{record.tps,jdbcType=VARCHAR},
project_id = #{record.projectId,jdbcType=VARCHAR},
test_name = #{record.testName,jdbcType=VARCHAR},
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR},
description = #{record.description,jdbcType=LONGVARCHAR},
load_configuration = #{record.loadConfiguration,jdbcType=LONGVARCHAR},
jmx_content = #{record.jmxContent,jdbcType=LONGVARCHAR}
jmx_content = #{record.jmxContent,jdbcType=LONGVARCHAR},
advanced_configuration = #{record.advancedConfiguration,jdbcType=LONGVARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -361,7 +387,8 @@
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_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -408,6 +435,9 @@
<if test="testName != null">
test_name = #{testName,jdbcType=VARCHAR},
</if>
<if test="testResourcePoolId != null">
test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR},
</if>
<if test="description != null">
description = #{description,jdbcType=LONGVARCHAR},
</if>
@ -417,6 +447,9 @@
<if test="jmxContent != null">
jmx_content = #{jmxContent,jdbcType=LONGVARCHAR},
</if>
<if test="advancedConfiguration != null">
advanced_configuration = #{advancedConfiguration,jdbcType=LONGVARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
@ -435,9 +468,11 @@
tps = #{tps,jdbcType=VARCHAR},
project_id = #{projectId,jdbcType=VARCHAR},
test_name = #{testName,jdbcType=VARCHAR},
test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR},
description = #{description,jdbcType=LONGVARCHAR},
load_configuration = #{loadConfiguration,jdbcType=LONGVARCHAR},
jmx_content = #{jmxContent,jdbcType=LONGVARCHAR}
jmx_content = #{jmxContent,jdbcType=LONGVARCHAR},
advanced_configuration = #{advancedConfiguration,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.LoadTestReport">
@ -454,7 +489,8 @@
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_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -46,8 +46,6 @@ public class MetricQueryService {
@Resource
private LoadTestReportMapper loadTestReportMapper;
@Resource
private LoadTestMapper loadTestMapper;
@Resource
private PerformanceReportService performanceReportService;
@Resource
private ExtLoadTestReportMapper extLoadTestReportMapper;
@ -163,9 +161,7 @@ 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();
String poolId = report.getTestResourcePoolId();
List<TestResource> resourceList = testResourceService.getTestResourceList(poolId);
// 默认监控资源池下的节点
if (CollectionUtils.isNotEmpty(resourceList)) {
@ -177,7 +173,7 @@ public class MetricQueryService {
}
});
}
String advancedConfiguration = loadTestWithBLOBs.getAdvancedConfiguration();
String advancedConfiguration = report.getAdvancedConfiguration();
JSONObject jsonObject = JSON.parseObject(advancedConfiguration);
JSONArray monitorParams = jsonObject.getJSONArray("monitorParams");
if (monitorParams == null) {
@ -250,9 +246,7 @@ public class MetricQueryService {
});
LoadTestReportWithBLOBs report = loadTestReportMapper.selectByPrimaryKey(reportId);
String testId = report.getTestId();
LoadTestWithBLOBs loadTestWithBLOBs = loadTestMapper.selectByPrimaryKey(testId);
String advancedConfiguration = loadTestWithBLOBs.getAdvancedConfiguration();
String advancedConfiguration = report.getAdvancedConfiguration();
JSONObject jsonObject = JSON.parseObject(advancedConfiguration);
JSONArray monitorParams = jsonObject.getJSONArray("monitorParams");
if (monitorParams == null) {

View File

@ -348,8 +348,10 @@ public class PerformanceTestService {
loadTestMapper.updateByPrimaryKeySelective(loadTest);
// 启动正常插入 report
testReport.setLoadConfiguration(loadTest.getLoadConfiguration());
testReport.setAdvancedConfiguration(loadTest.getAdvancedConfiguration());
testReport.setStatus(PerformanceTestStatus.Starting.name());
testReport.setProjectId(loadTest.getProjectId());
testReport.setTestResourcePoolId(loadTest.getTestResourcePoolId());
testReport.setTestName(loadTest.getName());
loadTestReportMapper.insertSelective(testReport);

View File

@ -8,11 +8,21 @@ ALTER TABLE load_test_report
ALTER TABLE load_test_report
ADD jmx_content LONGTEXT NULL;
ALTER TABLE load_test_report
ADD advanced_configuration LONGTEXT NULL;
alter table load_test_report
add test_resource_pool_id VARCHAR(50) null;
UPDATE load_test_report JOIN load_test ON load_test.id = load_test_report.test_id
SET load_test_report.project_id = load_test.project_id;
UPDATE load_test_report JOIN load_test ON load_test.id = load_test_report.test_id
SET load_test_report.test_name = load_test.name;
UPDATE load_test_report JOIN load_test ON load_test.id = test_id
SET load_test_report.advanced_configuration = load_test.advanced_configuration;
--

View File

@ -77,11 +77,15 @@
<table tableName="test_case_review_scenario"/>
<table tableName="test_plan"/>
<table tableName="test_case_test"/>-->
<table tableName="issues"></table>
<!-- <table tableName="custom_field"></table>-->
<!-- <table tableName="test_case"></table>-->
<!-- <table tableName="test_case"></table>-->
<!-- <table tableName="custom_field_template"></table>-->
<table tableName="load_test_report">
<ignoreColumn column="test_end_time"/>
<ignoreColumn column="test_start_time"/>
<ignoreColumn column="test_duration"/>
</table>
<!-- <table tableName="custom_field"></table>-->
<!-- <table tableName="test_case"></table>-->
<!-- <table tableName="test_case"></table>-->
<!-- <table tableName="custom_field_template"></table>-->
</context>
</generatorConfiguration>