From cf1537545843e518b993657fd59de8ecacaa6367 Mon Sep 17 00:00:00 2001 From: Ark2307 Date: Mon, 20 May 2024 20:08:51 +0530 Subject: [PATCH 1/2] changed dibs call in crons --- .../main/java/com/akto/utils/crons/SyncCron.java | 12 +++++++----- .../utils/crons/UpdateSensitiveInfoInApiInfo.java | 13 ++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/apps/dashboard/src/main/java/com/akto/utils/crons/SyncCron.java b/apps/dashboard/src/main/java/com/akto/utils/crons/SyncCron.java index 35e904e85d..43627a792c 100644 --- a/apps/dashboard/src/main/java/com/akto/utils/crons/SyncCron.java +++ b/apps/dashboard/src/main/java/com/akto/utils/crons/SyncCron.java @@ -34,14 +34,16 @@ public class SyncCron { public void setUpUpdateCronScheduler() { scheduler.scheduleAtFixedRate(new Runnable() { public void run() { + + Context.accountId.set(1000_000); + boolean dibs = callDibs(Cluster.SYNC_CRON_INFO, 300, 60); + if(!dibs){ + loggerMaker.infoAndAddToDb("Cron for updating new parameters, new endpoints and severity score dibs not acquired, thus skipping cron", LogDb.DASHBOARD); + return; + } AccountTask.instance.executeTask(new Consumer() { @Override public void accept(Account t) { - boolean dibs = callDibs(Cluster.SYNC_CRON_INFO, 300, 60); - if(!dibs){ - loggerMaker.infoAndAddToDb("Cron for updating new parameters, new endpoints and severity score dibs not acquired, thus skipping cron", LogDb.DASHBOARD); - return; - } AccountSettings accountSettings = AccountSettingsDao.instance.findOne(AccountSettingsDao.generateFilter()); LastCronRunInfo lastRunTimerInfo = accountSettings.getLastUpdatedCronInfo(); loggerMaker.infoAndAddToDb("Cron for updating new parameters, new endpoints and severity score picked up " + accountSettings.getId(), LogDb.DASHBOARD); diff --git a/apps/dashboard/src/main/java/com/akto/utils/crons/UpdateSensitiveInfoInApiInfo.java b/apps/dashboard/src/main/java/com/akto/utils/crons/UpdateSensitiveInfoInApiInfo.java index 9bd8f716a2..740cca99af 100644 --- a/apps/dashboard/src/main/java/com/akto/utils/crons/UpdateSensitiveInfoInApiInfo.java +++ b/apps/dashboard/src/main/java/com/akto/utils/crons/UpdateSensitiveInfoInApiInfo.java @@ -6,6 +6,7 @@ import java.util.function.Consumer; import com.akto.dao.AccountSettingsDao; +import com.akto.dao.context.Context; import com.akto.dto.Account; import com.akto.dto.AccountSettings; import com.akto.log.LoggerMaker; @@ -26,14 +27,16 @@ public class UpdateSensitiveInfoInApiInfo { public void setUpSensitiveMapInApiInfoScheduler() { scheduler.scheduleAtFixedRate(new Runnable() { public void run() { + + Context.accountId.set(1000_000); + boolean dibs = callDibs(Cluster.MAP_SENSITIVE_IN_INFO, 900, 60); + if(!dibs){ + loggerMaker.infoAndAddToDb("Cron for updating new parameters, new endpoints and severity score dibs not acquired, thus skipping cron", LogDb.DASHBOARD); + return; + } AccountTask.instance.executeTask(new Consumer() { @Override public void accept(Account t) { - boolean dibs = callDibs(Cluster.MAP_SENSITIVE_IN_INFO, 900, 60); - if(!dibs){ - loggerMaker.infoAndAddToDb("Cron for mapping sensitive info to apiInfo dibs not acquired, thus skipping cron", LogDb.DASHBOARD); - return; - } AccountSettings accountSettings = AccountSettingsDao.instance.findOne(AccountSettingsDao.generateFilter()); loggerMaker.infoAndAddToDb("Cron for mapping sensitive info picked up by " + accountSettings.getId(), LogDb.DASHBOARD); LastCronRunInfo lastRunTimerInfo = accountSettings.getLastUpdatedCronInfo(); From 719770b4ca472e406401486cf1fc8b7f00c22f92 Mon Sep 17 00:00:00 2001 From: Ark2307 Date: Mon, 20 May 2024 20:23:56 +0530 Subject: [PATCH 2/2] fixing logger and added dibs to usage metric --- .../java/com/akto/listener/InitializerListener.java | 10 ++++++++-- .../akto/utils/crons/UpdateSensitiveInfoInApiInfo.java | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java b/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java index 2169bfd1d5..ff0ef0c76f 100644 --- a/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java +++ b/apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java @@ -781,7 +781,7 @@ public void accept(Account t) { ex.printStackTrace(); // or loggger would be better } } - }, 0, 5, TimeUnit.MINUTES); + }, 0, 4, TimeUnit.HOURS); } @@ -895,7 +895,7 @@ public void accept(Account t) { } }, "webhook-sener"); } - }, 0, 15, TimeUnit.MINUTES); + }, 0, 1, TimeUnit.HOURS); } static class ChangesInfo { @@ -2479,6 +2479,12 @@ public static void syncWithAkto() { public void setupUsageScheduler() { scheduler.scheduleAtFixedRate(new Runnable() { public void run() { + Context.accountId.set(1000_000); + boolean dibs = callDibs("usage-scheduler", 60*60, 60); + if (!dibs) { + loggerMaker.infoAndAddToDb("Usage cron dibs not acquired, skipping usage cron", LoggerMaker.LogDb.DASHBOARD); + return; + } calcUsage(); } }, 0, 1, UsageUtils.USAGE_CRON_PERIOD); diff --git a/apps/dashboard/src/main/java/com/akto/utils/crons/UpdateSensitiveInfoInApiInfo.java b/apps/dashboard/src/main/java/com/akto/utils/crons/UpdateSensitiveInfoInApiInfo.java index 740cca99af..756956ae68 100644 --- a/apps/dashboard/src/main/java/com/akto/utils/crons/UpdateSensitiveInfoInApiInfo.java +++ b/apps/dashboard/src/main/java/com/akto/utils/crons/UpdateSensitiveInfoInApiInfo.java @@ -31,7 +31,7 @@ public void run() { Context.accountId.set(1000_000); boolean dibs = callDibs(Cluster.MAP_SENSITIVE_IN_INFO, 900, 60); if(!dibs){ - loggerMaker.infoAndAddToDb("Cron for updating new parameters, new endpoints and severity score dibs not acquired, thus skipping cron", LogDb.DASHBOARD); + loggerMaker.infoAndAddToDb("Cron for mapping sensitive info not picked up as dibs is acquired.", LogDb.DASHBOARD); return; } AccountTask.instance.executeTask(new Consumer() {