Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
6f1db9d4eb
|
@ -0,0 +1,32 @@
|
|||
package io.metersphere.performance.engine.producer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
public class LoadTestProducer {
|
||||
|
||||
@Value("${kafka.topic}")
|
||||
private String topic;
|
||||
@Resource
|
||||
private KafkaTemplate<String, Object> kafkaTemplate;
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
public void sendMessage(String reportId) {
|
||||
Metric metric = new Metric();
|
||||
metric.setReportId(reportId);
|
||||
metric.setThreadName("tearDown Thread Group"); // 发送停止消息
|
||||
try {
|
||||
this.kafkaTemplate.send(topic, objectMapper.writeValueAsString(metric));
|
||||
} catch (JsonProcessingException e) {
|
||||
LogUtil.error("发送停止消息失败", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package io.metersphere.performance.engine.producer;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class Metric {
|
||||
@JsonProperty("test.id")
|
||||
private String testId;
|
||||
@JsonProperty("test.name")
|
||||
private String testName;
|
||||
@JsonProperty("test.startTime")
|
||||
private Long clusterStartTime;
|
||||
@JsonProperty("test.reportId")
|
||||
private String reportId;
|
||||
@JsonProperty("ContentType")
|
||||
private String contentType;
|
||||
@JsonProperty("IdleTime")
|
||||
private Integer idleTime;
|
||||
@JsonProperty("ElapsedTime")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
|
||||
private Date elapsedTime;
|
||||
@JsonProperty("ErrorCount")
|
||||
private Integer errorCount;
|
||||
@JsonProperty("Timestamp")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
|
||||
private Date timestamp;
|
||||
@JsonProperty("URL")
|
||||
private String url;
|
||||
@JsonProperty("SampleStartTime")
|
||||
private String sampleStartTime;
|
||||
@JsonProperty("Success")
|
||||
private Boolean success;
|
||||
@JsonProperty("Bytes")
|
||||
private Integer bytes;
|
||||
@JsonProperty("SentBytes")
|
||||
private Integer sentBytes;
|
||||
@JsonProperty("AllThreads")
|
||||
private Integer allThreads;
|
||||
@JsonProperty("TestElement.name")
|
||||
private String testElementName;
|
||||
@JsonProperty("DataType")
|
||||
private String dataType;
|
||||
@JsonProperty("ResponseTime")
|
||||
private Integer responseTime;
|
||||
@JsonProperty("SampleCount")
|
||||
private Integer sampleCount;
|
||||
@JsonProperty("FailureMessage")
|
||||
private String failureMessage;
|
||||
@JsonProperty("ConnectTime")
|
||||
private Integer connectTime;
|
||||
@JsonProperty("ResponseCode")
|
||||
private String responseCode;
|
||||
@JsonProperty("TestStartTime")
|
||||
private Long testStartTime;
|
||||
@JsonProperty("AssertionResults")
|
||||
private List<Object> assertionResults;
|
||||
@JsonProperty("Latency")
|
||||
private Integer latency;
|
||||
@JsonProperty("InjectorHostname")
|
||||
private String injectorHostname;
|
||||
@JsonProperty("GrpThreads")
|
||||
private Integer grpThreads;
|
||||
@JsonProperty("SampleEndTime")
|
||||
private String sampleEndTime;
|
||||
@JsonProperty("BodySize")
|
||||
private Long bodySize;
|
||||
@JsonProperty("ThreadName")
|
||||
private String threadName;
|
||||
@JsonProperty("SampleLabel")
|
||||
private String sampleLabel;
|
||||
|
||||
}
|
|
@ -21,6 +21,7 @@ import io.metersphere.i18n.Translator;
|
|||
import io.metersphere.job.sechedule.PerformanceTestJob;
|
||||
import io.metersphere.performance.engine.Engine;
|
||||
import io.metersphere.performance.engine.EngineFactory;
|
||||
import io.metersphere.performance.engine.producer.LoadTestProducer;
|
||||
import io.metersphere.service.FileService;
|
||||
import io.metersphere.service.QuotaService;
|
||||
import io.metersphere.service.ScheduleService;
|
||||
|
@ -75,6 +76,8 @@ public class PerformanceTestService {
|
|||
private TestCaseService testCaseService;
|
||||
@Resource
|
||||
private TestResourcePoolMapper testResourcePoolMapper;
|
||||
@Resource
|
||||
private LoadTestProducer loadTestProducer;
|
||||
|
||||
public List<LoadTestDTO> list(QueryTestPlanRequest request) {
|
||||
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
|
||||
|
@ -437,6 +440,8 @@ public class PerformanceTestService {
|
|||
reportService.deleteReport(reportId);
|
||||
} else {
|
||||
stopEngine(reportId);
|
||||
// 发送测试停止消息
|
||||
loadTestProducer.sendMessage(reportId);
|
||||
// 停止测试之后设置报告的状态
|
||||
reportService.updateStatus(reportId, PerformanceTestStatus.Completed.name());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue