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

This commit is contained in:
Captain.B 2021-05-19 14:22:04 +08:00 committed by 刘瑞斌
parent 887877c714
commit d0d40742ae
7 changed files with 135 additions and 22 deletions

View File

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

View File

@ -1243,6 +1243,76 @@ public class LoadTestReportExample {
addCriterion("test_duration not between", value1, value2, "testDuration");
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

@ -19,11 +19,13 @@
<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" />
<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>
@ -86,10 +88,10 @@
<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, test_start_time, test_end_time,
test_duration
test_duration, 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
@ -145,15 +147,19 @@
user_id, trigger_mode, file_id,
max_users, avg_response_time, tps,
project_id, test_name, test_start_time,
test_end_time, test_duration, description,
load_configuration, jmx_content)
test_end_time, test_duration, 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}, #{testStartTime,jdbcType=BIGINT},
#{testEndTime,jdbcType=BIGINT}, #{testDuration,jdbcType=BIGINT}, #{description,jdbcType=LONGVARCHAR},
#{loadConfiguration,jdbcType=LONGVARCHAR}, #{jmxContent,jdbcType=LONGVARCHAR})
#{testEndTime,jdbcType=BIGINT}, #{testDuration,jdbcType=BIGINT}, #{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
@ -209,6 +215,9 @@
<if test="testDuration != null">
test_duration,
</if>
<if test="testResourcePoolId != null">
test_resource_pool_id,
</if>
<if test="description != null">
description,
</if>
@ -218,6 +227,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">
@ -271,6 +283,9 @@
<if test="testDuration != null">
#{testDuration,jdbcType=BIGINT},
</if>
<if test="testResourcePoolId != null">
#{testResourcePoolId,jdbcType=VARCHAR},
</if>
<if test="description != null">
#{description,jdbcType=LONGVARCHAR},
</if>
@ -280,6 +295,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">
@ -342,6 +360,9 @@
<if test="record.testDuration != null">
test_duration = #{record.testDuration,jdbcType=BIGINT},
</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>
@ -351,6 +372,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" />
@ -375,9 +399,11 @@
test_start_time = #{record.testStartTime,jdbcType=BIGINT},
test_end_time = #{record.testEndTime,jdbcType=BIGINT},
test_duration = #{record.testDuration,jdbcType=BIGINT},
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>
@ -400,7 +426,8 @@
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}
test_duration = #{record.testDuration,jdbcType=BIGINT},
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -456,6 +483,9 @@
<if test="testDuration != null">
test_duration = #{testDuration,jdbcType=BIGINT},
</if>
<if test="testResourcePoolId != null">
test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR},
</if>
<if test="description != null">
description = #{description,jdbcType=LONGVARCHAR},
</if>
@ -465,6 +495,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>
@ -486,9 +519,11 @@
test_start_time = #{testStartTime,jdbcType=BIGINT},
test_end_time = #{testEndTime,jdbcType=BIGINT},
test_duration = #{testDuration,jdbcType=BIGINT},
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">
@ -508,7 +543,8 @@
test_name = #{testName,jdbcType=VARCHAR},
test_start_time = #{testStartTime,jdbcType=BIGINT},
test_end_time = #{testEndTime,jdbcType=BIGINT},
test_duration = #{testDuration,jdbcType=BIGINT}
test_duration = #{testDuration,jdbcType=BIGINT},
test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -6,9 +6,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.client.utils.StringUtils;
import io.metersphere.base.domain.LoadTestReportWithBLOBs;
import io.metersphere.base.domain.LoadTestWithBLOBs;
import io.metersphere.base.domain.TestResource;
import io.metersphere.base.mapper.LoadTestMapper;
import io.metersphere.base.mapper.LoadTestReportMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
import io.metersphere.commons.constants.ParamConstants;
@ -32,7 +30,6 @@ import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
@ -46,8 +43,6 @@ public class MetricQueryService {
@Resource
private LoadTestReportMapper loadTestReportMapper;
@Resource
private LoadTestMapper loadTestMapper;
@Resource
private PerformanceReportService performanceReportService;
@Resource
private ExtLoadTestReportMapper extLoadTestReportMapper;
@ -163,9 +158,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 +170,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) {
@ -247,9 +240,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

@ -354,8 +354,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;
-- schedule
alter table schedule
add config VARCHAR(500) null;