From 367fbc72c4e9d807247d35781da69e4cf92fcf7d Mon Sep 17 00:00:00 2001 From: notshivansh Date: Sat, 26 Oct 2024 01:41:10 +0530 Subject: [PATCH] add response time in multiple exec tests --- .../components/shared/SampleDataComponent.jsx | 7 ++++++- .../workflow_node_executor/YamlNodeExecutor.java | 5 +++-- .../src/main/java/com/akto/runtime/utils/Utils.java | 12 +++++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/shared/SampleDataComponent.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/shared/SampleDataComponent.jsx index 60ec1782f1..0ff8a01173 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/shared/SampleDataComponent.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/shared/SampleDataComponent.jsx @@ -18,6 +18,7 @@ function SampleDataComponent(props) { const [popoverActive, setPopoverActive] = useState({}); const [lineNumbers, setLineNumbers] = useState({request: [], response: []}) const [currentIndex, setCurrentIndex] = useState({request: 0, response: 0}) + const [responseTime, setResponseTime] = useState(undefined) const ref = useRef(null) @@ -30,6 +31,9 @@ function SampleDataComponent(props) { } let responseJson = func.responseJson(parsed, sampleData?.highlightPaths) let requestJson = func.requestJson(parsed, sampleData?.highlightPaths) + + let responseTime = parsed?.responseTime; + setResponseTime(responseTime) let originalParsed; try{ @@ -201,7 +205,8 @@ function SampleDataComponent(props) { - {func.toSentenceCase(type)} + {func.toSentenceCase(type)} + { type=="response" && responseTime ? (` (${responseTime} ms)`) : "" } {isNewDiff ? diff --git a/apps/testing/src/main/java/com/akto/testing/workflow_node_executor/YamlNodeExecutor.java b/apps/testing/src/main/java/com/akto/testing/workflow_node_executor/YamlNodeExecutor.java index 677fd7fd21..cd0a0b09fb 100644 --- a/apps/testing/src/main/java/com/akto/testing/workflow_node_executor/YamlNodeExecutor.java +++ b/apps/testing/src/main/java/com/akto/testing/workflow_node_executor/YamlNodeExecutor.java @@ -162,7 +162,8 @@ public NodeResult processNode(Node node, Map varMap, Boolean all memory.reset(apiInfoKey.getApiCollectionId(), apiInfoKey.getUrl(), apiInfoKey.getMethod().name()); } tsAfterReq = Context.nowInMillis(); - responseTimeArr.add(tsAfterReq - tsBeforeReq); + int responseTime = tsAfterReq - tsBeforeReq; + responseTimeArr.add(responseTime); ExecutionResult attempt = new ExecutionResult(singleReq.getSuccess(), singleReq.getErrMsg(), testReq.getRequest(), testResponse); TestResult res = executor.validate(attempt, sampleRawApi, varMap, logId, validatorNode, yamlNodeDetails.getApiInfoKey()); if (res != null) { @@ -170,7 +171,7 @@ public NodeResult processNode(Node node, Map varMap, Boolean all } vulnerable = res.getVulnerable(); try { - message.add(convertOriginalReqRespToString(testReq.getRequest(), testResponse)); + message.add(convertOriginalReqRespToString(testReq.getRequest(), testResponse, responseTime)); } catch (Exception e) { ; } diff --git a/libs/utils/src/main/java/com/akto/runtime/utils/Utils.java b/libs/utils/src/main/java/com/akto/runtime/utils/Utils.java index e8fd30c157..701a39c3b9 100644 --- a/libs/utils/src/main/java/com/akto/runtime/utils/Utils.java +++ b/libs/utils/src/main/java/com/akto/runtime/utils/Utils.java @@ -52,7 +52,17 @@ public static Properties configProperties(String kafkaBrokerUrl, String groupIdC return properties; } + public static String convertOriginalReqRespToString(OriginalHttpRequest request, OriginalHttpResponse response, int responseTime) { + BasicDBObject ret = convertOriginalReqRespToStringUtil(request, response); + ret.append("responseTime", responseTime); + return ret.toString(); + } + public static String convertOriginalReqRespToString(OriginalHttpRequest request, OriginalHttpResponse response) { + return convertOriginalReqRespToStringUtil(request, response).toString(); + } + + public static BasicDBObject convertOriginalReqRespToStringUtil(OriginalHttpRequest request, OriginalHttpResponse response) { BasicDBObject req = new BasicDBObject(); if (request != null) { req.put("url", request.getUrl()); @@ -74,7 +84,7 @@ public static String convertOriginalReqRespToString(OriginalHttpRequest request, ret.put("request", req); ret.put("response", resp); - return ret.toString(); + return ret; } public static Map parseCookie(List cookieList){