Skip to content

Commit

Permalink
Refactor devops alerthistory (#2345)
Browse files Browse the repository at this point in the history
* Spotless Apply

* refactor_devops_alerthistory

---------

Co-authored-by: zhu-mingye <[email protected]>
  • Loading branch information
Zzm0809 and zhu-mingye authored Sep 27, 2023
1 parent 218cb25 commit 21b2c22
Show file tree
Hide file tree
Showing 25 changed files with 460 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.dinky.data.enums.BusinessType;
import org.dinky.data.enums.Status;
import org.dinky.data.model.AlertGroup;
import org.dinky.data.model.AlertHistory;
import org.dinky.data.result.ProTableResult;
import org.dinky.data.result.Result;
import org.dinky.service.AlertGroupService;
Expand Down Expand Up @@ -164,22 +163,4 @@ public Result<Void> deleteGroupById(@RequestParam("id") Integer id) {
return Result.failed(Status.DELETE_FAILED);
}
}

/**
* list alert history
*
* @param para {@link JsonNode}
* @return {@link ProTableResult} with {@link AlertHistory}
*/
@PostMapping("/history")
@ApiImplicitParam(
name = "para",
value = "JsonNode",
dataType = "JsonNode",
required = true,
dataTypeClass = JsonNode.class)
@ApiOperation("Query AlertHistory List")
public ProTableResult<AlertHistory> listAlertHistory(@RequestBody JsonNode para) {
return alertHistoryService.selectForProTable(para);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@

import org.dinky.data.annotation.Log;
import org.dinky.data.enums.BusinessType;
import org.dinky.data.enums.Status;
import org.dinky.data.model.AlertHistory;
import org.dinky.data.result.ProTableResult;
import org.dinky.data.result.Result;
import org.dinky.service.AlertHistoryService;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
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;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
Expand All @@ -52,18 +54,45 @@ public class AlertHistoryController {

private final AlertHistoryService alertHistoryService;

/** 动态查询列表 */
@PostMapping
/**
* Query Alert History By Job Instance Id
* @param jobInstanceId
* @return List<AlertHistory>
*/
@GetMapping("/list")
@ApiOperation("Query Alert History")
@ApiImplicitParam(
name = "para",
value = "Query Alert History",
dataTypeClass = JsonNode.class,
paramType = "body",
name = "jobInstanceId",
value = "Query Alert History By Job Instance Id",
dataTypeClass = Integer.class,
required = true,
dataType = "JsonNode")
dataType = "Integer")
@Log(title = "Query Alert History", businessType = BusinessType.QUERY)
public ProTableResult<AlertHistory> listAlertHistoryRecord(@RequestBody JsonNode para) {
return alertHistoryService.selectForProTable(para);
public Result<List<AlertHistory>> listAlertHistoryRecord(@RequestParam("jobInstanceId") Integer jobInstanceId) {
return Result.succeed(alertHistoryService.queryAlertHistoryRecordByJobInstanceId(jobInstanceId));
}

/**
* delete AlertInstance by id
*
* @param id {@link Integer}
* @return {@link Result} of {@link Void}
*/
@DeleteMapping("/delete")
@Log(title = "Delete Alert History By Id", businessType = BusinessType.DELETE)
@ApiOperation("Delete Alert History By Id")
@ApiImplicitParam(
name = "id",
value = "Alert History Id",
dataType = "Integer",
paramType = "query",
required = true,
dataTypeClass = Integer.class)
public Result<Void> deleteAlertInstanceById(@RequestParam("id") Integer id) {
if (alertHistoryService.removeById(id)) {
return Result.succeed(Status.DELETE_SUCCESS);
} else {
return Result.failed(Status.DELETE_FAILED);
}
}
}
12 changes: 12 additions & 0 deletions dinky-admin/src/main/java/org/dinky/data/model/AlertHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
Expand Down Expand Up @@ -56,6 +60,10 @@ public class AlertHistory implements Serializable {
@ApiModelProperty(value = "Alert Group ID", example = "1", required = true, dataType = "Integer")
private Integer alertGroupId;

@ApiModelProperty(value = "Alert Group", dataType = "AlertGroup")
@TableField(exist = false)
private AlertGroup alertGroup;

@ApiModelProperty(value = "Alert Instance ID", example = "1", required = true, dataType = "Integer")
private Integer jobInstanceId;

Expand All @@ -77,6 +85,8 @@ public class AlertHistory implements Serializable {
example = "2022-02-24 20:12:00",
required = false,
dataType = "LocalDateTime")
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime createTime;

@TableField(fill = FieldFill.INSERT_UPDATE)
Expand All @@ -85,5 +95,7 @@ public class AlertHistory implements Serializable {
example = "2022-02-24 20:12:00",
required = false,
dataType = "LocalDateTime")
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime updateTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.dinky.data.model.AlertHistory;
import org.dinky.mybatis.service.ISuperService;

import java.util.List;

/** AlertHistoryService */
public interface AlertHistoryService extends ISuperService<AlertHistory> {

Expand All @@ -32,4 +34,6 @@ public interface AlertHistoryService extends ISuperService<AlertHistory> {
* @return {@link Boolean}
*/
Boolean deleteByAlertGroupId(Integer alertGroupId);

List<AlertHistory> queryAlertHistoryRecordByJobInstanceId(Integer jobInstanceId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import org.dinky.data.model.AlertHistory;
import org.dinky.mapper.AlertHistoryMapper;
import org.dinky.mybatis.service.impl.SuperServiceImpl;
import org.dinky.service.AlertGroupService;
import org.dinky.service.AlertHistoryService;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -38,6 +40,9 @@
@RequiredArgsConstructor
public class AlertHistoryServiceImpl extends SuperServiceImpl<AlertHistoryMapper, AlertHistory>
implements AlertHistoryService {

private final AlertGroupService alertGroupService;

/**
* delete alert history by alert group id
*
Expand All @@ -51,4 +56,19 @@ public Boolean deleteByAlertGroupId(Integer alertGroupId) {
.selectList(new LambdaQueryWrapper<AlertHistory>().eq(AlertHistory::getAlertGroupId, alertGroupId));
return baseMapper.deleteBatchIds(alertHistoryList) > 0;
}

/**
* @param jobInstanceId
* @return
*/
@Override
public List<AlertHistory> queryAlertHistoryRecordByJobInstanceId(Integer jobInstanceId) {

return baseMapper
.selectList(new LambdaQueryWrapper<AlertHistory>().eq(AlertHistory::getJobInstanceId, jobInstanceId))
.stream()
.peek(alertHistory ->
alertHistory.setAlertGroup(alertGroupService.getById(alertHistory.getAlertGroupId())))
.collect(Collectors.toList());
}
}
47 changes: 22 additions & 25 deletions dinky-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"scripts": {
"analyze": "cross-env ANALYZE=1 max build",
"build": "max build ",
"deploy": "npm run build && npm run gh-pages",
"dev": " npm run start:dev ",
"postinstall": "max setup",
"lint": "npm run lint:js && npm run lint:prettier && npm run tsc",
Expand All @@ -15,7 +14,6 @@
"lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src ",
"lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
"lint:prettier": "prettier -c --write \"**/**.{js,jsx,tsx,ts,less,md,json}\" --end-of-line auto",
"openapi": "max openapi",
"prettier": "prettier -c --write \"**/**.{js,jsx,tsx,ts,less,md,json}\"",
"preview": "npm run build && max preview --port 8000",
"serve": "umi-serve",
Expand All @@ -38,58 +36,57 @@
],
"dependencies": {
"@ant-design/charts": "^1.4.2",
"@ant-design/icons": "^5.0.1",
"@ant-design/pro-components": "^2.6.3",
"@ant-design/pro-layout": "^7.13.3",
"@ant-design/pro-table": "^3.6.9",
"@ant-design/icons": "^5.2.6",
"@ant-design/pro-components": "^2.6.27",
"@ant-design/pro-layout": "^7.17.6",
"@ant-design/pro-table": "^3.12.11",
"@ant-design/use-emotion-css": "^1.0.4",
"@antv/x6": "^2.15.1",
"@antv/x6-plugin-selection": "^2.2.1",
"@antv/x6-react-shape": "^2.2.2",
"@monaco-editor/react": "^4.5.1",
"@monaco-editor/react": "^4.5.2",
"@umijs/route-utils": "^4.0.1",
"antd": "^5.6.1",
"antd": "^5.9.3",
"classnames": "^2.3.2",
"dayjs": "^1.11.9",
"dayjs": "^1.11.10",
"js-cookie": "^3.0.5",
"lodash": "^4.17.21",
"million": "^2.5.1-beta.3",
"million": "^2.6.1",
"moment": "^2.29.4",
"monaco-editor": "^0.41.0",
"monaco-editor": "^0.43.0",
"omit.js": "^2.0.2",
"rc-menu": "^9.8.4",
"rc-util": "^5.33.0",
"re-resizable": "6.9.11",
"rc-menu": "^9.12.0",
"rc-util": "^5.37.0",
"re-resizable": "^6.9.11",
"react": "^18.2.0",
"react-countup": "^6.4.2",
"react-dom": "^18.0.0",
"react-helmet-async": "^1.3.0",
"react-spring": "^9.7.1",
"react-markdown": "^8.0.7",
"react-spring": "^9.7.3",
"react-use-cookie": "^1.4.0",
"redux-persist": "^6.0.0",
"remark-gfm": "^4.0.0",
"screenfull": "^6.0.2",
"styled-components": "^6.0.0-rc.3",
"styled-components": "^6.0.8",
"use-sse": "^2.0.1"
},
"devDependencies": {
"@ant-design/pro-cli": "^3.0.1",
"@testing-library/react": "^14.0.0",
"@types/classnames": "^2.3.1",
"@types/express": "^4.17.17",
"@types/express": "^4.17.18",
"@types/history": "^5.0.0",
"@types/lodash": "^4.14.186",
"@types/react": "^18.0.28",
"@types/lodash": "^4.14.199",
"@types/react": "^18.2.22",
"@types/react-dom": "^18.0.11",
"@types/react-helmet": "^6.1.5",
"@umijs/lint": "^4.0.53",
"@umijs/max": "^4.0.53",
"@umijs/lint": "^4.0.81",
"@umijs/max": "^4.0.81",
"cross-env": "^7.0.3",
"eslint": "^8.35.0",
"eslint": "^8.50.0",
"express": "^4.18.2",
"gh-pages": "^5.0.0",
"husky": "^8",
"lint-staged": "^13",
"mockjs": "^1.1.0",
"prettier": "^2",
"react-dev-inspector": "^2.0.0",
"react-inspector": "^6.0.2",
Expand Down
7 changes: 7 additions & 0 deletions dinky-web/src/global.less
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,10 @@ h5 {
display: flex !important;
align-items: baseline !important;
}

.ant-pro-checkcard {
overflow: hidden;
.ant-pro-checkcard-body {
width: 100vw;
}
}
10 changes: 9 additions & 1 deletion dinky-web/src/locales/en-US/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,15 @@ export default {
'devops.jobinfo.ck.taskid': 'Task ID',
'devops.jobinfo.ck.trigger_timestamp': 'Trigger Time',
'devops.jobinfo.config.ClusterInstanceName': 'Flink Instance',
'devops.jobinfo.config.JobAlert': 'Alert',
'devops.jobinfo.config.JobAlert': 'Alert History',
'devops.jobinfo.config.JobAlert.history.group': 'Alert Group',
'devops.jobinfo.config.JobAlert.history.title': 'Alert Title',
'devops.jobinfo.config.JobAlert.history.content': 'Alert Content',
'devops.jobinfo.config.JobAlert.history.status': 'Alert Send Status',
'devops.jobinfo.config.JobAlert.history.log': 'Alert Log',
'devops.jobinfo.config.JobAlert.history.time': 'Alert Time',
'devops.jobinfo.config.JobAlert.history.delete':
'Are you sure to delete the alert history record?',
'devops.jobinfo.config.JobBaseInfo': 'Job Base Info',
'devops.jobinfo.config.JobCheckpoints': 'Checkpoints Info',
'devops.jobinfo.config.JobId': 'Flink Job ID',
Expand Down
7 changes: 7 additions & 0 deletions dinky-web/src/locales/zh-CN/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ export default {
'devops.jobinfo.ck.trigger_timestamp': '触发时间',
'devops.jobinfo.config.ClusterInstanceName': 'Flink实例',
'devops.jobinfo.config.JobAlert': '告警记录',
'devops.jobinfo.config.JobAlert.history.group': '告警组',
'devops.jobinfo.config.JobAlert.history.title': '告警标题',
'devops.jobinfo.config.JobAlert.history.content': '告警内容',
'devops.jobinfo.config.JobAlert.history.status': '告警发送状态',
'devops.jobinfo.config.JobAlert.history.log': '告警日志',
'devops.jobinfo.config.JobAlert.history.time': '告警时间',
'devops.jobinfo.config.JobAlert.history.delete': '你确定删除该告警记录吗?',
'devops.jobinfo.config.JobBaseInfo': '作业基本信息',
'devops.jobinfo.config.JobCheckpoints': '作业快照',
'devops.jobinfo.config.JobId': 'Flink Job ID',
Expand Down
Loading

0 comments on commit 21b2c22

Please sign in to comment.