Skip to content

Commit

Permalink
modify alert rule layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzm0809 committed Sep 14, 2023
1 parent a377b70 commit bbf9598
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.dinky.data.model.JobInstance;
import org.dinky.data.model.SystemConfiguration;
import org.dinky.data.model.Task;
import org.dinky.data.options.AlertRuleOptions;
import org.dinky.job.FlinkJobTaskPool;
import org.dinky.service.impl.AlertGroupServiceImpl;
import org.dinky.service.impl.AlertHistoryServiceImpl;
Expand Down Expand Up @@ -130,7 +131,7 @@ public class JobAlerts extends BaseSchedule {
@PostConstruct
public void init() {
refeshRulesData();
addSchedule("JobAlert", this::check, new PeriodicTrigger(1000 * 30));
addSchedule(AlertRuleOptions.JOB_ALERT_SCHEDULE, this::check, new PeriodicTrigger(1000 * 30));
}

/**
Expand All @@ -142,20 +143,20 @@ protected void check() {
for (Map.Entry<String, JobInfoDetail> job : taskPool.entrySet()) {
JobInfoDetail jobInfoDetail = job.getValue();
String key = job.getKey();
ruleFacts.put("time", TimeUtil.nowStr());
ruleFacts.put("jobDetail", jobInfoDetail);
ruleFacts.put("job", jobInfoDetail.getJobHistory().getJob());
ruleFacts.put("key", key);
ruleFacts.put("jobInstance", jobInfoDetail.getInstance());
ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_TIME, TimeUtil.nowStr());
ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_JOB_DETAIL, jobInfoDetail);
ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_JOB_NAME, jobInfoDetail.getJobHistory().getJob());
ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_KEY, key);
ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_JOB_INSTANCE, jobInfoDetail.getInstance());
ruleFacts.put(
"startTime",
AlertRuleOptions.JOB_ALERT_RULE_START_TIME,
TimeUtil.convertTimeToString(jobInfoDetail.getHistory().getStartTime()));
ruleFacts.put(
"endTime",
AlertRuleOptions.JOB_ALERT_RULE_END_TIME,
TimeUtil.convertTimeToString(jobInfoDetail.getHistory().getEndTime()));
ruleFacts.put("checkPoints", jobInfoDetail.getJobHistory().getCheckpoints());
ruleFacts.put("cluster", jobInfoDetail.getCluster());
ruleFacts.put("exceptions", jobInfoDetail.getJobHistory().getExceptions());
ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_CHECK_POINTS, jobInfoDetail.getJobHistory().getCheckpoints());
ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_CLUSTER, jobInfoDetail.getCluster());
ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_EXCEPTIONS, jobInfoDetail.getJobHistory().getExceptions());
rulesEngine.fire(rules, ruleFacts);
}
}
Expand All @@ -164,8 +165,8 @@ protected void check() {
* Refreshes the alert rules and related data.
*/
public void refeshRulesData() {
ruleFacts.put("exceptionRule", new ExceptionRule());
ruleFacts.put("checkpointRule", new CheckpointsRule());
ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_REFRESH_RULES_DATA, new ExceptionRule());
ruleFacts.put(AlertRuleOptions.JOB_ALERT_RULE_CHECKPOINT_RULES, new CheckpointsRule());

List<AlertRuleDTO> ruleDTOS = alertRuleService.getBaseMapper().selectWithTemplate();
freeMarkerHolder = new FreeMarkerHolder();
Expand Down Expand Up @@ -212,7 +213,7 @@ private Rule buildRule(AlertRuleDTO alertRuleDTO) {
* @param alertRuleDTO Alert Rule Info.
*/
private void executeAlertAction(Facts facts, AlertRuleDTO alertRuleDTO) {
JobInfoDetail jobInfoDetail = facts.get("jobDetail");
JobInfoDetail jobInfoDetail = facts.get(AlertRuleOptions.JOB_ALERT_RULE_JOB_DETAIL);
JobInstance jobInstance = jobInfoDetail.getInstance();
Task task = taskService.getById(jobInfoDetail.getInstance().getTaskId());

Expand All @@ -221,9 +222,9 @@ private void executeAlertAction(Facts facts, AlertRuleDTO alertRuleDTO) {
SystemConfiguration.getInstances().getDinkyAddr(),
task.getId());
Map<String, Object> dataModel = new HashMap<>(facts.asMap());
dataModel.put("task", task);
dataModel.put("taskUrl", taskUrl);
dataModel.put("rule", alertRuleDTO);
dataModel.put(AlertRuleOptions.JOB_ALERT_RULE_TASK, task);
dataModel.put(AlertRuleOptions.JOB_ALERT_RULE_TASK_URL, taskUrl);
dataModel.put(AlertRuleOptions.JOB_ALERT_RULE, alertRuleDTO);

String alertContent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -61,16 +62,20 @@ public ProTableResult<AlertRule> list(@RequestBody JsonNode para) {
}

@PutMapping
public Result<Boolean> put(@RequestBody AlertRule alertRule) {
public Result<Boolean> saveOrUpdateAlertRule(@RequestBody AlertRule alertRule) {
boolean saved = alertRuleService.saveOrUpdate(alertRule);
if (saved) {
jobAlerts.refeshRulesData();
return Result.succeed(Status.MODIFY_SUCCESS);
}
return Result.succeed(saved);
return Result.failed(Status.MODIFY_FAILED);
}

@DeleteMapping
public Result<Boolean> delete(int id) {
return Result.succeed(alertRuleService.removeById(id));
public Result<Boolean> deleteAlertRuleById(@RequestParam Integer id) {
if (alertRuleService.removeById(id)){
return Result.succeed(Status.DELETE_SUCCESS);
}
return Result.failed(Status.DELETE_FAILED);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.dinky.data.options;


public class AlertRuleOptions {
public static final String JOB_ALERT_SCHEDULE = "JobAlert";
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";
public static final String JOB_ALERT_RULE_KEY = "key";
public static final String JOB_ALERT_RULE_JOB_INSTANCE = "jobInstance";
public static final String JOB_ALERT_RULE_START_TIME = "startTime";
public static final String JOB_ALERT_RULE_END_TIME = "endTime";
public static final String JOB_ALERT_RULE_CHECK_POINTS = "checkPoints";
public static final String JOB_ALERT_RULE_CLUSTER = "cluster";
public static final String JOB_ALERT_RULE_EXCEPTIONS = "exceptions";
public static final String JOB_ALERT_RULE_REFRESH_RULES_DATA = "refreshRulesData";
public static final String JOB_ALERT_RULE_CHECKPOINT_RULES = "checkpointRule";
public static final String JOB_ALERT_RULE_TASK = "task";
public static final String JOB_ALERT_RULE_TASK_URL = "taskUrl";
public static final String JOB_ALERT_RULE = "rule";
}
2 changes: 1 addition & 1 deletion dinky-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "Apache License 2.0",
"scripts": {
"analyze": "cross-env ANALYZE=1 max build",
"build": "concurrently max build && npm run build-to-admin --prefix ../dinky-web-flink",
"build": "max build && npm install --prefix ../dinky-web-flink && npm run build-to-admin --prefix ../dinky-web-flink",
"deploy": "npm run build && npm run gh-pages",
"dev": "npm run build-to-admin --prefix ../dinky-web-flink && npm run start:dev ",
"postinstall": "max setup",
Expand Down
7 changes: 4 additions & 3 deletions dinky-web/src/locales/en-US/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,16 +958,17 @@ export default {
'sys.alert.rule.rule': 'Rule',
'sys.alert.rule.ruleType': 'Rule Type',
'sys.alert.rule.template': 'Alert Template',
'sys.alert.rule.triger': 'Trigger Configuration',
'sys.alert.rule.trigerConditions': 'Trigger Conditions',
'sys.alert.rule.trigger': 'Trigger Configuration',
'sys.alert.rule.triggerConditions': 'Trigger Conditions',
'sys.alert.rule.anyRule': 'Any Rule',
'sys.alert.rule.allRule': 'All Rules',
'sys.alert.rule.trigerRule': 'Trigger Rule',
'sys.alert.rule.triggerRule': 'Trigger Rule',
'sys.alert.rule.addRule': 'Add Rule',
'sys.alert.rule.jobStatus': 'Job Status',
'sys.alert.rule.checkpointTime': 'Checkpoint Time',
'sys.alert.rule.checkpointFailed': 'Checkpoint Failed',
'sys.alert.rule.jobException': 'Job Exception',
'sys.alert.rule.delete': 'Are you sure you want to delete this alert rule?',

// metrics
// server
Expand Down
7 changes: 4 additions & 3 deletions dinky-web/src/locales/zh-CN/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,16 +932,17 @@ export default {
'sys.alert.rule.ruleType': '规则类型',
'sys.alert.rule.rule': '规则',
'sys.alert.rule.template': '告警模板',
'sys.alert.rule.triger': '触发配置',
'sys.alert.rule.trigerConditions': '触发条件',
'sys.alert.rule.trigger': '触发配置',
'sys.alert.rule.triggerConditions': '触发条件',
'sys.alert.rule.anyRule': '任意规则',
'sys.alert.rule.allRule': '所有规则',
'sys.alert.rule.trigerRule': '触发规则',
'sys.alert.rule.triggerRule': '触发规则',
'sys.alert.rule.addRule': '添加规则',
'sys.alert.rule.jobStatus': '作业状态',
'sys.alert.rule.checkpointTime': 'CheckPoint时间',
'sys.alert.rule.checkpointFailed': 'Checkpoint失败',
'sys.alert.rule.jobException': '作业产生异常',
'sys.alert.rule.delete': '你确定要删除该告警策略吗?',

// metrics
// server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@
*
*/

import { RuleType } from '@/pages/SettingCenter/AlertRule/constants';
import {
AlertRules,
RuleOperator,
RuleType,
TriggerType
} from '@/pages/SettingCenter/AlertRule/constants';
import { getData } from '@/services/api';
import { SWITCH_OPTIONS } from '@/services/constants';
import { API_CONSTANTS } from '@/services/endpoints';
import { Alert } from '@/types/RegCenter/data';
import { AlertRule } from '@/types/SettingCenter/data';
Expand Down Expand Up @@ -85,42 +91,45 @@ const RuleEditForm = (props: AlertRuleFormProps) => {
}}
initialValues={values}
>
<ProFormText name='id' hidden={true} />
<ProFormText
disabled={isSystem}
rules={[{ required: true }]}
name='name'
width='md'
label={l('sys.alert.rule.name')}
placeholder={l('sys.alert.rule.name')}
/>

<ProFormSelect
label={l('sys.alert.rule.template')}
width='md'
name='templateId'
request={async () => getAlertTemplate()}
placeholder={l('sys.alert.rule.template')}
rules={[{ required: true, message: l('sys.alert.rule.template') }]}
/>

<ProFormTextArea width='md' name='description' label={l('global.table.note')} />

<Divider orientation={'left'}>{l('sys.alert.rule.triger')}</Divider>
<ProFormGroup>
<ProFormText name='id' hidden={true} />
<ProFormText
disabled={isSystem}
rules={[{ required: true }]}
name='name'
width='md'
label={l('sys.alert.rule.name')}
placeholder={l('sys.alert.rule.name')}
/>

<ProFormSelect
label={l('sys.alert.rule.template')}
width='md'
name='templateId'
request={async () => getAlertTemplate()}
placeholder={l('sys.alert.rule.template')}
rules={[{ required: true, message: l('sys.alert.rule.template') }]}
/>
</ProFormGroup>

<ProFormGroup>
<ProFormTextArea width='md' name='description' label={l('global.table.note')} />
<ProFormSwitch name='enabled' {...SWITCH_OPTIONS()} label={l('global.table.isEnable')} />
</ProFormGroup>

<Divider orientation={'left'}>{l('sys.alert.rule.trigger')}</Divider>

<ProFormRadio.Group
disabled={isSystem}
name='triggerConditions'
label={l('sys.alert.rule.trigerConditions')}
options={[
{ label: l('sys.alert.rule.anyRule'), value: ' or ' },
{ label: l('sys.alert.rule.allRule'), value: ' and ' }
]}
label={l('sys.alert.rule.triggerConditions')}
rules={[{ required: true }]}
options={TriggerType}
/>

<ProFormList
name='rule'
label={l('sys.alert.rule.trigerRule')}
label={l('sys.alert.rule.triggerRule')}
creatorButtonProps={
isSystem
? false
Expand Down Expand Up @@ -150,34 +159,13 @@ const RuleEditForm = (props: AlertRuleFormProps) => {
name='ruleKey'
width={'sm'}
mode={'single'}
options={[
{ 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)'
}
]}
options={AlertRules}
/>
<ProFormSelect
disabled={isSystem}
name='ruleOperator'
mode={'single'}
options={[
{ label: '>', value: 'GT' },
{ label: '<', value: 'LT' },
{ label: '=', value: 'EQ' },
{ label: '>=', value: 'GE' },
{ label: '<=', value: 'LE' },
{ label: '!=', value: 'NE' }
]}
options={RuleOperator}
/>

<ProFormText
Expand All @@ -188,8 +176,6 @@ const RuleEditForm = (props: AlertRuleFormProps) => {
</Space>
</ProFormGroup>
</ProFormList>

<ProFormSwitch name='enabled' label={l('button.enable')} />
</DrawerForm>
);
};
Expand Down
Loading

0 comments on commit bbf9598

Please sign in to comment.