feat: 修改告警

This commit is contained in:
zengxiaobo 2024-07-05 17:26:53 +08:00
parent 6231b9ebb1
commit b6bed4d225
3 changed files with 15 additions and 6 deletions

View File

@ -14,6 +14,14 @@ public interface AlertClient {
void post(Alert alert);
default void post(String key, Throwable ex, String message, Object... objects) {
post(new Alert(key, ex, message, objects));
}
default void post(String key, Throwable ex, String message) {
post(new Alert(key, ex, message, null));
}
@Data
class Alert {
private static final int MAX_MESSAGE_LENGTH = 8_000;
@ -25,7 +33,6 @@ public interface AlertClient {
String message;
String stack;
@Builder
public Alert(String key, Throwable ex, String message, Object... objects) {
this.key = key;
this.message = message;

View File

@ -26,6 +26,12 @@ public class AlertClientImpl implements AlertClient {
ListMultimap<AlertKey, AlertMessage> alertsMap = Multimaps.synchronizedListMultimap(ArrayListMultimap.create());
/**
* @param consumer
* @param executor
* @param period 默认间隔多少分钟发告警邮件
* @param consumeImmediatelyPreSecond 如果每秒出现多少次异常告警阈值
*/
@Builder
public AlertClientImpl(Consumer<Map<AlertKey, Collection<AlertMessage>>> consumer,
ScheduledThreadPoolExecutor executor,

View File

@ -21,11 +21,7 @@ class AlertClientImplTest {
.build();
for (int i = 0; i < 15; i++) {
alertClient.post(AlertClient.Alert.builder()
.ex(new RuntimeException())
.key("keykeykey")
.message("messagemessagemessagemessage")
.build());
alertClient.post("key", new RuntimeException(), "message");
}
}