From 198bb154c481101b91094fa7d41284e4468926dd Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 25 Feb 2021 13:27:47 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E6=89=8B=E5=8A=A8=E5=81=9C=E6=AD=A2=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=8F=91=E9=80=81=E9=80=9A=E7=9F=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/producer/LoadTestProducer.java | 14 ++-- .../performance/engine/producer/Log.java | 13 ++++ .../performance/engine/producer/Metric.java | 77 ------------------- 3 files changed, 22 insertions(+), 82 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/performance/engine/producer/Log.java delete mode 100644 backend/src/main/java/io/metersphere/performance/engine/producer/Metric.java diff --git a/backend/src/main/java/io/metersphere/performance/engine/producer/LoadTestProducer.java b/backend/src/main/java/io/metersphere/performance/engine/producer/LoadTestProducer.java index c8a6bf3c62..420d9f4adc 100644 --- a/backend/src/main/java/io/metersphere/performance/engine/producer/LoadTestProducer.java +++ b/backend/src/main/java/io/metersphere/performance/engine/producer/LoadTestProducer.java @@ -12,7 +12,7 @@ import javax.annotation.Resource; @Service public class LoadTestProducer { - @Value("${kafka.topic}") + @Value("${kafka.log.topic}") private String topic; @Resource private KafkaTemplate kafkaTemplate; @@ -20,11 +20,15 @@ public class LoadTestProducer { private ObjectMapper objectMapper; public void sendMessage(String reportId) { - Metric metric = new Metric(); - metric.setReportId(reportId); - metric.setThreadName("tearDown Thread Group"); // 发送停止消息 + Log log = Log.builder() + .reportId(reportId) + .resourceId("none") + .resourceIndex(0) + .content("Notifying test listeners of end of test") + .build(); + try { - this.kafkaTemplate.send(topic, objectMapper.writeValueAsString(metric)); + this.kafkaTemplate.send(topic, objectMapper.writeValueAsString(log)); } catch (JsonProcessingException e) { LogUtil.error("发送停止消息失败", e); } diff --git a/backend/src/main/java/io/metersphere/performance/engine/producer/Log.java b/backend/src/main/java/io/metersphere/performance/engine/producer/Log.java new file mode 100644 index 0000000000..813d932c20 --- /dev/null +++ b/backend/src/main/java/io/metersphere/performance/engine/producer/Log.java @@ -0,0 +1,13 @@ +package io.metersphere.performance.engine.producer; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class Log { + private String reportId; + private String resourceId; + private int resourceIndex; + private String content; +} diff --git a/backend/src/main/java/io/metersphere/performance/engine/producer/Metric.java b/backend/src/main/java/io/metersphere/performance/engine/producer/Metric.java deleted file mode 100644 index c2de345a7f..0000000000 --- a/backend/src/main/java/io/metersphere/performance/engine/producer/Metric.java +++ /dev/null @@ -1,77 +0,0 @@ -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 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; - -}