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 testName;
private String testResourcePoolId;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
} }

View File

@ -1063,6 +1063,76 @@ public class LoadTestReportExample {
addCriterion("test_name not between", value1, value2, "testName"); addCriterion("test_name not between", value1, value2, "testName");
return (Criteria) this; 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 { public static class Criteria extends GeneratedCriteria {

View File

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

View File

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

View File

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

View File

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

View File

@ -8,11 +8,21 @@ ALTER TABLE load_test_report
ALTER TABLE load_test_report ALTER TABLE load_test_report
ADD jmx_content LONGTEXT NULL; 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 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; 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 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; 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_case_review_scenario"/>
<table tableName="test_plan"/> <table tableName="test_plan"/>
<table tableName="test_case_test"/>--> <table tableName="test_case_test"/>-->
<table tableName="issues"></table> <table tableName="load_test_report">
<!-- <table tableName="custom_field"></table>--> <ignoreColumn column="test_end_time"/>
<!-- <table tableName="test_case"></table>--> <ignoreColumn column="test_start_time"/>
<!-- <table tableName="test_case"></table>--> <ignoreColumn column="test_duration"/>
<!-- <table tableName="custom_field_template"></table>--> </table>
<!-- <table tableName="custom_field"></table>-->
<!-- <table tableName="test_case"></table>-->
<!-- <table tableName="test_case"></table>-->
<!-- <table tableName="custom_field_template"></table>-->
</context> </context>
</generatorConfiguration> </generatorConfiguration>