@@ -98,6 +98,20 @@ public class ClientActor extends DataActor {
9898 private static final CodecRegistry codecRegistry = DaoInit .createCodecRegistry ();
9999 public static final String CYBORG_URL = "https://cyborg.akto.io" ;
100100 private static ExecutorService threadPool = Executors .newFixedThreadPool (maxConcurrentBatchWrites );
101+ private static final int maxConcurrentLogWrites = getMaxConcurrentLogWrites ();
102+ final private static ExecutorService logThreadPool = Executors .newFixedThreadPool (maxConcurrentLogWrites );
103+
104+ private static int getMaxConcurrentLogWrites () {
105+ String envValue = System .getenv ("MAX_CONCURRENT_LOG_WRITES" );
106+ if (envValue != null ) {
107+ try {
108+ return Integer .parseInt (envValue );
109+ } catch (NumberFormatException e ) {
110+ // fall through to default
111+ }
112+ }
113+ return 50 ;
114+ }
101115
102116 /**
103117 * Dedicated thread pool for agent traffic log HTTP writes.
@@ -1257,44 +1271,37 @@ public void createCollectionSimpleForVpc(int vxlanId, String vpcId, List<Collect
12571271 }
12581272 }
12591273
1260- public void insertRuntimeLog (Log log ) {
1261- Map <String , List <String >> headers = buildHeaders ();
1262- BasicDBObject obj = new BasicDBObject ();
1263- BasicDBObject logObj = new BasicDBObject ();
1264- logObj .put ("key" , log .getKey ());
1265- logObj .put ("log" , log .getLog ());
1266- logObj .put ("timestamp" , log .getTimestamp ());
1267- obj .put ("log" , logObj );
1268- OriginalHttpRequest request = new OriginalHttpRequest (url + "/insertRuntimeLog" , "" , "POST" , obj .toString (), headers , "" );
1269- try {
1270- OriginalHttpResponse response = ApiExecutor .sendRequestBackOff (request , true , null , false , null );
1271- String responsePayload = response .getBody ();
1272- if (response .getStatusCode () != 200 || responsePayload == null ) {
1273- loggerMaker .info ("non 2xx response in insertRuntimeLog" );
1274- return ;
1274+ private void insertLogAsync (Log log , String endpoint ) {
1275+ logThreadPool .submit (() -> {
1276+ try {
1277+ Map <String , List <String >> headers = buildHeaders ();
1278+ BasicDBObject obj = new BasicDBObject ();
1279+ BasicDBObject logObj = new BasicDBObject ();
1280+ logObj .put ("key" , log .getKey ());
1281+ logObj .put ("log" , log .getLog ());
1282+ logObj .put ("timestamp" , log .getTimestamp ());
1283+ obj .put ("log" , logObj );
1284+ OriginalHttpRequest request = new OriginalHttpRequest (url + endpoint , "" , "POST" , obj .toString (), headers , "" );
1285+ OriginalHttpResponse response = ApiExecutor .sendRequestBackOff (request , true , null , false , null );
1286+ if (response .getStatusCode () != 200 || response .getBody () == null ) {
1287+ loggerMaker .info ("non 2xx response in " + endpoint );
1288+ }
1289+ } catch (Exception e ) {
1290+ loggerMaker .error ("error in " + endpoint + ": " + e );
12751291 }
1276- } catch (Exception e ) {
1277- loggerMaker .error ("error in insertRuntimeLog" + e );
1278- return ;
1279- }
1292+ });
1293+ }
1294+
1295+ public void insertRuntimeLog (Log log ) {
1296+ insertLogAsync (log , "/insertRuntimeLog" );
12801297 }
12811298
12821299 public void insertAnalyserLog (Log log ) {
1283- Map <String , List <String >> headers = buildHeaders ();
1284- BasicDBObject obj = new BasicDBObject ();
1285- obj .put ("log" , log );
1286- OriginalHttpRequest request = new OriginalHttpRequest (url + "/insertAnalyserLog" , "" , "POST" , obj .toString (), headers , "" );
1287- try {
1288- OriginalHttpResponse response = ApiExecutor .sendRequestBackOff (request , true , null , false , null );
1289- String responsePayload = response .getBody ();
1290- if (response .getStatusCode () != 200 || responsePayload == null ) {
1291- loggerMaker .errorAndAddToDb ("non 2xx response in insertAnalyserLog" , LoggerMaker .LogDb .RUNTIME );
1292- return ;
1293- }
1294- } catch (Exception e ) {
1295- loggerMaker .errorAndAddToDb ("error in insertAnalyserLog" + e , LoggerMaker .LogDb .RUNTIME );
1296- return ;
1297- }
1300+ insertLogAsync (log , "/insertAnalyserLog" );
1301+ }
1302+
1303+ public void insertTestingLog (Log log ) {
1304+ insertLogAsync (log , "/insertTestingLog" );
12981305 }
12991306
13001307 public void modifyHybridSaasSetting (boolean isHybridSaas ) {
@@ -3313,28 +3320,6 @@ public void modifyHybridTestingSetting(boolean hybridTestingEnabled) {
33133320 }
33143321 }
33153322
3316- public void insertTestingLog (Log log ) {
3317- Map <String , List <String >> headers = buildHeaders ();
3318- BasicDBObject obj = new BasicDBObject ();
3319- BasicDBObject logObj = new BasicDBObject ();
3320- logObj .put ("key" , log .getKey ());
3321- logObj .put ("log" , log .getLog ());
3322- logObj .put ("timestamp" , log .getTimestamp ());
3323- obj .put ("log" , logObj );
3324- OriginalHttpRequest request = new OriginalHttpRequest (url + "/insertTestingLog" , "" , "POST" , obj .toString (), headers , "" );
3325- try {
3326- OriginalHttpResponse response = ApiExecutor .sendRequestBackOff (request , true , null , false , null );
3327- String responsePayload = response .getBody ();
3328- if (response .getStatusCode () != 200 || responsePayload == null ) {
3329- loggerMaker .info ("non 2xx response in insertTestingLog" );
3330- return ;
3331- }
3332- } catch (Exception e ) {
3333- loggerMaker .error ("error in insertTestingLog" + e );
3334- return ;
3335- }
3336- }
3337-
33383323 public void bulkWriteDependencyNodes (List <DependencyNode > dependencyNodeList ) {
33393324 BasicDBObject obj = new BasicDBObject ();
33403325 obj .put ("dependencyNodeList" , dependencyNodeList );
0 commit comments