Unverified Commit ad3f0df7 authored by gaoyan's avatar gaoyan Committed by GitHub

Refactor Alert (#2565)

* Optimize the process * fix daemon err * fix daemon err * fix daemon err * refactor alert * refactor alert data * refactor alert data * refactor alert data * formate code * fix dag bug * formate code
parent b698708a
...@@ -161,11 +161,7 @@ public class TaskController { ...@@ -161,11 +161,7 @@ public class TaskController {
@ExecuteProcess(type = ProcessType.FLINK_JOB_PLAN) @ExecuteProcess(type = ProcessType.FLINK_JOB_PLAN)
public Result<ObjectNode> getJobPlan(@ProcessId @RequestBody TaskDTO taskDTO) { public Result<ObjectNode> getJobPlan(@ProcessId @RequestBody TaskDTO taskDTO) {
ObjectNode jobPlan = null; ObjectNode jobPlan = null;
try { jobPlan = taskService.getJobPlan(taskDTO);
jobPlan = taskService.getJobPlan(taskDTO);
} catch (Exception e) {
return Result.failed(e.getMessage());
}
return Result.succeed(jobPlan, Status.EXECUTE_SUCCESS); return Result.succeed(jobPlan, Status.EXECUTE_SUCCESS);
} }
......
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.data.model.ext;
import org.dinky.alert.rules.CheckpointsRule;
import org.dinky.alert.rules.ExceptionRule;
import org.dinky.data.dto.JobDataDto;
import org.dinky.data.flink.checkpoint.CheckPointOverView;
import org.dinky.data.flink.exceptions.FlinkJobExceptionsDetail;
import org.dinky.data.model.ClusterInstance;
import org.dinky.data.model.SystemConfiguration;
import org.dinky.data.model.job.JobInstance;
import org.dinky.data.options.JobAlertRuleOptions;
import org.dinky.job.JobConfig;
import org.dinky.utils.JsonUtils;
import org.dinky.utils.TimeUtil;
import com.fasterxml.jackson.annotation.JsonProperty;
import cn.hutool.core.text.StrFormatter;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class JobAlertData {
/**
* Time about
*/
@JsonProperty(value = JobAlertRuleOptions.FIELD_NAME_TIME)
@Builder.Default
private String alertTime = "";
@JsonProperty(value = JobAlertRuleOptions.FIELD_NAME_START_TIME)
@Builder.Default
private String jobStartTime = "";
@JsonProperty(value = JobAlertRuleOptions.FIELD_NAME_END_TIME)
@Builder.Default
private String jobEndTime = "";
@JsonProperty(value = JobAlertRuleOptions.FIELD_NAME_DURATION)
@Builder.Default
private Long duration = 0L;
/**
* Job About
*/
@JsonProperty(value = JobAlertRuleOptions.FIELD_NAME_JOB_NAME)
@Builder.Default
private String jobName = "";
@JsonProperty(value = JobAlertRuleOptions.FIELD_NAME_JOB_ID)
@Builder.Default
private String jobId = "";
@JsonProperty(value = JobAlertRuleOptions.FIELD_NAME_JOB_STATUS)
@Builder.Default
private String jobStatus = "";
@JsonProperty(value = JobAlertRuleOptions.FIELD_TASK_ID)
@Builder.Default
private Integer taskId = 0;
@JsonProperty(value = JobAlertRuleOptions.FIELD_JOB_INSTANCE_ID)
@Builder.Default
private Integer jobInstanceId = 0;
@JsonProperty(value = JobAlertRuleOptions.FIELD_JOB_TASK_URL)
@Builder.Default
private String taskUrl = "";
@JsonProperty(value = JobAlertRuleOptions.FIELD_JOB_BATCH_MODEL)
@Builder.Default
private boolean batchModel = false;
/**
* Cluster About
*/
@JsonProperty(value = JobAlertRuleOptions.FIELD_NAME_CLUSTER_NAME)
@Builder.Default
private String clusterName = "";
@JsonProperty(value = JobAlertRuleOptions.FIELD_NAME_CLUSTER_TYPE)
@Builder.Default
private String clusterType = "";
@JsonProperty(value = JobAlertRuleOptions.FIELD_NAME_CLUSTER_HOSTS)
@Builder.Default
private String clusterHosts = "";
/**
* Flink About
*/
@JsonProperty(value = JobAlertRuleOptions.FIELD_NAME_EXCEPTIONS_MSG)
@Builder.Default
private String errorMsg = "";
@JsonProperty(value = JobAlertRuleOptions.FIELD_NAME_CHECKPOINT_COST_TIME)
@Builder.Default
private Long checkpointCostTime = 0L;
@JsonProperty(value = JobAlertRuleOptions.FIELD_NAME_CHECKPOINT_FAILED_COUNT)
@Builder.Default
private Long checkpointFailedCount = 0L;
@JsonProperty(value = JobAlertRuleOptions.FIELD_NAME_CHECKPOINT_COMPLETE_COUNT)
@Builder.Default
private Long checkpointCompleteCount = 0L;
@JsonProperty(value = JobAlertRuleOptions.FIELD_NAME_CHECKPOINT_FAILED)
@Builder.Default
private boolean isCheckpointFailed = false;
@JsonProperty(value = JobAlertRuleOptions.FIELD_NAME_IS_EXCEPTION)
@Builder.Default
private boolean isException = false;
private static String buildTaskUrl(JobInstance jobInstance) {
return StrFormatter.format(
"{}/#/devops/job-detail?id={}",
SystemConfiguration.getInstances().getDinkyAddr(),
jobInstance.getTaskId());
}
public static JobAlertData buildData(JobInfoDetail jobInfoDetail) {
JobAlertDataBuilder builder = JobAlertData.builder();
builder.alertTime(TimeUtil.nowStr());
JobDataDto jobDataDto = jobInfoDetail.getJobDataDto();
JobConfig job = JsonUtils.parseObject(jobInfoDetail.getHistory().getConfigJson(), JobConfig.class);
ClusterInstance clusterInstance = jobInfoDetail.getClusterInstance();
CheckPointOverView checkpoints = jobDataDto.getCheckpoints();
FlinkJobExceptionsDetail exceptions = jobDataDto.getExceptions();
JobInstance jobInstance = jobInfoDetail.getInstance();
String id = jobInstance.getId().toString();
builder.jobStatus(jobInstance.getStatus())
.jobInstanceId(jobInstance.getId())
.taskId(jobInstance.getTaskId())
.taskUrl(buildTaskUrl(jobInstance))
.jobName(jobInstance.getName())
.jobId(jobInstance.getJid())
.duration(jobInstance.getDuration())
.jobStartTime(TimeUtil.convertTimeToString(jobInstance.getCreateTime()))
.jobEndTime(TimeUtil.convertTimeToString(jobInstance.getFinishTime()));
if (job != null) {
builder.batchModel(job.isBatchModel());
}
if (clusterInstance != null) {
builder.clusterName(clusterInstance.getName())
.clusterType(clusterInstance.getType())
.clusterHosts(clusterInstance.getHosts());
}
if (jobDataDto.isError()) {
builder.errorMsg(jobDataDto.getErrorMsg());
} else if (exceptions != null && ExceptionRule.isException(id, exceptions)) {
// The error message is too long to send an alarm,
// and only the first line of abnormal information is used
builder.isException(true).errorMsg(exceptions.getRootException().split("\n")[0]);
}
if (checkpoints != null) {
builder.checkpointCostTime(CheckpointsRule.checkpointTime(id, checkpoints))
.isCheckpointFailed(CheckpointsRule.checkFailed(id, checkpoints));
if (checkpoints.getCounts() != null) {
builder.checkpointFailedCount(checkpoints.getCounts().getNumberFailedCheckpoints())
.checkpointCompleteCount(checkpoints.getCounts().getNumberCompletedCheckpoints());
}
}
return builder.build();
}
}
...@@ -19,22 +19,31 @@ ...@@ -19,22 +19,31 @@
package org.dinky.data.options; package org.dinky.data.options;
public class AlertRuleOptions { public class JobAlertRuleOptions {
public static final String JOB_ALERT_SCHEDULE = "JobAlert"; public static final String OPTIONS_JOB_ALERT_RULE = "jobAlertRule";
public static final String JOB_ALERT_RULE_TIME = "time";
public static final String JOB_ALERT_RULE_JOB_DETAIL = "jobDetail"; /**
public static final String JOB_ALERT_RULE_JOB_NAME = "job"; * Job Alert Data Filed record
public static final String JOB_ALERT_RULE_KEY = "key"; */
public static final String JOB_ALERT_RULE_JOB_INSTANCE = "jobInstance"; public static final String FIELD_NAME_TIME = "alertTime";
public static final String JOB_ALERT_RULE_START_TIME = "startTime";
public static final String JOB_ALERT_RULE_END_TIME = "endTime"; public static final String FIELD_NAME_START_TIME = "jobStartTime";
public static final String JOB_ALERT_RULE_CHECK_POINTS = "checkPoints"; public static final String FIELD_NAME_END_TIME = "jobEndTime";
public static final String JOB_ALERT_RULE_CLUSTER = "cluster"; public static final String FIELD_NAME_DURATION = "duration";
public static final String JOB_ALERT_RULE_EXCEPTIONS = "exceptions"; public static final String FIELD_NAME_JOB_NAME = "jobName";
public static final String JOB_ALERT_RULE_EXCEPTIONS_MSG = "exceptions_msg"; public static final String FIELD_NAME_JOB_ID = "jobId";
public static final String JOB_ALERT_RULE_EXCEPTION_CHECK = "exceptionRule"; public static final String FIELD_NAME_JOB_STATUS = "jobStatus";
public static final String JOB_ALERT_RULE_CHECKPOINT_RULES = "checkpointRule"; public static final String FIELD_TASK_ID = "taskId";
public static final String JOB_ALERT_RULE_TASK = "task"; public static final String FIELD_JOB_INSTANCE_ID = "jobInstanceId";
public static final String JOB_ALERT_RULE_TASK_URL = "taskUrl"; public static final String FIELD_JOB_TASK_URL = "taskUrl";
public static final String JOB_ALERT_RULE = "rule"; public static final String FIELD_JOB_BATCH_MODEL = "batchModel";
public static final String FIELD_NAME_CLUSTER_NAME = "clusterName";
public static final String FIELD_NAME_CLUSTER_TYPE = "clusterType";
public static final String FIELD_NAME_CLUSTER_HOSTS = "clusterHost";
public static final String FIELD_NAME_EXCEPTIONS_MSG = "errorMsg";
public static final String FIELD_NAME_CHECKPOINT_COST_TIME = "checkpointCostTime";
public static final String FIELD_NAME_CHECKPOINT_FAILED_COUNT = "checkpointFailedCount";
public static final String FIELD_NAME_CHECKPOINT_COMPLETE_COUNT = "checkpointCompleteCount";
public static final String FIELD_NAME_CHECKPOINT_FAILED = "isCheckpointFailed";
public static final String FIELD_NAME_IS_EXCEPTION = "isException";
} }
...@@ -22,8 +22,6 @@ package org.dinky.job.handler; ...@@ -22,8 +22,6 @@ package org.dinky.job.handler;
import org.dinky.alert.Alert; import org.dinky.alert.Alert;
import org.dinky.alert.AlertConfig; import org.dinky.alert.AlertConfig;
import org.dinky.alert.AlertResult; import org.dinky.alert.AlertResult;
import org.dinky.alert.rules.CheckpointsRule;
import org.dinky.alert.rules.ExceptionRule;
import org.dinky.assertion.Asserts; import org.dinky.assertion.Asserts;
import org.dinky.context.FreeMarkerHolder; import org.dinky.context.FreeMarkerHolder;
import org.dinky.context.SpringContextUtils; import org.dinky.context.SpringContextUtils;
...@@ -31,19 +29,17 @@ import org.dinky.daemon.pool.FlinkJobThreadPool; ...@@ -31,19 +29,17 @@ import org.dinky.daemon.pool.FlinkJobThreadPool;
import org.dinky.data.dto.AlertRuleDTO; import org.dinky.data.dto.AlertRuleDTO;
import org.dinky.data.dto.TaskDTO; import org.dinky.data.dto.TaskDTO;
import org.dinky.data.enums.Status; import org.dinky.data.enums.Status;
import org.dinky.data.model.SystemConfiguration;
import org.dinky.data.model.alert.AlertGroup; import org.dinky.data.model.alert.AlertGroup;
import org.dinky.data.model.alert.AlertHistory; import org.dinky.data.model.alert.AlertHistory;
import org.dinky.data.model.alert.AlertInstance; import org.dinky.data.model.alert.AlertInstance;
import org.dinky.data.model.ext.JobAlertData;
import org.dinky.data.model.ext.JobInfoDetail; import org.dinky.data.model.ext.JobInfoDetail;
import org.dinky.data.model.job.JobInstance; import org.dinky.data.options.JobAlertRuleOptions;
import org.dinky.data.options.AlertRuleOptions;
import org.dinky.service.AlertGroupService; import org.dinky.service.AlertGroupService;
import org.dinky.service.AlertHistoryService; import org.dinky.service.AlertHistoryService;
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.utils.JsonUtils; import org.dinky.utils.JsonUtils;
import org.dinky.utils.TimeUtil;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
...@@ -111,9 +107,6 @@ public class JobAlertHandler { ...@@ -111,9 +107,6 @@ public class JobAlertHandler {
return defaultJobAlertHandler; return defaultJobAlertHandler;
} }
/**
* Initializes the JobAlerts class by refreshing rules and setting up the scheduler.
*/
public JobAlertHandler() { public JobAlertHandler() {
refreshRulesData(); refreshRulesData();
} }
...@@ -123,47 +116,8 @@ public class JobAlertHandler { ...@@ -123,47 +116,8 @@ public class JobAlertHandler {
*/ */
public void check(JobInfoDetail jobInfoDetail) { public void check(JobInfoDetail jobInfoDetail) {
Facts ruleFacts = new Facts(); Facts ruleFacts = new Facts();
ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_EXCEPTION_CHECK, new ExceptionRule()); JobAlertData jobAlertData = JobAlertData.buildData(jobInfoDetail);
ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_CHECKPOINT_RULES, new CheckpointsRule()); JsonUtils.toMap(jobAlertData).forEach(ruleFacts::put);
ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_TIME, TimeUtil.nowStr());
ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_JOB_DETAIL, jobInfoDetail);
if (Asserts.isNotNull(jobInfoDetail.getJobDataDto().getJob())) {
ruleFacts.put(
AlertRuleOptions.JOB_ALERT_RULE_JOB_NAME,
jobInfoDetail.getJobDataDto().getJob());
}
ruleFacts.put(
AlertRuleOptions.JOB_ALERT_RULE_KEY, jobInfoDetail.getInstance().getId());
ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_JOB_INSTANCE, jobInfoDetail.getInstance());
ruleFacts.put(
AlertRuleOptions.JOB_ALERT_RULE_START_TIME,
TimeUtil.convertTimeToString(jobInfoDetail.getInstance().getCreateTime()));
ruleFacts.put(
AlertRuleOptions.JOB_ALERT_RULE_END_TIME,
TimeUtil.convertTimeToString(jobInfoDetail.getInstance().getFinishTime()));
if (Asserts.isNotNull(jobInfoDetail.getJobDataDto().getCheckpoints())) {
ruleFacts.put(
AlertRuleOptions.JOB_ALERT_RULE_CHECK_POINTS,
jobInfoDetail.getJobDataDto().getCheckpoints());
}
ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_CLUSTER, jobInfoDetail.getClusterInstance());
ruleFacts.put(
AlertRuleOptions.JOB_ALERT_RULE_EXCEPTIONS,
jobInfoDetail.getJobDataDto().getExceptions());
if (jobInfoDetail.getJobDataDto().isError()) {
ruleFacts.put(
AlertRuleOptions.JOB_ALERT_RULE_EXCEPTIONS_MSG,
jobInfoDetail.getJobDataDto().getErrorMsg());
} else {
if (Asserts.isNotNull(jobInfoDetail.getJobDataDto().getExceptions().getRootException())) {
ruleFacts.put(
AlertRuleOptions.JOB_ALERT_RULE_EXCEPTIONS_MSG,
jobInfoDetail.getJobDataDto().getExceptions().getRootException());
}
}
rulesEngine.fire(rules, ruleFacts); rulesEngine.fire(rules, ruleFacts);
} }
...@@ -216,21 +170,10 @@ public class JobAlertHandler { ...@@ -216,21 +170,10 @@ public class JobAlertHandler {
* @param alertRuleDTO Alert Rule Info. * @param alertRuleDTO Alert Rule Info.
*/ */
private void executeAlertAction(Facts facts, AlertRuleDTO alertRuleDTO) { private void executeAlertAction(Facts facts, AlertRuleDTO alertRuleDTO) {
JobInfoDetail jobInfoDetail = facts.get(AlertRuleOptions.JOB_ALERT_RULE_JOB_DETAIL); TaskDTO task = taskService.getTaskInfoById(facts.get(JobAlertRuleOptions.FIELD_TASK_ID));
JobInstance jobInstance = jobInfoDetail.getInstance();
TaskDTO task = taskService.getTaskInfoById(jobInfoDetail.getInstance().getTaskId());
String taskUrl = StrFormatter.format(
"{}/#/devops/job-detail?id={}",
SystemConfiguration.getInstances().getDinkyAddr(),
task.getId());
Map<String, Object> dataModel = new HashMap<>(facts.asMap()); Map<String, Object> dataModel = new HashMap<>(facts.asMap());
dataModel.put(AlertRuleOptions.JOB_ALERT_RULE_TASK, task); dataModel.put(JobAlertRuleOptions.OPTIONS_JOB_ALERT_RULE, alertRuleDTO);
dataModel.put(AlertRuleOptions.JOB_ALERT_RULE_TASK_URL, taskUrl);
dataModel.put(AlertRuleOptions.JOB_ALERT_RULE, alertRuleDTO);
String alertContent; String alertContent;
try { try {
alertContent = freeMarkerHolder.buildWithData(alertRuleDTO.getTemplateName(), dataModel); alertContent = freeMarkerHolder.buildWithData(alertRuleDTO.getTemplateName(), dataModel);
} catch (IOException | TemplateException e) { } catch (IOException | TemplateException e) {
...@@ -247,7 +190,7 @@ public class JobAlertHandler { ...@@ -247,7 +190,7 @@ public class JobAlertHandler {
} }
sendAlert( sendAlert(
alertInstance, alertInstance,
jobInstance.getId(), facts.get(JobAlertRuleOptions.FIELD_JOB_INSTANCE_ID),
alertGroup.getId(), alertGroup.getId(),
alertRuleDTO.getName(), alertRuleDTO.getName(),
alertContent); alertContent);
......
...@@ -228,9 +228,13 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -228,9 +228,13 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
Optional.ofNullable(task.getClusterId()).ifPresent(config::setClusterId); Optional.ofNullable(task.getClusterId()).ifPresent(config::setClusterId);
} }
log.info("Init remote cluster"); log.info("Init remote cluster");
Optional.ofNullable(config.getClusterId()).ifPresent(i -> { try {
config.setAddress(clusterInstanceService.buildEnvironmentAddress(config.isUseRemote(), i)); Optional.ofNullable(config.getClusterId()).ifPresent(i -> {
}); config.setAddress(clusterInstanceService.buildEnvironmentAddress(config.isUseRemote(), i));
});
} catch (Exception e) {
log.error("Init remote cluster error", e);
}
return config; return config;
} }
...@@ -267,9 +271,6 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -267,9 +271,6 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
// 注解自调用会失效,这里通过获取对象方法绕过此限制 // 注解自调用会失效,这里通过获取对象方法绕过此限制
TaskServiceImpl taskServiceBean = applicationContext.getBean(TaskServiceImpl.class); TaskServiceImpl taskServiceBean = applicationContext.getBean(TaskServiceImpl.class);
TaskDTO taskDTO = taskServiceBean.prepareTask(submitDto); TaskDTO taskDTO = taskServiceBean.prepareTask(submitDto);
// The job instance does not exist by default,
// so that it does not affect other operations, such as checking the jobmanager address
taskDTO.setJobInstanceId(null);
JobResult jobResult = taskServiceBean.executeJob(taskDTO); JobResult jobResult = taskServiceBean.executeJob(taskDTO);
log.info("Job Submit success"); log.info("Job Submit success");
Task task = new Task(submitDto.getId(), jobResult.getJobInstanceId()); Task task = new Task(submitDto.getId(), jobResult.getJobInstanceId());
......
...@@ -472,45 +472,21 @@ VALUES (146, 10, ' 拷贝', '/registration/datasource/copy', null, 'registration ...@@ -472,45 +472,21 @@ VALUES (146, 10, ' 拷贝', '/registration/datasource/copy', null, 'registration
-- ---------------------------- -- ----------------------------
-- Records of dinky_alert_rule -- Records of dinky_alert_rule
-- ---------------------------- -- ----------------------------
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (3, 'alert.rule.jobFail', '[{"ruleKey":"jobStatus","ruleOperator":"EQ","ruleValue":"''FAILED''","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
create_time, update_time) INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (4, 'alert.rule.getJobInfoFail', '[{"ruleKey":"jobStatus","ruleOperator":"EQ","ruleValue":"''UNKNOWN''","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
VALUES (3, 'alert.rule.jobFail', INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (5, 'alert.rule.jobRestart', '[{"ruleKey":"jobStatus","ruleOperator":"EQ","ruleValue":"''RESTARTING''","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
'[{"ruleKey":"jobInstance.status","ruleOperator":"EQ","ruleValue":"''FAILED''","rulePriority":"1"}]', 1, INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (6, 'alert.rule.checkpointFail', '[{"ruleKey":"isCheckpointFailed","ruleOperator":"EQ","ruleValue":"true"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-04 23:03:02'); INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (7, 'alert.rule.jobRunException', '[{"ruleKey":"isException","ruleOperator":"EQ","ruleValue":"true"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled,
create_time, update_time)
VALUES (4, 'alert.rule.getJobInfoFail',
'[{"ruleKey":"jobInstance.status","ruleOperator":"EQ","ruleValue":"''UNKNOWN''","rulePriority":"1"}]', 1,
'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-05 18:03:43');
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled,
create_time, update_time)
VALUES (5, 'alert.rule.jobRestart',
'[{"ruleKey":"jobInstance.status","ruleOperator":"EQ","ruleValue":"''RESTARTING''","rulePriority":"1"}]', 1,
'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-06 21:35:12');
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled,
create_time, update_time)
VALUES (6, 'alert.rule.checkpointFail',
'[{"ruleKey":"checkpointRule.checkFailed(#key,#checkPoints)","ruleOperator":"EQ","ruleValue":"true"}]', 1,
'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-06 21:49:03');
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled,
create_time, update_time)
VALUES (7, 'alert.rule.jobRunException',
'[{"ruleKey":"exceptionRule.isException(#key,#exceptions)","ruleOperator":"EQ","ruleValue":"true"}]', 1,
'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-06 21:50:12');
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled,
create_time, update_time)
VALUES (8, 'alert.rule.checkpointTimeout',
'[{"ruleKey":"checkpointRule.checkpointTime(#key,#checkPoints)","ruleOperator":"GE","ruleValue":"1000"}]', 1,
'CUSTOM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-06 22:23:35');
INSERT INTO dinky_alert_template INSERT INTO dinky_alert_template
VALUES (1, 'Default', ' VALUES (1, 'Default', '
- **Job Name :** <font color=''gray''>${task.name}</font> - **Job Name :** <font color=''gray''>${jobName}</font>
- **Job Status :** <font color=''red''>${jobInstance.status}</font> - **Job Status :** <font color=''red''>${jobStatus}</font>
- **Alert Time :** ${time} - **Alert Time :** ${alertTime}
- **Start Time :** ${startTime} - **Start Time :** ${jobStartTime}
- **End Time :** ${endTime} - **End Time :** ${jobEndTime}
- **<font color=''red''>${(exceptions.rootException)?substring(0,20)}</font>** - **<font color=''red''>${errorMsg}</font>**
[Go toTask Web](http://${taskUrl}) [Go toTask Web](http://${taskUrl})
', 1, current_timestamp, current_timestamp,null,null); ', 1, current_timestamp, current_timestamp,null,null);
......
...@@ -38,28 +38,21 @@ public class CheckpointsRule { ...@@ -38,28 +38,21 @@ public class CheckpointsRule {
private static final Logger logger = LoggerFactory.getLogger(CheckpointsRule.class); private static final Logger logger = LoggerFactory.getLogger(CheckpointsRule.class);
private final LoadingCache<String, Object> checkpointsCache; private static final LoadingCache<String, Object> checkpointsCache =
CacheBuilder.newBuilder().expireAfterAccess(60, TimeUnit.SECONDS).build(CacheLoader.from(key -> null));
/**
* Constructor for initializing the CheckpointsRule object.
*/
public CheckpointsRule() {
checkpointsCache = CacheBuilder.newBuilder()
.expireAfterAccess(60, TimeUnit.SECONDS)
.build(CacheLoader.from(key -> null));
}
/** /**
* Checks if a checkpoint has expired. * Checks if a checkpoint has expired.
*
* @param latest The latest checkpoint node. * @param latest The latest checkpoint node.
* @param key The key used to identify the checkpoint. * @param jobInstanceID The key used to identify the checkpoint.
* @param ckKey The checkpoint key to check for expiration. * @param ckKey The checkpoint key to check for expiration.
* @return True if the checkpoint has expired, false otherwise. * @return True if the checkpoint has expired, false otherwise.
*/ */
private boolean isExpire(CheckPointOverView latest, String key, String ckKey) { private static boolean isExpire(CheckPointOverView latest, String jobInstanceID, String ckKey) {
logger.debug("checkpointTime key: {} ,checkpoints: {}, key: {}", key, latest, ckKey); logger.debug("checkpointTime key: {} ,checkpoints: {}, key: {}", jobInstanceID, latest, ckKey);
CheckPointOverView his = (CheckPointOverView) checkpointsCache.getIfPresent(key); CheckPointOverView his = (CheckPointOverView) checkpointsCache.getIfPresent(jobInstanceID);
switch (ckKey) { switch (ckKey) {
case "completed": case "completed":
...@@ -89,7 +82,7 @@ public class CheckpointsRule { ...@@ -89,7 +82,7 @@ public class CheckpointsRule {
} }
long latestTime = long latestTime =
latestLatestCheckpoints.getFailedCheckpointStatistics().getTriggerTimestamp(); latestLatestCheckpoints.getFailedCheckpointStatistics().getTriggerTimestamp();
checkpointsCache.put(key, latest); checkpointsCache.put(jobInstanceID, latest);
if (his != null) { if (his != null) {
long hisTime = 0; long hisTime = 0;
if (failedCheckpointStatistics != null) { if (failedCheckpointStatistics != null) {
...@@ -106,18 +99,19 @@ public class CheckpointsRule { ...@@ -106,18 +99,19 @@ public class CheckpointsRule {
/** /**
* Retrieves the checkpoint time for a specific key. * Retrieves the checkpoint time for a specific key.
* @param key The key used to identify the checkpoint. *
* @param key The key used to identify the checkpoint.
* @param checkpoints The checkpoints object containing relevant data. * @param checkpoints The checkpoints object containing relevant data.
* @return The checkpoint time, or null if the checkpoint has expired. * @return The checkpoint time, or null if the checkpoint has expired.
*/ */
public Long checkpointTime(String key, CheckPointOverView checkpoints) { public static Long checkpointTime(String key, CheckPointOverView checkpoints) {
if (isExpire(checkpoints, key, "completed")) { if (isExpire(checkpoints, key, "completed")) {
return null; return -1L;
} }
CheckPointOverView.LatestCheckpoints checkpointsLatestCheckpoints = checkpoints.getLatestCheckpoints(); CheckPointOverView.LatestCheckpoints checkpointsLatestCheckpoints = checkpoints.getLatestCheckpoints();
if (null == checkpointsLatestCheckpoints if (null == checkpointsLatestCheckpoints
|| null == checkpointsLatestCheckpoints.getCompletedCheckpointStatistics()) { || null == checkpointsLatestCheckpoints.getCompletedCheckpointStatistics()) {
return null; return -1L;
} }
return checkpoints return checkpoints
.getLatestCheckpoints() .getLatestCheckpoints()
...@@ -127,11 +121,12 @@ public class CheckpointsRule { ...@@ -127,11 +121,12 @@ public class CheckpointsRule {
/** /**
* Checks if a specific checkpoint has failed. * Checks if a specific checkpoint has failed.
* @param key The key used to identify the checkpoint. *
* @param key The key used to identify the checkpoint.
* @param checkpoints The checkpoints object containing relevant data. * @param checkpoints The checkpoints object containing relevant data.
* @return True if the checkpoint has failed, null if it has expired. * @return True if the checkpoint has failed, null if it has expired.
*/ */
public Boolean checkFailed(String key, CheckPointOverView checkpoints) { public static Boolean checkFailed(String key, CheckPointOverView checkpoints) {
return !isExpire(checkpoints, key, "failed"); return !isExpire(checkpoints, key, "failed");
} }
} }
...@@ -29,33 +29,28 @@ import com.google.common.cache.LoadingCache; ...@@ -29,33 +29,28 @@ import com.google.common.cache.LoadingCache;
public class ExceptionRule { public class ExceptionRule {
private final LoadingCache<Integer, Long> hisTime; private static final LoadingCache<String, Long> hisTime =
CacheBuilder.newBuilder().expireAfterAccess(60, TimeUnit.SECONDS).build(CacheLoader.from(key -> null));
public ExceptionRule() {
hisTime = CacheBuilder.newBuilder()
.expireAfterAccess(60, TimeUnit.SECONDS)
.build(CacheLoader.from(key -> null));
}
/** /**
* Executes a certain operation based on the provided key and exceptions object. * Executes a certain operation based on the provided key and exceptions object.
* This method is stored within the database, is called through SPEL, and is not an executable method * This method is stored within the database, is called through SPEL, and is not an executable method
* @param key The key used to identify the operation. * @param jobinstanceId The key used to identify the operation.
* @param exceptions The exceptions object containing relevant data. * @param exceptions The exceptions object containing relevant data.
* @return True if the operation should be executed, false otherwise. * @return True if the operation should be executed, false otherwise.
*/ */
public Boolean isException(Integer key, FlinkJobExceptionsDetail exceptions) { public static Boolean isException(String jobinstanceId, FlinkJobExceptionsDetail exceptions) {
// If the exception is the same as the previous one, it will not be reported again // If the exception is the same as the previous one, it will not be reported again
if (exceptions.getTimestamp() == null) { if (exceptions.getTimestamp() == null) {
return false; return false;
} }
long timestamp = exceptions.getTimestamp(); long timestamp = exceptions.getTimestamp();
Long hisTimeIfPresent = hisTime.getIfPresent(key); Long hisTimeIfPresent = hisTime.getIfPresent(jobinstanceId);
if (hisTimeIfPresent != null && hisTimeIfPresent == timestamp) { if (hisTimeIfPresent != null && hisTimeIfPresent == timestamp) {
return false; return false;
} }
hisTime.put(key, timestamp); hisTime.put(jobinstanceId, timestamp);
if (exceptions.getRootException() != null) { if (exceptions.getRootException() != null) {
return !exceptions.getRootException().isEmpty(); return !exceptions.getRootException().isEmpty();
} else { } else {
......
...@@ -135,6 +135,10 @@ public class JsonUtils { ...@@ -135,6 +135,10 @@ public class JsonUtils {
return parseObject(json, new TypeReference<Map<String, String>>() {}); return parseObject(json, new TypeReference<Map<String, String>>() {});
} }
public static Map<String, Object> toMap(Object o) {
return objectMapper.convertValue(o, new TypeReference<Map<String, Object>>() {});
}
public static <K, V> Map<K, V> toMap(String json, Class<K> classK, Class<V> classV) { public static <K, V> Map<K, V> toMap(String json, Class<K> classK, Class<V> classV) {
return parseObject(json, new TypeReference<Map<K, V>>() {}); return parseObject(json, new TypeReference<Map<K, V>>() {});
} }
......
...@@ -900,15 +900,18 @@ export default { ...@@ -900,15 +900,18 @@ export default {
* sys * sys
* *
* */ * */
'sys.alert.rule.label.taskId': 'Task ID',
'sys.alert.rule.label.duration': 'Running time',
'sys.alert.rule.label.batchModel': 'Batch mode',
'sys.alert.rule.label.jobType': 'Execution mode',
'sys.alert.rule.label.jobException': 'The job is abnormal',
'sys.alert.rule.label.checkpointFailed': 'Checkpoint Failed',
'sys.alert.rule.label.checkpointTime': 'CheckPoint Time',
'sys.alert.rule.label.jobStatus': 'Job status',
'sys.alert.rule.addRule': 'Add Rule', 'sys.alert.rule.addRule': 'Add Rule',
'sys.alert.rule.allRule': 'All Rules', 'sys.alert.rule.allRule': 'All Rules',
'sys.alert.rule.anyRule': 'Any Rule', 'sys.alert.rule.anyRule': 'Any Rule',
'sys.alert.rule.checkpointFailed': 'Checkpoint Failed',
'sys.alert.rule.checkpointTime': 'Checkpoint Time',
'sys.alert.rule.delete': 'Are you sure you want to delete this alert rule?', 'sys.alert.rule.delete': 'Are you sure you want to delete this alert rule?',
'sys.alert.rule.jobException': 'Job Exception',
'sys.alert.rule.jobStatus': 'Job Status',
'sys.alert.rule.name': 'Alert Rule Name', 'sys.alert.rule.name': 'Alert Rule Name',
'sys.alert.rule.rule': 'Rule', 'sys.alert.rule.rule': 'Rule',
'sys.alert.rule.ruleType': 'Rule Type', 'sys.alert.rule.ruleType': 'Rule Type',
......
...@@ -861,15 +861,18 @@ export default { ...@@ -861,15 +861,18 @@ export default {
* sys * sys
* *
* */ * */
'sys.alert.rule.label.taskId': '作业ID',
'sys.alert.rule.label.duration': '运行时间',
'sys.alert.rule.label.batchModel': '批模式',
'sys.alert.rule.label.jobType': '执行模式',
'sys.alert.rule.label.jobException': '作业产生异常',
'sys.alert.rule.label.checkpointFailed': 'Checkpoint失败',
'sys.alert.rule.label.checkpointTime': 'CheckPoint时间',
'sys.alert.rule.label.jobStatus': '作业状态',
'sys.alert.rule.addRule': '添加规则', 'sys.alert.rule.addRule': '添加规则',
'sys.alert.rule.allRule': '所有规则', 'sys.alert.rule.allRule': '所有规则',
'sys.alert.rule.anyRule': '任意规则', 'sys.alert.rule.anyRule': '任意规则',
'sys.alert.rule.checkpointFailed': 'Checkpoint失败',
'sys.alert.rule.checkpointTime': 'CheckPoint时间',
'sys.alert.rule.delete': '你确定要删除该告警策略吗?', 'sys.alert.rule.delete': '你确定要删除该告警策略吗?',
'sys.alert.rule.jobException': '作业产生异常',
'sys.alert.rule.jobStatus': '作业状态',
'sys.alert.rule.name': '告警策略名称', 'sys.alert.rule.name': '告警策略名称',
'sys.alert.rule.rule': '规则', 'sys.alert.rule.rule': '规则',
'sys.alert.rule.ruleType': '规则类型', 'sys.alert.rule.ruleType': '规则类型',
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* *
*/ */
export const enum ClusterType { export enum ClusterType {
STANDALONE = 'standalone', STANDALONE = 'standalone',
YARN = 'yarn-application', YARN = 'yarn-application',
YARN_SESSION = 'yarn-session', YARN_SESSION = 'yarn-session',
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
* *
*/ */
import { JOB_STATUS } from '@/pages/DevOps/constants';
import { ClusterType } from '@/pages/RegCenter/Cluster/constants';
import { l } from '@/utils/intl'; import { l } from '@/utils/intl';
import { CheckboxOptionType } from 'antd/es/checkbox/Group'; import { CheckboxOptionType } from 'antd/es/checkbox/Group';
import { DefaultOptionType } from 'antd/es/select'; import { DefaultOptionType } from 'antd/es/select';
...@@ -26,25 +28,18 @@ export enum RuleType { ...@@ -26,25 +28,18 @@ export enum RuleType {
CUSTOM = 'CUSTOM' CUSTOM = 'CUSTOM'
} }
export enum OperatorType {
OPTIONS_SEL = 'OPTIONS_SEL',
STR_VALUE = 'STR_VALUE',
NUMBER_VALUE = 'NUMBER_VALUE'
}
export const TriggerType: CheckboxOptionType[] = [ export const TriggerType: CheckboxOptionType[] = [
{ label: l('sys.alert.rule.anyRule'), value: ' or ' }, { label: l('sys.alert.rule.anyRule'), value: ' or ' },
{ label: l('sys.alert.rule.allRule'), value: ' and ' } { label: l('sys.alert.rule.allRule'), value: ' and ' }
]; ];
export const AlertRules: DefaultOptionType[] = [ export const AllRuleOperator: DefaultOptionType[] = [
{ label: l('sys.alert.rule.jobStatus'), value: 'jobInstance.status' },
{
label: l('sys.alert.rule.checkpointTime'),
value: 'checkPoints.checkpointTime(#key,#checkPoints)'
},
{
label: l('sys.alert.rule.checkpointFailed'),
value: 'checkPoints.checkFailed(#key,#checkPoints)'
},
{ label: l('sys.alert.rule.jobException'), value: 'exceptionRule.isException(#key,#exceptions)' }
];
export const RuleOperator: DefaultOptionType[] = [
{ label: '>', value: 'GT' }, { label: '>', value: 'GT' },
{ label: '<', value: 'LT' }, { label: '<', value: 'LT' },
{ label: '=', value: 'EQ' }, { label: '=', value: 'EQ' },
...@@ -52,3 +47,52 @@ export const RuleOperator: DefaultOptionType[] = [ ...@@ -52,3 +47,52 @@ export const RuleOperator: DefaultOptionType[] = [
{ label: '>=', value: 'GE' }, { label: '>=', value: 'GE' },
{ label: '<=', value: 'LE' } { label: '<=', value: 'LE' }
]; ];
export const EqRuleOperator: DefaultOptionType[] = [{ label: '=', value: 'EQ' }];
export const BOOLEAN_VALUE_ENUM: DefaultOptionType[] = [
{ label: 'True', value: 'true' },
{ label: 'False', value: 'false' }
];
export const AlertRules: any = {
jobName: {
label: l('sys.alert.rule.label.taskId'),
valueType: OperatorType.NUMBER_VALUE,
options_enum: EqRuleOperator
},
duration: {
label: l('sys.alert.rule.label.duration'),
valueType: OperatorType.NUMBER_VALUE
},
jobStatus: {
label: l('sys.alert.rule.label.jobStatus'),
valueType: OperatorType.OPTIONS_SEL,
valueEnum: Object.values(JOB_STATUS).map((t) => `'${t}'`)
},
batchModel: {
label: l('sys.alert.rule.label.batchModel'),
valueType: OperatorType.OPTIONS_SEL,
valueEnum: BOOLEAN_VALUE_ENUM
},
clusterType: {
label: l('sys.alert.rule.label.jobType'),
valueType: OperatorType.OPTIONS_SEL,
valueEnum: Object.values(ClusterType).map((t) => `'${t}'`)
},
checkpointCostTime: {
label: l('sys.alert.rule.label.checkpointTime'),
valueType: OperatorType.OPTIONS_SEL,
valueEnum: BOOLEAN_VALUE_ENUM
},
isCheckpointFailed: {
label: l('sys.alert.rule.label.checkpointFailed'),
valueType: OperatorType.OPTIONS_SEL,
valueEnum: BOOLEAN_VALUE_ENUM
},
isException: {
label: l('sys.alert.rule.label.jobException'),
valueType: OperatorType.OPTIONS_SEL,
valueEnum: BOOLEAN_VALUE_ENUM
}
};
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {
AlertRules,
AllRuleOperator,
EqRuleOperator,
OperatorType
} from '@/pages/SettingCenter/AlertRule/AlertRuleList/RuleEditForm/constants';
import { l } from '@/utils/intl';
import { ProFormDigit, ProFormSelect, ProFormText } from '@ant-design/pro-components';
import { DefaultOptionType } from 'antd/es/select';
export const AlertRulesOption = () => {
const res: DefaultOptionType[] = [];
for (const [k, v] of Object.entries(AlertRules)) {
res.push({
// @ts-ignore
label: v.label,
value: k
});
}
return res;
};
export const getOperatorOptions = (key: string) => {
if (key && key in AlertRules) {
if (AlertRules[key].valueType == OperatorType.NUMBER_VALUE) {
return AllRuleOperator;
} else {
return EqRuleOperator;
}
} else {
return [];
}
};
export const buildValueItem = (key: string, isSystem: boolean) => {
const plh = l('pages.datastudio.label.jobConfig.addConfig.value');
if (key && key in AlertRules) {
switch (AlertRules[key].valueType) {
case OperatorType.NUMBER_VALUE:
return (
<ProFormDigit
disabled={isSystem}
name={'ruleValue'}
fieldProps={{ precision: 0 }}
placeholder={plh}
/>
);
case OperatorType.STR_VALUE:
return <ProFormText disabled={isSystem} name={'ruleValue'} placeholder={plh} />;
case OperatorType.OPTIONS_SEL:
return (
<ProFormSelect
disabled={isSystem}
name='ruleValue'
mode={'single'}
placeholder={plh}
options={AlertRules[key].valueEnum}
/>
);
}
}
return <span></span>;
};
...@@ -18,11 +18,14 @@ ...@@ -18,11 +18,14 @@
*/ */
import { import {
AlertRules,
RuleOperator,
RuleType, RuleType,
TriggerType TriggerType
} from '@/pages/SettingCenter/AlertRule/constants'; } from '@/pages/SettingCenter/AlertRule/AlertRuleList/RuleEditForm/constants';
import {
AlertRulesOption,
buildValueItem,
getOperatorOptions
} from '@/pages/SettingCenter/AlertRule/AlertRuleList/RuleEditForm/function';
import { getData } from '@/services/api'; import { getData } from '@/services/api';
import { SWITCH_OPTIONS } from '@/services/constants'; import { SWITCH_OPTIONS } from '@/services/constants';
import { API_CONSTANTS } from '@/services/endpoints'; import { API_CONSTANTS } from '@/services/endpoints';
...@@ -41,6 +44,7 @@ import { ...@@ -41,6 +44,7 @@ import {
ProFormText, ProFormText,
ProFormTextArea ProFormTextArea
} from '@ant-design/pro-components'; } from '@ant-design/pro-components';
import { ProFormDependency } from '@ant-design/pro-form';
import { Button, Divider, Form, Space } from 'antd'; import { Button, Divider, Form, Space } from 'antd';
type AlertRuleFormProps = { type AlertRuleFormProps = {
...@@ -159,20 +163,21 @@ const RuleEditForm = (props: AlertRuleFormProps) => { ...@@ -159,20 +163,21 @@ const RuleEditForm = (props: AlertRuleFormProps) => {
name='ruleKey' name='ruleKey'
width={'sm'} width={'sm'}
mode={'single'} mode={'single'}
options={AlertRules} options={AlertRulesOption()}
/>
<ProFormSelect
disabled={isSystem}
name='ruleOperator'
mode={'single'}
options={RuleOperator}
/>
<ProFormText
disabled={isSystem}
name={'ruleValue'}
placeholder={l('pages.datastudio.label.jobConfig.addConfig.value')}
/> />
<ProFormDependency name={['ruleKey']}>
{(ruleKey) => (
<ProFormSelect
disabled={isSystem}
name='ruleOperator'
mode={'single'}
options={getOperatorOptions(ruleKey.ruleKey)}
/>
)}
</ProFormDependency>
<ProFormDependency name={['ruleKey']}>
{(ruleKey) => buildValueItem(ruleKey.ruleKey, isSystem)}
</ProFormDependency>
</Space> </Space>
</ProFormGroup> </ProFormGroup>
</ProFormList> </ProFormList>
......
...@@ -23,7 +23,7 @@ import { EnableSwitchBtn } from '@/components/CallBackButton/EnableSwitchBtn'; ...@@ -23,7 +23,7 @@ import { EnableSwitchBtn } from '@/components/CallBackButton/EnableSwitchBtn';
import { PopconfirmDeleteBtn } from '@/components/CallBackButton/PopconfirmDeleteBtn'; import { PopconfirmDeleteBtn } from '@/components/CallBackButton/PopconfirmDeleteBtn';
import { Authorized } from '@/hooks/useAccess'; import { Authorized } from '@/hooks/useAccess';
import RuleEditForm from '@/pages/SettingCenter/AlertRule/AlertRuleList/RuleEditForm'; import RuleEditForm from '@/pages/SettingCenter/AlertRule/AlertRuleList/RuleEditForm';
import { RuleType } from '@/pages/SettingCenter/AlertRule/constants'; import { RuleType } from '@/pages/SettingCenter/AlertRule/AlertRuleList/RuleEditForm/constants';
import { queryList } from '@/services/api'; import { queryList } from '@/services/api';
import { handleAddOrUpdate, handleRemoveById } from '@/services/BusinessCrud'; import { handleAddOrUpdate, handleRemoveById } from '@/services/BusinessCrud';
import { PROTABLE_OPTIONS_PUBLIC, STATUS_ENUM, STATUS_MAPPING } from '@/services/constants'; import { PROTABLE_OPTIONS_PUBLIC, STATUS_ENUM, STATUS_MAPPING } from '@/services/constants';
......
...@@ -1960,20 +1960,19 @@ CREATE TABLE `dinky_alert_rules` ( ...@@ -1960,20 +1960,19 @@ CREATE TABLE `dinky_alert_rules` (
-- Records of dinky_alert_rule -- Records of dinky_alert_rule
-- ---------------------------- -- ----------------------------
BEGIN; BEGIN;
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (3, 'alert.rule.jobFail', '[{"ruleKey":"jobInstance.status","ruleOperator":"EQ","ruleValue":"\'FAILED\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-04 23:03:02'); INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (3, 'alert.rule.jobFail', '[{"ruleKey":"jobStatus","ruleOperator":"EQ","ruleValue":"\'FAILED\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (4, 'alert.rule.getJobInfoFail', '[{"ruleKey":"jobInstance.status","ruleOperator":"EQ","ruleValue":"\'UNKNOWN\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-05 18:03:43'); INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (4, 'alert.rule.getJobInfoFail', '[{"ruleKey":"jobStatus","ruleOperator":"EQ","ruleValue":"\'UNKNOWN\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (5, 'alert.rule.jobRestart', '[{"ruleKey":"jobInstance.status","ruleOperator":"EQ","ruleValue":"\'RESTARTING\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-06 21:35:12'); INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (5, 'alert.rule.jobRestart', '[{"ruleKey":"jobStatus","ruleOperator":"EQ","ruleValue":"\'RESTARTING\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (6, 'alert.rule.checkpointFail', '[{"ruleKey":"checkpointRule.checkFailed(#key,#checkPoints)","ruleOperator":"EQ","ruleValue":"true"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-06 21:49:03'); INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (6, 'alert.rule.checkpointFail', '[{"ruleKey":"isCheckpointFailed","ruleOperator":"EQ","ruleValue":"true"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (7, 'alert.rule.jobRunException', '[{"ruleKey":"exceptionRule.isException(#key,#exceptions)","ruleOperator":"EQ","ruleValue":"true"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-06 21:50:12'); INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (7, 'alert.rule.jobRunException', '[{"ruleKey":"isException","ruleOperator":"EQ","ruleValue":"true"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (8, 'alert.rule.checkpointTimeout', '[{"ruleKey":"checkpointRule.checkpointTime(#key,#checkPoints)","ruleOperator":"GE","ruleValue":"1000"}]', 1, 'CUSTOM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-06 22:23:35');
INSERT INTO dinky_alert_template VALUES (1, 'Default', ' INSERT INTO dinky_alert_template VALUES (1, 'Default', '
- **Job Name :** <font color=''gray''>${task.name}</font> - **Job Name :** <font color=''gray''>${jobName}</font>
- **Job Status :** <font color=''red''>${jobInstance.status}</font> - **Job Status :** <font color=''red''>${jobStatus}</font>
- **Alert Time :** ${time} - **Alert Time :** ${alertTime}
- **Start Time :** ${startTime} - **Start Time :** ${jobStartTime}
- **End Time :** ${endTime} - **End Time :** ${jobEndTime}
- **<font color=''red''>${(exceptions.rootException)?substring(0,20)}</font>** - **<font color=''red''>${errorMsg}</font>**
[Go toTask Web](http://${taskUrl}) [Go toTask Web](http://${taskUrl})
', 1, current_timestamp(), current_timestamp(),null,null); ', 1, current_timestamp(), current_timestamp(),null,null);
......
...@@ -2801,20 +2801,20 @@ comment on column public.dinky_alert_rules.updater is 'updater'; ...@@ -2801,20 +2801,20 @@ comment on column public.dinky_alert_rules.updater is 'updater';
-- ---------------------------- -- ----------------------------
-- Records of dinky_alert_rule -- Records of dinky_alert_rule
-- ---------------------------- -- ----------------------------
INSERT INTO public.dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (3, 'alert.rule.jobFail', '[{"ruleKey":"jobInstance.status","ruleOperator":"EQ","ruleValue":"\'FAILED\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-04 23:03:02');
INSERT INTO public.dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (4, 'alert.rule.getJobInfoFail', '[{"ruleKey":"jobInstance.status","ruleOperator":"EQ","ruleValue":"\'UNKNOWN\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-05 18:03:43'); INSERT INTO public.dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (3, 'alert.rule.jobFail', '[{"ruleKey":"jobStatus","ruleOperator":"EQ","ruleValue":"\'FAILED\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
INSERT INTO public.dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (5, 'alert.rule.jobRestart', '[{"ruleKey":"jobInstance.status","ruleOperator":"EQ","ruleValue":"\'RESTARTING\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-06 21:35:12'); INSERT INTO public.dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (4, 'alert.rule.getJobInfoFail', '[{"ruleKey":"jobStatus","ruleOperator":"EQ","ruleValue":"\'UNKNOWN\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
INSERT INTO public.dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (6, 'alert.rule.checkpointFail', '[{"ruleKey":"checkpointRule.checkFailed(#key,#checkPoints)","ruleOperator":"EQ","ruleValue":"true"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-06 21:49:03'); INSERT INTO public.dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (5, 'alert.rule.jobRestart', '[{"ruleKey":"jobStatus","ruleOperator":"EQ","ruleValue":"\'RESTARTING\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
INSERT INTO public.dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (7, 'alert.rule.jobRunException', '[{"ruleKey":"exceptionRule.isException(#key,#exceptions)","ruleOperator":"EQ","ruleValue":"true"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-06 21:50:12'); INSERT INTO public.dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (6, 'alert.rule.checkpointFail', '[{"ruleKey":"isCheckpointFailed","ruleOperator":"EQ","ruleValue":"true"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
INSERT INTO public.dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (8, 'alert.rule.checkpointTimeout', '[{"ruleKey":"checkpointRule.checkpointTime(#key,#checkPoints)","ruleOperator":"GE","ruleValue":"1000"}]', 1, 'CUSTOM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-06 22:23:35'); INSERT INTO public.dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (7, 'alert.rule.jobRunException', '[{"ruleKey":"isException","ruleOperator":"EQ","ruleValue":"true"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
INSERT INTO public.dinky_alert_template VALUES (1, 'Default', ' INSERT INTO public.dinky_alert_template VALUES (1, 'Default', '
- **Job Name :** <font color=''gray''>${task.name}</font> - **Job Name :** <font color=''gray''>${jobName}</font>
- **Job Status :** <font color=''red''>${jobInstance.status}</font> - **Job Status :** <font color=''red''>${jobStatus}</font>
- **Alert Time :** ${time} - **Alert Time :** ${alertTime}
- **Start Time :** ${startTime} - **Start Time :** ${jobStartTime}
- **End Time :** ${endTime} - **End Time :** ${jobEndTime}
- **<font color=''red''>${(exceptions.rootException)?substring(0,20)}</font>** - **<font color=''red''>${errorMsg}</font>**
[Go toTask Web](http://${taskUrl}) [Go toTask Web](http://${taskUrl})
', 1, null, null); ', 1, null, null);
......
...@@ -213,12 +213,12 @@ INSERT INTO `dinky_sys_menu` VALUES (146, 10, ' 拷贝', '/registration/datasour ...@@ -213,12 +213,12 @@ INSERT INTO `dinky_sys_menu` VALUES (146, 10, ' 拷贝', '/registration/datasour
-- ---------------------------- -- ----------------------------
-- Records of dinky_alert_rule -- Records of dinky_alert_rule
-- ---------------------------- -- ----------------------------
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (3, 'alert.rule.jobFail', '[{"ruleKey":"jobInstance.status","ruleOperator":"EQ","ruleValue":"\'FAILED\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-04 23:03:02');
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (4, 'alert.rule.getJobInfoFail', '[{"ruleKey":"jobInstance.status","ruleOperator":"EQ","ruleValue":"\'UNKNOWN\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-05 18:03:43'); INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (3, 'alert.rule.jobFail', '[{"ruleKey":"jobStatus","ruleOperator":"EQ","ruleValue":"\'FAILED\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (5, 'alert.rule.jobRestart', '[{"ruleKey":"jobInstance.status","ruleOperator":"EQ","ruleValue":"\'RESTARTING\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-06 21:35:12'); INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (4, 'alert.rule.getJobInfoFail', '[{"ruleKey":"jobStatus","ruleOperator":"EQ","ruleValue":"\'UNKNOWN\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (6, 'alert.rule.checkpointFail', '[{"ruleKey":"checkpointRule.checkFailed(#key,#checkPoints)","ruleOperator":"EQ","ruleValue":"true"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-06 21:49:03'); INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (5, 'alert.rule.jobRestart', '[{"ruleKey":"jobStatus","ruleOperator":"EQ","ruleValue":"\'RESTARTING\'","rulePriority":"1"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (7, 'alert.rule.jobRunException', '[{"ruleKey":"exceptionRule.isException(#key,#exceptions)","ruleOperator":"EQ","ruleValue":"true"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-06 21:50:12'); INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (6, 'alert.rule.checkpointFail', '[{"ruleKey":"isCheckpointFailed","ruleOperator":"EQ","ruleValue":"true"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time) VALUES (8, 'alert.rule.checkpointTimeout', '[{"ruleKey":"checkpointRule.checkpointTime(#key,#checkPoints)","ruleOperator":"GE","ruleValue":"1000"}]', 1, 'CUSTOM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-09-06 22:23:35'); INSERT INTO dinky_alert_rules (id, name, rule, template_id, rule_type, trigger_conditions, description, enabled, create_time, update_time, creator, updater) VALUES (7, 'alert.rule.jobRunException', '[{"ruleKey":"isException","ruleOperator":"EQ","ruleValue":"true"}]', 1, 'SYSTEM', ' or ', '', 1, '1970-01-01 00:00:00', '2023-11-22 17:03:44', null, null);
INSERT INTO dinky_alert_template VALUES (1, 'Default', ' INSERT INTO dinky_alert_template VALUES (1, 'Default', '
- **Job Name :** <font color=''gray''>${task.name}</font> - **Job Name :** <font color=''gray''>${task.name}</font>
......
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