Unverified Commit cad58144 authored by Zzm0809's avatar Zzm0809 Committed by GitHub

[Feature] support alert interval (#3011)

parent adf013fa
...@@ -39,8 +39,10 @@ import org.dinky.data.model.ext.JobInfoDetail; ...@@ -39,8 +39,10 @@ import org.dinky.data.model.ext.JobInfoDetail;
import org.dinky.data.options.JobAlertRuleOptions; import org.dinky.data.options.JobAlertRuleOptions;
import org.dinky.service.AlertGroupService; import org.dinky.service.AlertGroupService;
import org.dinky.service.AlertHistoryService; import org.dinky.service.AlertHistoryService;
import org.dinky.service.SysConfigService;
import org.dinky.service.TaskService; import org.dinky.service.TaskService;
import org.dinky.service.impl.AlertRuleServiceImpl; import org.dinky.service.impl.AlertRuleServiceImpl;
import org.dinky.service.impl.SysConfigServiceImpl;
import org.dinky.utils.JsonUtils; import org.dinky.utils.JsonUtils;
import java.io.IOException; import java.io.IOException;
...@@ -59,6 +61,10 @@ import org.jeasy.rules.core.RuleBuilder; ...@@ -59,6 +61,10 @@ import org.jeasy.rules.core.RuleBuilder;
import org.jeasy.rules.spel.SpELCondition; import org.jeasy.rules.spel.SpELCondition;
import org.springframework.context.annotation.DependsOn; import org.springframework.context.annotation.DependsOn;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.StrFormatter; import cn.hutool.core.text.StrFormatter;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
...@@ -73,6 +79,7 @@ public class JobAlertHandler { ...@@ -73,6 +79,7 @@ public class JobAlertHandler {
private static final AlertHistoryService alertHistoryService; private static final AlertHistoryService alertHistoryService;
private static final AlertGroupService alertGroupService; private static final AlertGroupService alertGroupService;
private static final TaskService taskService; private static final TaskService taskService;
private static final SysConfigService sysConfigService;
private static final AlertRuleServiceImpl alertRuleService; private static final AlertRuleServiceImpl alertRuleService;
/** /**
...@@ -97,6 +104,7 @@ public class JobAlertHandler { ...@@ -97,6 +104,7 @@ public class JobAlertHandler {
alertHistoryService = SpringContextUtils.getBean("alertHistoryServiceImpl", AlertHistoryService.class); alertHistoryService = SpringContextUtils.getBean("alertHistoryServiceImpl", AlertHistoryService.class);
alertGroupService = SpringContextUtils.getBean("alertGroupServiceImpl", AlertGroupService.class); alertGroupService = SpringContextUtils.getBean("alertGroupServiceImpl", AlertGroupService.class);
alertRuleService = SpringContextUtils.getBean("alertRuleServiceImpl", AlertRuleServiceImpl.class); alertRuleService = SpringContextUtils.getBean("alertRuleServiceImpl", AlertRuleServiceImpl.class);
sysConfigService = SpringContextUtils.getBean("sysConfigServiceImpl", SysConfigServiceImpl.class);
} }
public static JobAlertHandler getInstance() { public static JobAlertHandler getInstance() {
...@@ -201,6 +209,10 @@ public class JobAlertHandler { ...@@ -201,6 +209,10 @@ public class JobAlertHandler {
if (alertInstance == null || !alertInstance.getEnabled()) { if (alertInstance == null || !alertInstance.getEnabled()) {
continue; continue;
} }
// if current time in diff minute time, and alert send record count > diff minute max send count,
// then not send, else send
// todo: 多线程会重复发送,需要优化
if (isGTEMaxSendRecordCount(alertGroup, task) && timeIsInDiffMinute(alertGroup, task)) {
sendAlert( sendAlert(
alertInstance, alertInstance,
facts.get(JobAlertRuleOptions.FIELD_JOB_INSTANCE_ID), facts.get(JobAlertRuleOptions.FIELD_JOB_INSTANCE_ID),
...@@ -211,6 +223,66 @@ public class JobAlertHandler { ...@@ -211,6 +223,66 @@ public class JobAlertHandler {
} }
} }
} }
}
/**
* 判断是否大于最大发送次数 | Whether it is greater than the maximum number of sending times
*
* @param alertGroup
* @param task
* @return if true, then send alert
*/
private boolean isGTEMaxSendRecordCount(AlertGroup alertGroup, TaskDTO task) {
// check diff seconds max send count| 指定时间间隔内最大发送次数 2
int diffMinuteMaxSendCount = (int) sysConfigService
.getOneConfigByKey(Status.SYS_ENV_SETTINGS_DIFF_MINUTE_MAX_SEND_COUNT.getKey())
.getValue();
// check diff seconds max send count | 指定时间间隔 1
int jobResendDiffSecond = (int) sysConfigService
.getOneConfigByKey(Status.SYS_ENV_SETTINGS_JOB_RESEND_DIFF_SECOND.getKey())
.getValue();
// 获取当前时间 - 指定时间间隔 = 指定时间间隔前的时间 | get current time - diff seconds = diff seconds time
DateTime diffMinuteTime = DateUtil.offsetSecond(DateUtil.date(), -jobResendDiffSecond);
// 获取指定时间间隔前的时间到当前时间之间的发送记录数 | get diff minute time to current time alert send record count
long jobInstanceAlertSendRecordCount = alertHistoryService.count(
new LambdaQueryWrapper<>(AlertHistory.class)
.eq(AlertHistory::getAlertGroupId, alertGroup.getId()) // alert group id
.eq(AlertHistory::getJobInstanceId, task.getJobInstanceId()) // assert group id
.ge(true, AlertHistory::getCreateTime, diffMinuteTime) // 指定时间间隔前的时间 | diff minute time
.le(true, AlertHistory::getCreateTime, DateUtil.date()) // 当前时间 | current time
);
// 1. 如果 当前时间 在 指定时间间隔前的时间区间内,且发送记录数大于指定时间间隔内最大发送次数,则不发送 | if current time in diff minute time, and alert send
// record count > diff minute max send count, then not send
// 2. 如果 当前时间 不在 指定时间间隔前的时间区间内,则发送 | if current time not in diff minute time, then send
if (jobInstanceAlertSendRecordCount >= diffMinuteMaxSendCount) {
log.warn(
Status.JOB_ALERT_MAX_SEND_COUNT.getMessage(),
jobResendDiffSecond,
diffMinuteMaxSendCount,
jobInstanceAlertSendRecordCount);
return false;
}
return true;
}
/**
* 判断当前时间是否在指定时间间隔前的时间区间内 | Whether the current time is in the time interval before the specified time interval
*
* @param alertGroup
* @param task
* @return
*/
private boolean timeIsInDiffMinute(AlertGroup alertGroup, TaskDTO task) {
// check diff minute max send count | 指定时间间隔 1
int jobResendDiffSecond = (int) sysConfigService
.getOneConfigByKey(Status.SYS_ENV_SETTINGS_JOB_RESEND_DIFF_SECOND.getKey())
.getValue();
// 获取当前时间 - 指定时间间隔 = 指定时间间隔前的时间 | get current time - diff seconds = diff seconds time
DateTime diffSecondTime = DateUtil.offsetSecond(DateUtil.date(), -jobResendDiffSecond);
// 1. 如果 当前时间 在 指定时间间隔前的时间区间内
return !DateUtil.date().before(diffSecondTime);
}
/** /**
* Sends an alert based on the alert instance's configuration. * Sends an alert based on the alert instance's configuration.
......
...@@ -40,6 +40,13 @@ public interface SysConfigService extends ISuperService<SysConfig> { ...@@ -40,6 +40,13 @@ public interface SysConfigService extends ISuperService<SysConfig> {
*/ */
Map<String, List<Configuration<?>>> getAll(); Map<String, List<Configuration<?>>> getAll();
/**
* Get one configuration by key.
*
* @return A map of string keys to lists of {@link Configuration} objects.
*/
Configuration<Object> getOneConfigByKey(String key);
/** /**
* Initialize system configurations. * Initialize system configurations.
*/ */
......
...@@ -52,6 +52,23 @@ public class SysConfigServiceImpl extends SuperServiceImpl<SysConfigMapper, SysC ...@@ -52,6 +52,23 @@ public class SysConfigServiceImpl extends SuperServiceImpl<SysConfigMapper, SysC
return SystemConfiguration.getInstances().getAllConfiguration(); return SystemConfiguration.getInstances().getAllConfiguration();
} }
/**
* Get one configuration by key.
*
* @param key
* @return A map of string keys to lists of {@link Configuration} objects.
*/
@Override
public Configuration<Object> getOneConfigByKey(String key) {
List<Configuration<?>> configurationList =
getAll().entrySet().stream().flatMap(x -> x.getValue().stream()).collect(Collectors.toList());
return (Configuration<Object>) configurationList.stream()
.filter(x -> x.getKey().equals(key))
.findFirst()
.orElseThrow(() -> new RuntimeException("No such configuration: " + key));
}
@Override @Override
public void initSysConfig() { public void initSysConfig() {
SystemConfiguration systemConfiguration = SystemConfiguration.getInstances(); SystemConfiguration systemConfiguration = SystemConfiguration.getInstances();
......
...@@ -188,6 +188,7 @@ public enum Status { ...@@ -188,6 +188,7 @@ public enum Status {
TASK_IS_EXIST(12010, "task.is.existed"), TASK_IS_EXIST(12010, "task.is.existed"),
TASK_IS_PUBLISH_CANNOT_DELETE(12011, "task.is.publish.cannot.delete"), TASK_IS_PUBLISH_CANNOT_DELETE(12011, "task.is.publish.cannot.delete"),
TASK_IS_RUNNING_CANNOT_DELETE(12012, "task.is.running.cannot.delete"), TASK_IS_RUNNING_CANNOT_DELETE(12012, "task.is.running.cannot.delete"),
JOB_ALERT_MAX_SEND_COUNT(12013, "job.alert.max.send.count"),
/** /**
* alert instance * alert instance
...@@ -331,6 +332,13 @@ public enum Status { ...@@ -331,6 +332,13 @@ public enum Status {
SYS_ENV_SETTINGS_PYTHONHOME_NOTE(115, "sys.env.settings.pythonHome.note"), SYS_ENV_SETTINGS_PYTHONHOME_NOTE(115, "sys.env.settings.pythonHome.note"),
SYS_ENV_SETTINGS_DINKYADDR(116, "sys.env.settings.dinkyAddr"), SYS_ENV_SETTINGS_DINKYADDR(116, "sys.env.settings.dinkyAddr"),
SYS_ENV_SETTINGS_DINKYADDR_NOTE(117, "sys.env.settings.dinkyAddr.note"), SYS_ENV_SETTINGS_DINKYADDR_NOTE(117, "sys.env.settings.dinkyAddr.note"),
SYS_ENV_SETTINGS_JOB_RESEND_DIFF_SECOND(118, "sys.env.settings.jobResendDiffSecond"),
SYS_ENV_SETTINGS_JOB_RESEND_DIFF_SECOND_NOTE(119, "sys.env.settings.jobResendDiffSecond.note"),
SYS_ENV_SETTINGS_DIFF_MINUTE_MAX_SEND_COUNT(120, "sys.env.settings.diffMinuteMaxSendCount"),
SYS_ENV_SETTINGS_DIFF_MINUTE_MAX_SEND_COUNT_NOTE(121, "sys.env.settings.diffMinuteMaxSendCount.note"),
SYS_ENV_SETTINGS_MAX_RETAIN_DAYS(1171, "sys.env.settings.maxRetainDays"), SYS_ENV_SETTINGS_MAX_RETAIN_DAYS(1171, "sys.env.settings.maxRetainDays"),
SYS_ENV_SETTINGS_MAX_RETAIN_DAYS_NOTE(1172, "sys.env.settings.maxRetainDays.note"), SYS_ENV_SETTINGS_MAX_RETAIN_DAYS_NOTE(1172, "sys.env.settings.maxRetainDays.note"),
SYS_ENV_SETTINGS_MAX_RETAIN_COUNT(1173, "sys.env.settings.maxRetainCount"), SYS_ENV_SETTINGS_MAX_RETAIN_COUNT(1173, "sys.env.settings.maxRetainCount"),
......
...@@ -61,6 +61,7 @@ public class SystemConfiguration { ...@@ -61,6 +61,7 @@ public class SystemConfiguration {
ReflectUtil.getFields(SystemConfiguration.class, f -> f.getType() == Configuration.class)) ReflectUtil.getFields(SystemConfiguration.class, f -> f.getType() == Configuration.class))
.map(f -> (Configuration<?>) ReflectUtil.getFieldValue(systemConfiguration, f)) .map(f -> (Configuration<?>) ReflectUtil.getFieldValue(systemConfiguration, f))
.collect(Collectors.toList()); .collect(Collectors.toList());
private final Configuration<Boolean> useRestAPI = key(Status.SYS_FLINK_SETTINGS_USERESTAPI) private final Configuration<Boolean> useRestAPI = key(Status.SYS_FLINK_SETTINGS_USERESTAPI)
.booleanType() .booleanType()
.defaultValue(true) .defaultValue(true)
...@@ -105,6 +106,17 @@ public class SystemConfiguration { ...@@ -105,6 +106,17 @@ public class SystemConfiguration {
.defaultValue(System.getProperty("dinkyAddr")) .defaultValue(System.getProperty("dinkyAddr"))
.note(Status.SYS_ENV_SETTINGS_DINKYADDR_NOTE); .note(Status.SYS_ENV_SETTINGS_DINKYADDR_NOTE);
private final Configuration<Integer> jobReSendDiffSecond = key(Status.SYS_ENV_SETTINGS_JOB_RESEND_DIFF_SECOND)
.intType()
.defaultValue(60)
.note(Status.SYS_ENV_SETTINGS_JOB_RESEND_DIFF_SECOND_NOTE);
private final Configuration<Integer> diffMinuteMaxSendCount =
key(Status.SYS_ENV_SETTINGS_DIFF_MINUTE_MAX_SEND_COUNT)
.intType()
.defaultValue(2)
.note(Status.SYS_ENV_SETTINGS_DIFF_MINUTE_MAX_SEND_COUNT_NOTE);
private final Configuration<Integer> jobMaxRetainCount = key(Status.SYS_ENV_SETTINGS_MAX_RETAIN_COUNT) private final Configuration<Integer> jobMaxRetainCount = key(Status.SYS_ENV_SETTINGS_MAX_RETAIN_COUNT)
.intType() .intType()
.defaultValue(10) .defaultValue(10)
......
...@@ -106,6 +106,7 @@ task.is.online= Task is online, modification is prohibited ...@@ -106,6 +106,7 @@ task.is.online= Task is online, modification is prohibited
task.is.existed=Task is existed task.is.existed=Task is existed
task.is.publish.cannot.delete=Task is published, cannot delete task.is.publish.cannot.delete=Task is published, cannot delete
task.is.running.cannot.delete=Task is running, cannot delete, please stop the task first task.is.running.cannot.delete=Task is running, cannot delete, please stop the task first
job.alert.max.send.count=You have configured the maximum number of sends within the specified time interval [{}] seconds to be: [{}]. The current time is within the time interval before the specified time interval, and the number of records that have been sent is: [{}]. No alarm message will be sent.
cluster.instance.deploy=Deploy Success cluster.instance.deploy=Deploy Success
clear.failed=Clear Failed clear.failed=Clear Failed
rename.success=Rename Successfully rename.success=Rename Successfully
...@@ -189,6 +190,10 @@ sys.env.settings.pythonHome=Python Env variables ...@@ -189,6 +190,10 @@ sys.env.settings.pythonHome=Python Env variables
sys.env.settings.pythonHome.note=Python environment variables, used to submit Python tasks and build Python Udf sys.env.settings.pythonHome.note=Python environment variables, used to submit Python tasks and build Python Udf
sys.env.settings.dinkyAddr=Dinky Address sys.env.settings.dinkyAddr=Dinky Address
sys.env.settings.dinkyAddr.note=The address must be the same as the address configured in the Dinky Application background url sys.env.settings.dinkyAddr.note=The address must be the same as the address configured in the Dinky Application background url
sys.env.settings.jobResendDiffSecond=Alert anti-resend interval
sys.env.settings.jobResendDiffSecond.note=During this interval, when the Alert information sent reaches the configured value of [Maximum number of alarm resend prevention], after reaching the threshold, the Alert information will no longer be sent; unit: seconds
sys.env.settings.diffMinuteMaxSendCount=Maximum number of alarms to prevent resending
sys.env.settings.diffMinuteMaxSendCount.note=This configuration is used to send alarm information N times within the specified interval configured in [Alarm Anti-Resend Interval]. After reaching the maximum number set by this configuration, alarm information will no longer be sent. ,Note: This configuration is based on task instances, that is, each task instance will be calculated separately.sys.env.settings.maxRetainDays=Job history max retained days
sys.env.settings.maxRetainDays=Job history max retained days sys.env.settings.maxRetainDays=Job history max retained days
sys.env.settings.maxRetainDays.note=The maximum number of days for the history of submitted jobs and auto-registered cluster records to be retained will be automatically deleted when they expire sys.env.settings.maxRetainDays.note=The maximum number of days for the history of submitted jobs and auto-registered cluster records to be retained will be automatically deleted when they expire
sys.env.settings.maxRetainCount=Job history max retained counts sys.env.settings.maxRetainCount=Job history max retained counts
......
...@@ -106,6 +106,7 @@ task.is.online=任务已上线,禁止修改 ...@@ -106,6 +106,7 @@ task.is.online=任务已上线,禁止修改
task.is.existed=作业已存在 task.is.existed=作业已存在
task.is.publish.cannot.delete=作业已发布,无法删除,请先下线 task.is.publish.cannot.delete=作业已发布,无法删除,请先下线
task.is.running.cannot.delete=作业正在运行,无法删除,请先停止 task.is.running.cannot.delete=作业正在运行,无法删除,请先停止
job.alert.max.send.count=你配置了指定时间间隔[{}]秒内最大发送次数为:[{}],当前时间在指定时间间隔前的时间区间内,且已经发送记录数为:[{}],不发送告警消息
cluster.instance.deploy=部署完成 cluster.instance.deploy=部署完成
clear.failed=清除失败 clear.failed=清除失败
rename.success=重命名成功 rename.success=重命名成功
...@@ -189,6 +190,10 @@ sys.env.settings.pythonHome=Python 环境变量 ...@@ -189,6 +190,10 @@ sys.env.settings.pythonHome=Python 环境变量
sys.env.settings.pythonHome.note=Python 环境变量,用于提交 Python 任务以及构建 Python Udf sys.env.settings.pythonHome.note=Python 环境变量,用于提交 Python 任务以及构建 Python Udf
sys.env.settings.dinkyAddr=Dinky 地址 sys.env.settings.dinkyAddr=Dinky 地址
sys.env.settings.dinkyAddr.note=该地址必须与Dinky Application后台url中配置的地址相同 sys.env.settings.dinkyAddr.note=该地址必须与Dinky Application后台url中配置的地址相同
sys.env.settings.jobResendDiffSecond=告警防重发间隔
sys.env.settings.jobResendDiffSecond.note=在此间隔内,发送告警信息达到 [告警防重发最大条数] 配置的值时,达到阈值后,不再发送告警信息; 单位:秒
sys.env.settings.diffMinuteMaxSendCount=告警防重发最大条数
sys.env.settings.diffMinuteMaxSendCount.note=此配置用于在 [告警防重发间隔] 配置的指定间隔内,发送了 N 次告警信息,达到此配置设置的最大条数后,不再发送告警信息,注意: 此配置以任务实例为单位,即: 每个任务实例都会单独计算
sys.env.settings.maxRetainDays=作业历史最大保留天数 sys.env.settings.maxRetainDays=作业历史最大保留天数
sys.env.settings.maxRetainDays.note=提交的作业历史与自动注册的集群记录最大保留天数,过期会被自动删除 sys.env.settings.maxRetainDays.note=提交的作业历史与自动注册的集群记录最大保留天数,过期会被自动删除
sys.env.settings.maxRetainCount=作业历史最大保留数量 sys.env.settings.maxRetainCount=作业历史最大保留数量
......
...@@ -38,6 +38,13 @@ ...@@ -38,6 +38,13 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-statebackend-rocksdb -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-statebackend-rocksdb</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.flink</groupId> <groupId>org.apache.flink</groupId>
<artifactId>flink-connector-jdbc</artifactId> <artifactId>flink-connector-jdbc</artifactId>
......
...@@ -43,6 +43,11 @@ ...@@ -43,6 +43,11 @@
<artifactId>flink-connector-jdbc</artifactId> <artifactId>flink-connector-jdbc</artifactId>
<version>3.1.0-1.17</version> <version>3.1.0-1.17</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-statebackend-rocksdb</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.flink</groupId> <groupId>org.apache.flink</groupId>
<artifactId>flink-table-api-scala-bridge_2.12</artifactId> <artifactId>flink-table-api-scala-bridge_2.12</artifactId>
......
...@@ -117,6 +117,7 @@ export async function getInitialState(): Promise<{ ...@@ -117,6 +117,7 @@ export async function getInitialState(): Promise<{
// ProLayout 支持的api https://procomponents.ant.design/components/layout // ProLayout 支持的api https://procomponents.ant.design/components/layout
export const layout: RunTimeLayoutConfig = ({ initialState }) => { export const layout: RunTimeLayoutConfig = ({ initialState }) => {
// @ts-ignore
const fullscreen = initialState?.fullscreen; const fullscreen = initialState?.fullscreen;
const defaultSettings = { const defaultSettings = {
...@@ -130,12 +131,13 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => { ...@@ -130,12 +131,13 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => {
// 自定义 403 页面 // 自定义 403 页面
unAccessible: <UnAccessible />, unAccessible: <UnAccessible />,
// 增加一个 loading 的状态 // 增加一个 loading 的状态
childrenRender: (children) => { childrenRender: (children: any) => {
return initialState?.loading ? ( return initialState?.loading ? (
<PageLoading /> <PageLoading />
) : ( ) : (
<AccessContextProvider currentUser={initialState?.currentUser}> <AccessContextProvider currentUser={initialState?.currentUser}>
<FullScreenProvider>{children}</FullScreenProvider> {/* @ts-ignore */}
<FullScreenProvider key={location.pathname}>{children}</FullScreenProvider>
</AccessContextProvider> </AccessContextProvider>
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment