diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/common/BatchJobLauncher.java b/batch/src/main/java/com/navercorp/pinpoint/batch/common/BatchJobLauncher.java index 1f7c5e416d044..f2ceffb0f29ba 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/common/BatchJobLauncher.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/common/BatchJobLauncher.java @@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import java.util.Date; +import java.util.Objects; /** * @author minwoo.jung @@ -33,26 +34,25 @@ public class BatchJobLauncher extends JobLaunchSupport { private final Logger logger = LogManager.getLogger(this.getClass()); - public static final String CLEANUP_INACTIVE_AGENTS_JOB_NAME = "cleanupInactiveAgentsJob"; - - private final boolean enableCleanupInactiveAgentsJob; - - private final boolean enableUriStatAlarmJob; + private final BatchProperties batchProperties; public BatchJobLauncher(@Qualifier("jobRegistry") JobLocator locator, @Qualifier("jobLauncher") JobLauncher launcher, BatchProperties batchProperties) { super(locator, launcher); - this.enableCleanupInactiveAgentsJob = batchProperties.isEnableCleanupInactiveAgents(); - this.enableUriStatAlarmJob = batchProperties.getEnableUriStatAlarmJob(); + this.batchProperties = Objects.requireNonNull(batchProperties, "batchProperties"); } public void alarmJob() { - JobParameters params = createTimeParameter(); - run("alarmJob", params); + if (batchProperties.isAlarmJobEnable()) { + run("alarmJob", createTimeParameter()); + } else { + logger.debug("Skip alarmJob, because 'enableUriStatAlarmJob' is disabled."); + } + } public void uriStatAlarmJob() { - if (enableUriStatAlarmJob) { + if (batchProperties.isUriStatAlarmJobEnable()) { run("uriAlarmJob", createTimeParameter()); } else { logger.debug("Skip uriAlarmJob, because 'enableUriStatAlarmJob' is disabled."); @@ -67,19 +67,26 @@ private JobParameters createTimeParameter() { } public void agentCountJob() { - run("agentCountJob", createTimeParameter()); + if (batchProperties.isAgentCountJobEnable()) { + run("agentCountJob", createTimeParameter()); + } else { + logger.debug("Skip agentCountJob, because 'enableAgentCountJob' is disabled."); + } } public void flinkCheckJob() { - run("flinkCheckJob", createTimeParameter()); + if (batchProperties.isFlinkCheckJobEnable()) { + run("flinkCheckJob", createTimeParameter()); + } else { + logger.debug("Skip flinkCheckJob, because 'enableFlinkCheckJob' is disabled."); + } } public void cleanupInactiveAgentsJob() { - if (enableCleanupInactiveAgentsJob) { - run(CLEANUP_INACTIVE_AGENTS_JOB_NAME, createTimeParameter()); + if (batchProperties.isCleanupInactiveAgentsJobEnable()) { + run("cleanupInactiveAgentsJob", createTimeParameter()); } else { - logger.debug("Skip " + CLEANUP_INACTIVE_AGENTS_JOB_NAME + ", because 'enableCleanupInactiveAgentsJob' is disabled."); + logger.debug("Skip cleanupInactiveAgentsJob, because 'enableCleanupInactiveAgentsJob' is disabled."); } } - } diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/common/BatchProperties.java b/batch/src/main/java/com/navercorp/pinpoint/batch/common/BatchProperties.java index cbcc3f38b786c..997eb703df3d2 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/common/BatchProperties.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/common/BatchProperties.java @@ -43,38 +43,47 @@ public class BatchProperties { @Value("${batch.flink.rest.port:8081}") private int flinkRestPort; - @Value("${job.cleanup.inactive.agents:false}") - private boolean enableCleanupInactiveAgents; + @Value("${job.alarm.enable:true}") + private boolean alarmJobEnable; - @Value("${job.alarm.uristat.enable:false}") - private boolean enableUriStatAlarmJob; + @Value("${job.alarm.cron}") + private String alarmJobCron; - private static final int DEFAULT_CLEANUP_INACTIVE_AGENTS_DURATION_DAYS = 30; - private static final int MINIMUM_CLEANUP_INACTIVE_AGENTS_DURATION_DAYS = 7; + @Value("${job.agent.count.enable:true}") + private boolean agentCountJobEnable; - @Value("${job.cleanup.inactive.agents.duration.days:30}") - private int cleanupInactiveAgentsDurationDays; + @Value("${job.agent.count.cron}") + private String agentCountJobCron; + + @Value("${job.flink.check.enable:true}") + private boolean flinkCheckJobEnable; + + @Value("${job.flink.check.cron}") + private String flinkCheckJobCron; + + @Value("${job.cleanup.inactive.agents.enable:true}") + private boolean cleanupInactiveAgentsJobEnable; + + @Value("${job.cleanup.inactive.agents.cron}") + private String cleanupInactiveAgentsJobCron; - // Spring supports `org.springframework.scheduling.annotation.Scheduled#CRON_DISABLED` since Spring 5.x - // https://github.com/spring-projects/spring-framework/issues/21397 - // BatchLauner does not run a job even if cron is executed. Nevertheless, Cron should be disabled if possible. - private static final String DISABLED_CLEANUP_INACTIVE_AGENTS_CRON = "0 0 0 29 2 ?"; + @Value("${job.alarm.uristat.enable:true}") + private boolean uriStatAlarmJobEnable; - @Value("${job.cleanup.inactive.agents.cron:}") - private String cleanupInactiveAgentsCron; + @Value("${job.alarm.uristat.cron}") + private String uriStatAlarmJobCron; + @Value("${job.cleanup.inactive.agents.duration.days:30}") + private int cleanupInactiveAgentsDurationDays; + + private static final int MINIMUM_CLEANUP_INACTIVE_AGENTS_DURATION_DAYS = 7; @PostConstruct public void setup() { beforeLog(); - if (!enableCleanupInactiveAgents) { - cleanupInactiveAgentsDurationDays = DEFAULT_CLEANUP_INACTIVE_AGENTS_DURATION_DAYS; - cleanupInactiveAgentsCron = DISABLED_CLEANUP_INACTIVE_AGENTS_CRON; - } else { - if (cleanupInactiveAgentsDurationDays < MINIMUM_CLEANUP_INACTIVE_AGENTS_DURATION_DAYS) { - throw new IllegalArgumentException("'cleanupInactiveAgentsDuration' must be 'cleanupInactiveAgentsDuration >= 30'"); - } + if (cleanupInactiveAgentsDurationDays < MINIMUM_CLEANUP_INACTIVE_AGENTS_DURATION_DAYS) { + throw new IllegalArgumentException("'cleanupInactiveAgentsDuration' must be 'cleanupInactiveAgentsDuration >= 30'"); } afterLog(); @@ -104,33 +113,67 @@ public String getBatchEnv() { return batchEnv; } - public boolean isEnableCleanupInactiveAgents() { - return enableCleanupInactiveAgents; + public boolean isCleanupInactiveAgentsJobEnable() { + return cleanupInactiveAgentsJobEnable; } - public boolean getEnableUriStatAlarmJob() { - return enableUriStatAlarmJob; + public boolean isUriStatAlarmJobEnable() { + return uriStatAlarmJobEnable; } - public int getCleanupInactiveAgentsDurationDays() { - return cleanupInactiveAgentsDurationDays; + public String getCleanupInactiveAgentsJobCron() { + return cleanupInactiveAgentsJobCron; } - public String getCleanupInactiveAgentsCron() { - return cleanupInactiveAgentsCron; + public boolean isAlarmJobEnable() { + return alarmJobEnable; } + public String getAlarmJobCron() { + return alarmJobCron; + } + + public boolean isAgentCountJobEnable() { + return agentCountJobEnable; + } + + public String getAgentCountJobCron() { + return agentCountJobCron; + } + + public boolean isFlinkCheckJobEnable() { + return flinkCheckJobEnable; + } + + public String getFlinkCheckJobCron() { + return flinkCheckJobCron; + } + + public String getUriStatAlarmJobCron() { + return uriStatAlarmJobCron; + } + public int getCleanupInactiveAgentsDurationDays() { + return cleanupInactiveAgentsDurationDays; + } @Override public String toString() { - return "BatchConfiguration{" + - "batchEnv='" + batchEnv + '\'' + + return "BatchProperties{" + + "logger=" + logger + + ", batchEnv='" + batchEnv + '\'' + ", flinkServerList=" + Arrays.toString(flinkServerList) + ", flinkRestPort=" + flinkRestPort + - ", enableCleanupInactiveAgents=" + enableCleanupInactiveAgents + + ", alarmJobEnable=" + alarmJobEnable + + ", alarmJobCron='" + alarmJobCron + '\'' + + ", agentCountJobEnable=" + agentCountJobEnable + + ", agentCountJobCron='" + agentCountJobCron + '\'' + + ", flinkCheckJobEnable=" + flinkCheckJobEnable + + ", flinkCheckJobCron='" + flinkCheckJobCron + '\'' + + ", cleanupInactiveAgentsJobEnable=" + cleanupInactiveAgentsJobEnable + + ", cleanupInactiveAgentsJobCron='" + cleanupInactiveAgentsJobCron + '\'' + + ", uriStatAlarmJobEnable=" + uriStatAlarmJobEnable + + ", uriStatAlarmJobCron='" + uriStatAlarmJobCron + '\'' + ", cleanupInactiveAgentsDurationDays=" + cleanupInactiveAgentsDurationDays + - ", cleanupInactiveAgentsCron='" + cleanupInactiveAgentsCron + '\'' + - ", enableUriStatAlarmJob=" + enableUriStatAlarmJob + '}'; } } diff --git a/batch/src/main/resources/applicationContext-batch-schedule.xml b/batch/src/main/resources/applicationContext-batch-schedule.xml index ae839f9f26340..ac24af0d8dd65 100644 --- a/batch/src/main/resources/applicationContext-batch-schedule.xml +++ b/batch/src/main/resources/applicationContext-batch-schedule.xml @@ -8,11 +8,11 @@ - - - - - + + + + + diff --git a/batch/src/main/resources/batch-root.properties b/batch/src/main/resources/batch-root.properties index f1c627a02943f..c5a19e8c6ed9d 100644 --- a/batch/src/main/resources/batch-root.properties +++ b/batch/src/main/resources/batch-root.properties @@ -24,17 +24,22 @@ webhook.enable=false batch.flink.server= batch.flink.rest.port=8081 -#cleanup inactive agents job -job.cleanup.inactive.agents=false +########################################################### +# batch job config # +########################################################### + +job.alarm.cron=0 0/3 * * * * + +job.agent.count.cron=0 0 2 * * * + +job.flink.check.cron=0 0/10 * * * * -# "0 0 3 * * WED" = 3:00 AM on every Wednesday. -# "0 0 0 10 * *" = 0:00 AM on the 10th of every month. -# "0 0 16 * * MON-FRI" = 4:00 PM on every weekdays. -# There is no default value. -job.cleanup.inactive.agents.cron= +job.alarm.uristat.enable=false +job.alarm.uristat.cron=0 2/3 * * * * -# Default value is 30 (minimum value is 30) -#job.cleanup.inactive.agents.duration.days= +job.cleanup.inactive.agents.enable=false +job.cleanup.inactive.agents.cron=0 0 3 * * WED +job.cleanup.inactive.agents.duration.days=30 ########################################################### # BANNER # diff --git a/batch/src/test/java/com/navercorp/pinpoint/batch/BatchPropertiesTest.java b/batch/src/test/java/com/navercorp/pinpoint/batch/BatchPropertiesTest.java index 929bcb86c3040..99f6c02449e69 100644 --- a/batch/src/test/java/com/navercorp/pinpoint/batch/BatchPropertiesTest.java +++ b/batch/src/test/java/com/navercorp/pinpoint/batch/BatchPropertiesTest.java @@ -52,10 +52,10 @@ public void cleanupInactiveAgentsConfigurationTest() { properties.setup(); assertThat(properties) - .extracting(BatchProperties::isEnableCleanupInactiveAgents, - BatchProperties::getCleanupInactiveAgentsCron, + .extracting(BatchProperties::isCleanupInactiveAgentsJobEnable, + BatchProperties::getCleanupInactiveAgentsJobCron, BatchProperties::getCleanupInactiveAgentsDurationDays) - .containsExactly(false, "0 0 0 29 2 ?", 30); + .containsExactly(false, "0 0 3 * * WED", 30); } diff --git a/datasource/src/main/resources/datasource/jdbc-root.properties b/datasource/src/main/resources/datasource/jdbc-root.properties index 6db01c5271ba3..3a4e2a30a133d 100644 --- a/datasource/src/main/resources/datasource/jdbc-root.properties +++ b/datasource/src/main/resources/datasource/jdbc-root.properties @@ -21,7 +21,7 @@ spring.datasource.hikari.data-source-properties.characterEncoding=${mysql.prop.c # metadata spring.meta-datasource.hikari.driver-class-name=${spring.datasource.hikari.driver-class-name} -spring.meta-datasource.hikari.jdbc-url=${spring.datasource.hikari.jdbc-url}/metadata +spring.meta-datasource.hikari.jdbc-url=${spring.datasource.hikari.jdbc-url} spring.meta-datasource.hikari.username=${spring.datasource.hikari.username} spring.meta-datasource.hikari.password=${spring.datasource.hikari.password}