Skip to content

Commit

Permalink
Merge pull request #1865 from akto-api-security/feature/logs_in_fetch…
Browse files Browse the repository at this point in the history
…ing_test_run_result

added logs
  • Loading branch information
Ark2307 authored Dec 25, 2024
2 parents b0c74eb + d17c4b5 commit 5f51726
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.bson.conversions.Bson;
import org.bson.types.ObjectId;

import java.time.Instant;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -593,14 +594,18 @@ public String fetchTestingRunResults() {
addActionError("Invalid test summary id");
return ERROR.toUpperCase();
}


if (testingRunResultSummaryHexId != null) loggerMaker.infoAndAddToDb("fetchTestingRunResults called for hexId=" + testingRunResultSummaryHexId);
if (queryMode != null) loggerMaker.infoAndAddToDb("fetchTestingRunResults called for queryMode="+queryMode);

int timeNow = Context.now();
Bson ignoredIssuesFilters = Filters.and(
Filters.in(TestingRunIssues.TEST_RUN_ISSUES_STATUS, "IGNORED"),
Filters.in(TestingRunIssues.LATEST_TESTING_RUN_SUMMARY_ID, testingRunResultSummaryId)
);
List<TestingRunIssues> issueslist = TestingRunIssuesDao.instance.findAll(ignoredIssuesFilters, Projections.include("_id"));
loggerMaker.infoAndAddToDb("[" + (Context.now() - timeNow) + "] Fetched testing run issues of size: " + issueslist.size(), LogDb.DASHBOARD);

List<Bson> testingRunResultFilters = prepareTestRunResultsFilters(testingRunResultSummaryId, queryMode);

Expand All @@ -618,21 +623,27 @@ public String fetchTestingRunResults() {
int pageLimit = limit <= 0 ? 150 : limit;
Bson sortStage = prepareTestingRunResultCustomSorting(sortKey, sortOrder);

timeNow = Context.now();
Bson filters = testingRunResultFilters.isEmpty() ? Filters.empty() : Filters.and(testingRunResultFilters);
this.testingRunResults = TestingRunResultDao.instance
.fetchLatestTestingRunResultWithCustomAggregations(filters, pageLimit, skip, sortStage);
loggerMaker.infoAndAddToDb("[" + (Context.now() - timeNow) + "] Fetched testing run results of size: " + testingRunResults.size(), LogDb.DASHBOARD);

timeNow = Context.now();
removeTestingRunResultsByIssues(testingRunResults, issueslist, false);
loggerMaker.infoAndAddToDb("[" + (Context.now() - timeNow) + "] Removed ignored issues from testing run results. Current size of testing run results: " + testingRunResults.size(), LogDb.DASHBOARD);

testCountMap = new HashMap<>();
for(QueryMode qm : QueryMode.values()) {
if(qm.equals(QueryMode.ALL) || qm.equals(QueryMode.SKIPPED_EXEC_NO_ACTION)) {
continue;
}

timeNow = Context.now();
int count = (int) TestingRunResultDao.instance.count(Filters.and(
prepareTestRunResultsFilters(testingRunResultSummaryId, qm)
));
loggerMaker.infoAndAddToDb("[" + (Context.now() - timeNow) + "] Fetched total count of testingRunResults for: " + qm.name(), LogDb.DASHBOARD);
testCountMap.put(qm.toString(), count);
}

Expand All @@ -642,18 +653,24 @@ public String fetchTestingRunResults() {
loggerMaker.errorAndAddToDb(e, "error in fetchLatestTestingRunResult: " + e);
}

timeNow = Context.now();
loggerMaker.infoAndAddToDb("fetchTestingRunResults completed in: " + (Context.now() - timeNow), LogDb.DASHBOARD);

return SUCCESS.toUpperCase();
}

public static void removeTestingRunResultsByIssues(List<TestingRunResult> testingRunResults,
List<TestingRunIssues> testingRunIssues,
boolean retainByIssues) {
long startTime = System.currentTimeMillis();

Set<String> issuesSet = new HashSet<>();
for (TestingRunIssues issue : testingRunIssues) {
String apiInfoKeyString = issue.getId().getApiInfoKey().toString();
String key = apiInfoKeyString + "|" + issue.getId().getTestSubCategory();
issuesSet.add(key);
}
loggerMaker.infoAndAddToDb("Total issues to be removed from TestingRunResults list: " + issuesSet.size(), LogDb.DASHBOARD);

Iterator<TestingRunResult> resultIterator = testingRunResults.iterator();

Expand All @@ -670,6 +687,10 @@ public static void removeTestingRunResultsByIssues(List<TestingRunResult> testin
resultIterator.remove();
}
}

long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
loggerMaker.infoAndAddToDb("[" + Instant.now() + "] Removed elements from TestingRunResults list in " + duration + " ms", LogDb.DASHBOARD);
}

private Map<String, List<String>> reportFilterList;
Expand Down

0 comments on commit 5f51726

Please sign in to comment.