From 290a0bad1a682125716839d5aaa265193f275d62 Mon Sep 17 00:00:00 2001 From: Ravi kiran Chiruvolu Date: Thu, 2 Jun 2022 10:51:07 -0700 Subject: [PATCH] Make priming of pop alerts configurable --- .../horizon/alerts/EnvironmentConfig.java | 13 ++++++++++ .../egads/PeriodOverPeriodProcessor.java | 25 +++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/opentsdb/horizon/alerts/EnvironmentConfig.java b/src/main/java/net/opentsdb/horizon/alerts/EnvironmentConfig.java index 054d138..0782fde 100644 --- a/src/main/java/net/opentsdb/horizon/alerts/EnvironmentConfig.java +++ b/src/main/java/net/opentsdb/horizon/alerts/EnvironmentConfig.java @@ -307,6 +307,10 @@ public class EnvironmentConfig { public static final String DEFAULT_PULSAR_ATHENZ_KEY_ID = "0"; + public static final String ENABLE_PRIMING = "enable_pop_priming"; + + public static final String DEFAULT_ENABLE_PRIMING = "true"; + static { String file = PROPERTIES_FILE; if(IS_LOCAL) { @@ -668,6 +672,15 @@ public boolean isSnoozeTagsEnabled() { )); } + public boolean enablePOPPriming() { + return Boolean.parseBoolean( + propertiesFile.getProperty( + ENABLE_PRIMING, + DEFAULT_ENABLE_PRIMING + ) + ); + } + public Optional> getList(final String property, final String defaultValue, final String delimiter) { diff --git a/src/main/java/net/opentsdb/horizon/alerts/query/egads/PeriodOverPeriodProcessor.java b/src/main/java/net/opentsdb/horizon/alerts/query/egads/PeriodOverPeriodProcessor.java index fe56435..dd1ed8d 100644 --- a/src/main/java/net/opentsdb/horizon/alerts/query/egads/PeriodOverPeriodProcessor.java +++ b/src/main/java/net/opentsdb/horizon/alerts/query/egads/PeriodOverPeriodProcessor.java @@ -75,6 +75,7 @@ public final class PeriodOverPeriodProcessor private final TSDBClient tsdbClient; private final StatusWriter statusWriter; private final CollectorWriter collectorWriter; + private final boolean enablePriming; private String namespace; private long alertId; @@ -111,7 +112,23 @@ public PeriodOverPeriodProcessor( final TSDBClient tsdbClient, final StatusWriter statusWriter, final CollectorWriter collectorWriter) { + this ( + alertConfig, + tsdbClient, + statusWriter, + collectorWriter, + new EnvironmentConfig().enablePOPPriming() + ); + } + + public PeriodOverPeriodProcessor( + final PeriodOverPeriodAlertConfig alertConfig, + final TSDBClient tsdbClient, + final StatusWriter statusWriter, + final CollectorWriter collectorWriter, + final boolean enablePriming) { super(alertConfig); + this.enablePriming = enablePriming; Validate.paramNotNull(tsdbClient, "tsdbClient cannot be null"); Validate.paramNotNull(statusWriter, "statusWriter cannot be null"); Validate.paramNotNull(collectorWriter, "collectorWriter cannot be null"); @@ -122,6 +139,7 @@ public PeriodOverPeriodProcessor( displayWindowSec = DISPLAY_WINDOW_SEC; } + /* ------------ Methods ------------ */ @Override @@ -180,8 +198,11 @@ public AlertEventBag execute(final long endTime, final List alerts = processResponse(response, stateStore); LOG.debug("processed response result: alert_id={}, end_time={}, alerts={}", alertId, endTime, alerts); - - tryPrimeNextModel(endTime, timeUnit); + if (enablePriming) { + tryPrimeNextModel(endTime, timeUnit); + } else { + LOG.debug("Priming is disabled for Period over period alerts. Skipping for alert_id={}", alertId); + } return new AlertEventBag(alerts, getAlertConfig()); }