Skip to content

Commit

Permalink
add tess results fetch api
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushaga14 committed Sep 21, 2024
1 parent 6e3bd39 commit 5e0a88e
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public void setTestSourceConfig(TestSourceConfig testSourceConfig) {
String logicalGroupName;
BasicDBList issuesIds;
List<YamlTemplate> activeAdvancedFilters;
List<TestingRunResultSummary> currentlyRunningTests;

public BasicDBList getIssuesIds() {
return issuesIds;
Expand Down Expand Up @@ -1977,6 +1978,15 @@ public String fetchActiveAdvancedFilters(){
return Action.SUCCESS.toUpperCase();
}

public String fetchStatusOfTests(){
try {
this.currentlyRunningTests = DbLayer.fetchStatusOfTests();
} catch (Exception e) {
return Action.ERROR.toUpperCase();
}
return Action.SUCCESS.toUpperCase();
}

public List<CustomDataTypeMapper> getCustomDataTypes() {
return customDataTypes;
}
Expand Down Expand Up @@ -2883,4 +2893,12 @@ public void setActiveAdvancedFilters(List<YamlTemplate> activeAdvancedFilters) {
this.activeAdvancedFilters = activeAdvancedFilters;
}

public List<TestingRunResultSummary> getCurrentlyRunningTests() {
return currentlyRunningTests;
}

public void setCurrentlyRunningTests(List<TestingRunResultSummary> currentlyRunningTests) {
this.currentlyRunningTests = currentlyRunningTests;
}

}
11 changes: 11 additions & 0 deletions apps/database-abstractor/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,17 @@
</result>
</action>

<action name="api/fetchStatusOfTests" class="com.akto.action.DbAction" method="fetchStatusOfTests">
<interceptor-ref name="json"/>
<interceptor-ref name="defaultStack" />
<result name="SUCCESS" type="json"/>
<result name="ERROR" type="json">
<param name="statusCode">422</param>
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">^actionErrors.*</param>
</result>
</action>

</package>

</struts>
35 changes: 35 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/ClientActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.akto.bulk_update_util.ApiInfoBulkUpdate;
import com.akto.dao.SetupDao;
import com.akto.dao.context.Context;
import com.akto.dao.testing.TestingRunResultSummariesDao;
import com.akto.database_abstractor_authenticator.JwtAuthenticator;
import com.akto.dto.*;
import com.akto.dto.ApiInfo.ApiInfoKey;
Expand Down Expand Up @@ -3128,4 +3129,38 @@ public List<YamlTemplate> fetchActiveAdvancedFilters(){
return respList;
}

public List<TestingRunResultSummary> fetchStatusOfTests() {
Map<String, List<String>> headers = buildHeaders();
List<TestingRunResultSummary> result = new ArrayList<>();
OriginalHttpRequest request = new OriginalHttpRequest(url + "/fetchStatusOfTests", "", "GET", null, headers, "");
try {
OriginalHttpResponse response = ApiExecutor.sendRequestBackOff(request, true, null, false, null);
String responsePayload = response.getBody();
if (response.getStatusCode() != 200 || responsePayload == null) {
loggerMaker.errorAndAddToDb("non 2xx response in fetchStatusOfTests", LoggerMaker.LogDb.RUNTIME);
return null;
}
BasicDBObject payloadObj;
try {
payloadObj = BasicDBObject.parse(responsePayload);
BasicDBList tests = (BasicDBList) payloadObj.get("currentlyRunningTests");
for (Object test: tests) {
BasicDBObject obj = (BasicDBObject) test;
obj.remove("id");
obj.remove("testingRunId");
TestingRunResultSummary res = objectMapper.readValue(obj.toJson(), TestingRunResultSummary.class);
res.setId(new ObjectId(obj.getString("hexId")));
res.setTestingRunId(new ObjectId(obj.getString("testingRunHexId")));
result.add(res);
}
} catch(Exception e) {
loggerMaker.errorAndAddToDb("error extracting response in fetchStatusOfTests" + e, LoggerMaker.LogDb.RUNTIME);
}

return result;
} catch (Exception e) {
loggerMaker.errorAndAddToDb("error in fetchStatusOfTests" + e, LoggerMaker.LogDb.RUNTIME);
return null;
}
}
}
2 changes: 2 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/DataActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,6 @@ public abstract class DataActor {
public abstract void insertProtectionLog(Log log);

public abstract List<YamlTemplate> fetchActiveAdvancedFilters();

public abstract List<TestingRunResultSummary> fetchStatusOfTests();
}
4 changes: 4 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/DbActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,8 @@ public List<YamlTemplate> fetchActiveAdvancedFilters(){
return DbLayer.fetchActiveFilterTemplates();
}

public List<TestingRunResultSummary> fetchStatusOfTests() {
return DbLayer.fetchStatusOfTests();
}

}
12 changes: 12 additions & 0 deletions libs/utils/src/main/java/com/akto/data_actor/DbLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -910,4 +910,16 @@ public static List<YamlTemplate> fetchActiveFilterTemplates(){
Filters.ne(YamlTemplate.INACTIVE, false)
);
}

public static List<TestingRunResultSummary> fetchStatusOfTests() {
int timeFilter = Context.now() - 30 * 60;
List<TestingRunResultSummary> currentRunningTests = TestingRunResultSummariesDao.instance.findAll(
Filters.gte(TestingRunResultSummary.START_TIMESTAMP, timeFilter),
Projections.include("_id", TestingRunResultSummary.STATE, TestingRunResultSummary.TESTING_RUN_ID)
);
for (TestingRunResultSummary summary: currentRunningTests) {
summary.setTestingRunHexId(summary.getTestingRunId().toHexString());
}
return currentRunningTests;
}
}

0 comments on commit 5e0a88e

Please sign in to comment.