refactor(性能测试): 同步各个节点的启动时间
This commit is contained in:
parent
41b387b8a6
commit
26d7a007a8
|
@ -29,6 +29,7 @@ public class ShiroUtils {
|
|||
filterChainDefinitionMap.put("/display/file/**", "anon");
|
||||
filterChainDefinitionMap.put("/jmeter/download/**", "anon");
|
||||
filterChainDefinitionMap.put("/jmeter/ping", "anon");
|
||||
filterChainDefinitionMap.put("/jmeter/ready/**", "anon");
|
||||
filterChainDefinitionMap.put("/authsource/list/allenable", "anon");
|
||||
filterChainDefinitionMap.put("/sso/signin", "anon");
|
||||
filterChainDefinitionMap.put("/sso/callback", "anon");
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package io.metersphere.performance.controller;
|
||||
|
||||
|
||||
import io.metersphere.commons.utils.WeakConcurrentHashMap;
|
||||
import io.metersphere.controller.handler.annotation.NoResultHolder;
|
||||
import io.metersphere.performance.service.JmeterFileService;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
|
@ -12,25 +14,41 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("jmeter")
|
||||
public class JmeterFileController {
|
||||
@Resource
|
||||
private JmeterFileService jmeterFileService;
|
||||
private final WeakConcurrentHashMap<String, List<Double>> readyMap = new WeakConcurrentHashMap<>(600_000);// 默认保留10分钟
|
||||
|
||||
@GetMapping("ping")
|
||||
public String checkStatus() {
|
||||
return "PONG";
|
||||
}
|
||||
|
||||
@GetMapping("ready")
|
||||
@NoResultHolder
|
||||
public long ready(@RequestParam("reportId") String reportId, @RequestParam("ratio") String ratio,
|
||||
@RequestParam("resourceIndex") int resourceIndex) {
|
||||
try {
|
||||
List<Double> ratios = readyMap.getOrDefault(reportId, Arrays.stream(ratio.split(",")).map(Double::parseDouble).collect(Collectors.toList()));
|
||||
ratios.set(resourceIndex, -1.0);
|
||||
readyMap.put(reportId, ratios);
|
||||
return ratios.stream().filter(r -> r > 0).count();
|
||||
} catch (Exception e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("download")
|
||||
public ResponseEntity<byte[]> downloadJmeterFiles(@RequestParam("testId") String testId, @RequestParam("resourceId") String resourceId,
|
||||
@RequestParam("ratio") String ratio,
|
||||
@RequestParam("reportId") String reportId, @RequestParam("resourceIndex") int resourceIndex) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
double[] ratios = Arrays.stream(ratio.split(",")).mapToDouble(Double::parseDouble).toArray();
|
||||
byte[] bytes = jmeterFileService.downloadZip(testId, ratios, startTime, reportId, resourceIndex);
|
||||
byte[] bytes = jmeterFileService.downloadZip(testId, ratios, reportId, resourceIndex);
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType("application/octet-stream"))
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + testId + ".zip\"")
|
||||
|
|
|
@ -10,7 +10,6 @@ public class EngineContext {
|
|||
private String fileType;
|
||||
private String content;
|
||||
private String resourcePoolId;
|
||||
private Long startTime;
|
||||
private String reportId;
|
||||
private Integer resourceIndex;
|
||||
private Map<String, Object> properties = new HashMap<>();
|
||||
|
@ -76,14 +75,6 @@ public class EngineContext {
|
|||
this.resourcePoolId = resourcePoolId;
|
||||
}
|
||||
|
||||
public Long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(Long startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public String getReportId() {
|
||||
return reportId;
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ public class EngineFactory {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static EngineContext createContext(LoadTestWithBLOBs loadTest, double[] ratios, long startTime, String reportId, int resourceIndex) {
|
||||
public static EngineContext createContext(LoadTestWithBLOBs loadTest, double[] ratios, String reportId, int resourceIndex) {
|
||||
final List<FileMetadata> fileMetadataList = performanceTestService.getFileMetadataByTestId(loadTest.getId());
|
||||
if (org.springframework.util.CollectionUtils.isEmpty(fileMetadataList)) {
|
||||
MSException.throwException(Translator.get("run_load_test_file_not_found") + loadTest.getId());
|
||||
|
@ -104,7 +104,6 @@ public class EngineFactory {
|
|||
engineContext.setNamespace(loadTest.getProjectId());
|
||||
engineContext.setFileType(FileType.JMX.name());
|
||||
engineContext.setResourcePoolId(loadTest.getTestResourcePoolId());
|
||||
engineContext.setStartTime(startTime);
|
||||
engineContext.setReportId(reportId);
|
||||
engineContext.setResourceIndex(resourceIndex);
|
||||
|
||||
|
|
|
@ -655,7 +655,6 @@ public class JmeterDocumentParser implements DocumentParser {
|
|||
// 添加关联关系 test.id test.name test.startTime test.reportId
|
||||
collectionProp.appendChild(createKafkaProp(document, "test.id", context.getTestId()));
|
||||
collectionProp.appendChild(createKafkaProp(document, "test.name", context.getTestName()));
|
||||
collectionProp.appendChild(createKafkaProp(document, "test.startTime", context.getStartTime().toString()));
|
||||
collectionProp.appendChild(createKafkaProp(document, "test.reportId", context.getReportId()));
|
||||
|
||||
elementProp.appendChild(collectionProp);
|
||||
|
|
|
@ -29,10 +29,10 @@ public class JmeterFileService {
|
|||
@Resource
|
||||
private ExtLoadTestReportMapper extLoadTestReportMapper;
|
||||
|
||||
public byte[] downloadZip(String testId, double[] ratios, long startTime, String reportId, int resourceIndex) {
|
||||
public byte[] downloadZip(String testId, double[] ratios, String reportId, int resourceIndex) {
|
||||
try {
|
||||
LoadTestWithBLOBs loadTest = loadTestMapper.selectByPrimaryKey(testId);
|
||||
EngineContext context = EngineFactory.createContext(loadTest, ratios, startTime, reportId, resourceIndex);
|
||||
EngineContext context = EngineFactory.createContext(loadTest, ratios, reportId, resourceIndex);
|
||||
return zipFilesToByteArray(context);
|
||||
} catch (MSException e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
|
|
Loading…
Reference in New Issue