Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[alarm] refactor new alarm #2902

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
efba1f6
[improve] update backend monitor tags to label
tomsun28 Dec 17, 2024
62e84cf
[improve] update alarm fra
tomsun28 Dec 19, 2024
c8eec91
Merge branch 'master' into new-alarm
tomsun28 Dec 24, 2024
ac5f1b3
[improve] update alarm stru
tomsun28 Dec 24, 2024
6b781c4
[improve] update alarm
tomsun28 Dec 25, 2024
e15418e
[improve] update alarm
tomsun28 Dec 25, 2024
469ec93
[improve] update alarm
tomsun28 Dec 25, 2024
5a790f4
[improve] update alarm
tomsun28 Dec 25, 2024
557fa93
[improve] update alarm
tomsun28 Dec 25, 2024
5bd9d21
[improve] update alarm
tomsun28 Dec 25, 2024
bf3f6d6
[improve] update alarm
tomsun28 Dec 25, 2024
78db1b1
[improve] update alarm
tomsun28 Dec 25, 2024
4741cc9
[improve] update alarm
tomsun28 Dec 25, 2024
ef49b72
[webapp] update alert pojo
tomsun28 Dec 25, 2024
604de18
[webapp] update alert pojo
tomsun28 Dec 25, 2024
a7438fb
[improve] update alarm
tomsun28 Dec 25, 2024
d7a4e92
[improve] update alarm
tomsun28 Dec 25, 2024
f5acbfe
[improve] update alarm
tomsun28 Dec 25, 2024
d97830c
[improve] update alarm
tomsun28 Dec 25, 2024
dc247d0
[improve] update alarm
tomsun28 Dec 25, 2024
cae868d
[improve] update alarm
tomsun28 Dec 25, 2024
bcd8e76
[improve] update alarm
tomsun28 Dec 25, 2024
e3b5de7
[improve] update alarm
tomsun28 Dec 25, 2024
107581a
[improve] update alarm
tomsun28 Dec 25, 2024
d7794f5
[improve] update alarm
tomsun28 Dec 25, 2024
e7122b9
[improve] update alarm
tomsun28 Dec 25, 2024
81934a0
[improve] update alarm
tomsun28 Dec 25, 2024
17798de
[improve] update alarm
tomsun28 Dec 25, 2024
46c5271
Update hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/cal…
tomsun28 Dec 25, 2024
ff4b4fa
Update hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/red…
tomsun28 Dec 25, 2024
fa3d43b
Update hertzbeat-common/src/main/java/org/apache/hertzbeat/common/ent…
tomsun28 Dec 25, 2024
8f321c0
Update hertzbeat-base/pom.xml
tomsun28 Dec 25, 2024
7cbd5ce
Update hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/red…
tomsun28 Dec 25, 2024
79196c6
Update hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/cal…
tomsun28 Dec 25, 2024
a8b6204
Update hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/ser…
tomsun28 Dec 25, 2024
da6be30
Update hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/ser…
tomsun28 Dec 25, 2024
be6724e
Update hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/ser…
tomsun28 Dec 25, 2024
1555cf1
Update hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/ser…
tomsun28 Dec 25, 2024
abd9dd1
Update hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/red…
tomsun28 Dec 25, 2024
48ba387
Update hertzbeat-base/pom.xml
tomsun28 Dec 25, 2024
0c3e0bb
Update hertzbeat-common/src/main/java/org/apache/hertzbeat/common/ent…
tomsun28 Dec 25, 2024
0753a7e
Update hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/cal…
tomsun28 Dec 25, 2024
fdc667d
Update hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/cal…
tomsun28 Dec 25, 2024
0e1901a
Update hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/red…
tomsun28 Dec 25, 2024
0089821
Merge branch 'master' into new-alarm
tomsun28 Dec 25, 2024
201c6cf
[improve] update alarm
tomsun28 Dec 26, 2024
5e36d75
[improve] update alarm
tomsun28 Dec 26, 2024
2df0abb
[improve] update alarm
tomsun28 Dec 26, 2024
238a2b8
[improve] update alarm
tomsun28 Dec 26, 2024
8333382
Merge branch 'master' into new-alarm
Calvin979 Dec 27, 2024
2a3a61c
Merge branch 'master' into new-alarm
tomsun28 Dec 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion hertzbeat-alerter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@
<!-- common -->
<dependency>
<groupId>org.apache.hertzbeat</groupId>
<artifactId>hertzbeat-common</artifactId>
<artifactId>hertzbeat-base</artifactId>
<scope>provided</scope>
</dependency>
<!-- plugin -->
<dependency>
<groupId>org.apache.hertzbeat</groupId>
<artifactId>hertzbeat-plugin</artifactId>
</dependency>
<!-- spring -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -50,6 +55,21 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- email -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<!-- freemarker -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>${nekohtml.version}</version>
</dependency>
<!-- kafka -->
<dependency>
<groupId>org.apache.kafka</groupId>
Expand All @@ -73,6 +93,36 @@
<version>${easy-poi.version}</version>
<scope>compile</scope>
</dependency>
<!-- sms -->
<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java-sms</artifactId>
<exclusions>
<exclusion>
<groupId>com.squareup.okhttp</groupId>
<artifactId>logging-interceptor</artifactId>
</exclusion>
<exclusion>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
</exclusion>
<exclusion>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.huaweicloud.sdk</groupId>
<artifactId>huaweicloud-sdk-smn</artifactId>
<version>${huawei.sdk.version}</version>
<exclusions>
<exclusion>
<groupId>org.openeuler</groupId>
<artifactId>bgmprovider</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-vector</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public AlerterWorkerPool() {
private void initWorkExecutor() {
ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setUncaughtExceptionHandler((thread, throwable) -> {
log.error("workerExecutor has uncaughtException.");
log.error("Alerter workerExecutor has uncaughtException.");
log.error(throwable.getMessage(), throwable);
})
.setDaemon(true)
Expand All @@ -62,7 +62,7 @@ private void initWorkExecutor() {
private void initNotifyExecutor() {
ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setUncaughtExceptionHandler((thread, throwable) -> {
log.error("notifyExecutor has uncaughtException.");
log.error("Alerter notifyExecutor has uncaughtException.");
log.error(throwable.getMessage(), throwable);
})
.setDaemon(true)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.apache.hertzbeat.alert.calculate;
tomsun28 marked this conversation as resolved.
Show resolved Hide resolved
tomsun28 marked this conversation as resolved.
Show resolved Hide resolved

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.hertzbeat.alert.service.DataSourceService;
import org.apache.hertzbeat.common.entity.alerter.AlertDefine;
import org.apache.hertzbeat.common.entity.alerter.SingleAlert;
import org.apache.hertzbeat.common.util.JexlExpressionRunner;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.Collections;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.collections4.CollectionUtils;

/**
* Periodic Alert Calculator
*/

@Slf4j
@RequiredArgsConstructor
public class PeriodicAlertCalculator {

private final DataSourceService dataSourceService;
private final JexlExpressionRunner expressionRunner;
private final Map<String, SingleAlert> notRecoveredAlertMap = new ConcurrentHashMap<>(16);


public List<SingleAlert> calculate(AlertDefine rule) {
if (!rule.isEnable() || StringUtils.isEmpty(rule.getExpr())) {
return Collections.emptyList();
}
// todo: implement the following logic
try {
// Execute query
List<Map<String, Object>> queryResults = dataSourceService.query(
rule.getDatasource(),
rule.getExpr()
);

if (CollectionUtils.isEmpty(queryResults)) {
return Collections.emptyList();
}

// Execute expression calculation on query results
List<SingleAlert> newAlerts = queryResults.stream()
.filter(result -> execAlertExpression(result, rule.getExpr()))
.map(result -> buildAlert(rule, result))
.collect(Collectors.toList());

// Handle recovery notification
if (newAlerts.isEmpty()) {
return handleAlertRecover(rule);
}

return newAlerts;
} catch (Exception e) {
log.error("Calculate periodic rule {} failed: {}", rule.getName(), e.getMessage());
return Collections.emptyList();
}
}

private boolean execAlertExpression(Map<String, Object> result, String expr) {
return false;
}

private SingleAlert buildAlert(AlertDefine rule, Map<String, Object> metrics) {
return SingleAlert.builder()
.labels(rule.getLabels())
.annotations(rule.getAnnotations())
.triggerTimes(1)
.startAt(System.currentTimeMillis())
.activeAt(System.currentTimeMillis())
.build();
}

private List<SingleAlert> handleAlertRecover(AlertDefine rule) {
SingleAlert firingAlert = notRecoveredAlertMap.remove(rule.getId().toString());
if (firingAlert != null) {
return Collections.singletonList(buildResolvedAlert(rule, firingAlert));
}
return Collections.emptyList();
}

private SingleAlert buildResolvedAlert(AlertDefine rule, SingleAlert firingAlert) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.apache.hertzbeat.alert.calculate;
tomsun28 marked this conversation as resolved.
Show resolved Hide resolved
tomsun28 marked this conversation as resolved.
Show resolved Hide resolved

import lombok.extern.slf4j.Slf4j;

/**
* period alert rule scheduler
*/
@Slf4j
public class PeriodicAlertRuleScheduler {

// todo implement the following logic
}
Loading
Loading