Skip to content

Commit

Permalink
Merge pull request #1386 from akto-api-security/hotfix/logs_dep_analyser
Browse files Browse the repository at this point in the history
logs for dependency analyser syncwithdb
  • Loading branch information
avneesh-akto authored Aug 21, 2024
2 parents 233df68 + 6208bdb commit da8fb0b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.mongodb.client.model.*;
import org.bson.Document;
import org.bson.conversions.Bson;
import com.akto.log.LoggerMaker;
import com.akto.log.LoggerMaker.LogDb;

import java.util.*;

Expand All @@ -31,6 +33,7 @@ public class DependencyAnalyser {
Store valueStore; // this is to store all the values seen in response payload
Store urlValueStore; // this is to store all the url$value seen in response payload
Store urlParamValueStore; // this is to store all the url$param$value seen in response payload
private static final LoggerMaker loggerMaker = new LoggerMaker(DependencyAnalyser.class, LogDb.RUNTIME);

Map<String, Set<String>> urlsToResponseParam = new HashMap<>();

Expand Down Expand Up @@ -354,10 +357,12 @@ public void mergeNodes() {
}

public void syncWithDb() {
loggerMaker.infoAndAddToDb("Syncing dependency analyser nodes");
ArrayList<WriteModel<DependencyNode>> bulkUpdates1 = new ArrayList<>();
ArrayList<WriteModel<DependencyNode>> bulkUpdates2 = new ArrayList<>();
ArrayList<WriteModel<DependencyNode>> bulkUpdates3 = new ArrayList<>();

loggerMaker.infoAndAddToDb("dependency analyser nodes size: " + nodes.size());
mergeNodes();

for (DependencyNode dependencyNode: nodes.values()) {
Expand Down Expand Up @@ -449,6 +454,10 @@ filter3, update3, new UpdateOptions().upsert(false)
}
}

loggerMaker.infoAndAddToDb("dependency analyser bulkUpdates1 size: " + bulkUpdates1.size());
loggerMaker.infoAndAddToDb("dependency analyser bulkUpdates2 size: " + bulkUpdates2.size());
loggerMaker.infoAndAddToDb("dependency analyser bulkUpdates3 size: " + bulkUpdates3.size());

// ordered has to be true or else won't work
if (bulkUpdates1.size() > 0) DependencyNodeDao.instance.getMCollection().bulkWrite(bulkUpdates1, new BulkWriteOptions().ordered(false));
if (bulkUpdates2.size() > 0) DependencyNodeDao.instance.getMCollection().bulkWrite(bulkUpdates2, new BulkWriteOptions().ordered(false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.akto.hybrid_runtime.APICatalogSync;
import com.akto.hybrid_runtime.URLAggregator;
import com.akto.hybrid_runtime.policies.AuthPolicy;
import com.akto.log.LoggerMaker;
import com.akto.util.HTTPHeadersExample;
import com.akto.util.JSONUtils;
import com.google.common.base.Charsets;
Expand All @@ -31,6 +32,7 @@ public class DependencyAnalyser {
Store valueStore; // this is to store all the values seen in response payload
Store urlValueStore; // this is to store all the url$value seen in response payload
Store urlParamValueStore; // this is to store all the url$param$value seen in response payload
private static final LoggerMaker loggerMaker = new LoggerMaker(DependencyAnalyser.class, LoggerMaker.LogDb.RUNTIME);

Map<String, Set<String>> urlsToResponseParam = new HashMap<>();

Expand Down Expand Up @@ -343,10 +345,12 @@ public void mergeNodes() {
}

public void syncWithDb() {
loggerMaker.infoAndAddToDb("Syncing dependency analyser nodes");
ArrayList<WriteModel<DependencyNode>> bulkUpdates1 = new ArrayList<>();
ArrayList<WriteModel<DependencyNode>> bulkUpdates2 = new ArrayList<>();
ArrayList<WriteModel<DependencyNode>> bulkUpdates3 = new ArrayList<>();

loggerMaker.infoAndAddToDb("dependency analyser nodes size: " + nodes.size());
mergeNodes();

for (DependencyNode dependencyNode: nodes.values()) {
Expand Down Expand Up @@ -439,8 +443,10 @@ filter3, update3, new UpdateOptions().upsert(false)
}

// ordered has to be true or else won't work


loggerMaker.infoAndAddToDb("dependency analyser bulkUpdates1 size: " + bulkUpdates1.size());
loggerMaker.infoAndAddToDb("dependency analyser bulkUpdates2 size: " + bulkUpdates2.size());
loggerMaker.infoAndAddToDb("dependency analyser bulkUpdates3 size: " + bulkUpdates3.size());


if (bulkUpdates1.size() > 0) DependencyNodeDao.instance.getMCollection().bulkWrite(bulkUpdates1, new BulkWriteOptions().ordered(false));
Expand Down

0 comments on commit da8fb0b

Please sign in to comment.