forked from Netflix/conductor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
617d602
commit f13e6d8
Showing
8 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
core/src/main/java/com/netflix/conductor/core/execution/alerts/AlertProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.netflix.conductor.core.execution.alerts; | ||
|
||
import com.netflix.conductor.dao.ExecutionDAO; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.inject.Inject; | ||
import java.util.Map; | ||
|
||
|
||
public class AlertProcessor { | ||
private static final Logger logger = LoggerFactory.getLogger(AlertProcessor.class); | ||
|
||
private ExecutionDAO edao; | ||
|
||
@Inject | ||
public AlertProcessor(ExecutionDAO edao) { | ||
this.edao = edao; | ||
} | ||
|
||
public void processAlerts() { | ||
logger.info("Fetching grouped alerts from alerts table..."); | ||
Map<Integer, Integer> groupedAlerts = edao.getGroupedAlerts(); | ||
|
||
groupedAlerts.forEach((alertLookupId, alertCount) -> { | ||
Integer registryAlertCount = edao.getAlertCountFromRegistry(alertLookupId); | ||
if (registryAlertCount != null && alertCount > registryAlertCount) { | ||
logger.info("Alert threshold exceeded for lookup ID: {}. Count: {}, Threshold: {}", | ||
alertLookupId, alertCount, registryAlertCount); | ||
notifyService(alertLookupId, alertCount); | ||
} | ||
}); | ||
} | ||
|
||
private void notifyService(Integer alertLookupId, int alertCount) { | ||
logger.info("Notifying service for alertLookupId: {}, alertCount: {}", alertLookupId, alertCount); | ||
// Add logic to call the notify service | ||
} | ||
} | ||
|
37 changes: 37 additions & 0 deletions
37
core/src/main/java/com/netflix/conductor/core/execution/alerts/AlertScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.netflix.conductor.core.execution.alerts; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.inject.Inject; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class AlertScheduler { | ||
private static final Logger logger = LoggerFactory.getLogger(AlertScheduler.class); | ||
|
||
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); | ||
private final AlertProcessor alertProcessor; | ||
|
||
@Inject | ||
public AlertScheduler(AlertProcessor alertProcessor) { | ||
this.alertProcessor = alertProcessor; | ||
} | ||
|
||
public void start() { | ||
logger.info("Starting AlertScheduler to process alerts every 10 minutes..."); | ||
scheduler.scheduleAtFixedRate(() -> { | ||
try { | ||
alertProcessor.processAlerts(); | ||
} catch (Exception e) { | ||
logger.error("Error processing alerts", e); | ||
} | ||
}, 0, 10, TimeUnit.MINUTES); | ||
} | ||
|
||
public void stop() { | ||
logger.info("Stopping AlertScheduler..."); | ||
scheduler.shutdown(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters