Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[type:feat]Alert module adapts to namespace transformation #5692

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion db/init/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,7 @@ CREATE TABLE IF NOT EXISTS `alert_receiver`
`match_all` tinyint(4) NOT NULL COMMENT 'match all or not',
`labels` varchar(255) COMMENT 'labels',
`levels` varchar(255) COMMENT 'levels',
`namespace_id` varchar(50) COMMENT 'namespace id',
`date_created` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT 'create time',
`date_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT 'update time',
PRIMARY KEY (`id`) USING BTREE
Expand Down Expand Up @@ -2429,4 +2430,4 @@ CREATE TABLE IF NOT EXISTS `scale_history`
`date_created` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT 'create time',
`date_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT 'update time',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
3 changes: 2 additions & 1 deletion db/init/ob/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,7 @@ CREATE TABLE IF NOT EXISTS `alert_receiver`
`match_all` tinyint(4) NOT NULL COMMENT 'match all or not',
`labels` varchar(255) COMMENT 'labels',
`levels` varchar(255) COMMENT 'levels',
`namespace_id` varchar(50) COMMENT 'namespace id',
`date_created` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT 'create time',
`date_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT 'update time',
PRIMARY KEY (`id`) USING BTREE
Expand Down Expand Up @@ -2380,4 +2381,4 @@ INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_creat
INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343264', '1346358560427216896', '1792749362445840483', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');
INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343265', '1346358560427216896', '1792749362445840484', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');
INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');
INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');
INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');
4 changes: 3 additions & 1 deletion db/init/og/create-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2531,6 +2531,7 @@ CREATE TABLE "public"."alert_receiver"
"match_all" int4 NOT NULL,
"labels" varchar(255) COLLATE "pg_catalog"."default",
"levels" varchar(255) COLLATE "pg_catalog"."default",
"namespace_id" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
"date_created" timestamp(6) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone),
"date_updated" timestamp(6) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone)
)
Expand All @@ -2540,6 +2541,7 @@ COMMENT ON COLUMN "public"."alert_receiver"."name" IS 'alarm receiver name';
COMMENT ON COLUMN "public"."alert_receiver"."enable" IS 'enable or not';
COMMENT ON COLUMN "public"."alert_receiver"."type" IS 'notice type 0-SMS 1-Email 2-webhook 3-WeChat Official Account 4-Enterprise WeChat Robot 5-DingTalk Robot 6-FeiShu Robot 7-Telegram Bot 8-SlackWebHook 9-Discord Bot 10-Enterprise WeChat';
COMMENT ON COLUMN "public"."alert_receiver"."match_all" IS 'match all or not';
COMMENT ON COLUMN "public"."alert_receiver"."namespace_id" IS 'namespace id';
COMMENT ON COLUMN "public"."alert_receiver"."date_created" IS 'create time';
COMMENT ON COLUMN "public"."alert_receiver"."date_updated" IS 'update time';

Expand Down Expand Up @@ -2771,4 +2773,4 @@ COMMENT ON COLUMN "public"."scale_history"."num" IS 'number of bootstrap';
COMMENT ON COLUMN "public"."scale_history"."action" IS 'status 1:enable 0:disable';
COMMENT ON COLUMN "public"."scale_history"."msg" IS 'message';
COMMENT ON COLUMN "public"."scale_history"."date_created" IS 'create time';
COMMENT ON COLUMN "public"."scale_history"."date_updated" IS 'update time';
COMMENT ON COLUMN "public"."scale_history"."date_updated" IS 'update time';
8 changes: 5 additions & 3 deletions db/init/oracle/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2689,6 +2689,7 @@ create table alert_receiver
match_all NUMBER(10),
labels varchar(255),
levels varchar(255),
namespace_id varchar(50) not null,
date_created timestamp(3) default SYSDATE not null,
date_updated timestamp(3) default SYSDATE not null,
PRIMARY KEY (id)
Expand Down Expand Up @@ -2717,6 +2718,9 @@ comment
on column alert_receiver.levels
is 'alarm levels';
comment
on column lert_receiver.namespace_id
is 'namespace id';
comment
on column alert_receiver.date_created
is 'create time';
comment
Expand Down Expand Up @@ -2993,6 +2997,4 @@ comment on column SCALE_HISTORY.msg
comment on column SCALE_HISTORY.date_created
is 'create time';
comment on column SCALE_HISTORY.date_updated
is 'update time';


is 'update time';
5 changes: 3 additions & 2 deletions db/init/pg/create-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,7 @@ CREATE TABLE "public"."alert_receiver"
"match_all" int4 NOT NULL,
"labels" varchar(255) COLLATE "pg_catalog"."default",
"levels" varchar(255) COLLATE "pg_catalog"."default",
"namespace_id" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
"date_created" timestamp(6) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone),
"date_updated" timestamp(6) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone)
)
Expand All @@ -2664,6 +2665,7 @@ COMMENT ON COLUMN "public"."alert_receiver"."name" IS 'alarm receiver name';
COMMENT ON COLUMN "public"."alert_receiver"."enable" IS 'enable or not';
COMMENT ON COLUMN "public"."alert_receiver"."type" IS 'notice type 0-SMS 1-Email 2-webhook 3-WeChat Official Account 4-Enterprise WeChat Robot 5-DingTalk Robot 6-FeiShu Robot 7-Telegram Bot 8-SlackWebHook 9-Discord Bot 10-Enterprise WeChat';
COMMENT ON COLUMN "public"."alert_receiver"."match_all" IS 'match all or not';
COMMENT ON COLUMN "public"."discovery_upstream"."namespace_id" IS 'the namespace id';
COMMENT ON COLUMN "public"."alert_receiver"."date_created" IS 'create time';
COMMENT ON COLUMN "public"."alert_receiver"."date_updated" IS 'update time';

Expand Down Expand Up @@ -2891,5 +2893,4 @@ COMMENT ON COLUMN "public"."scale_history"."num" IS 'number of bootstrap';
COMMENT ON COLUMN "public"."scale_history"."action" IS 'status 1:enable 0:disable';
COMMENT ON COLUMN "public"."scale_history"."msg" IS 'message';
COMMENT ON COLUMN "public"."scale_history"."date_created" IS 'create time';
COMMENT ON COLUMN "public"."scale_history"."date_updated" IS 'update time';

COMMENT ON COLUMN "public"."scale_history"."date_updated" IS 'update time';
12 changes: 7 additions & 5 deletions db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ ALTER TABLE `shenyu`.`discovery_upstream` ADD COLUMN `namespace_id` varchar(50)

ALTER TABLE `shenyu`.`proxy_selector` ADD COLUMN `namespace_id` varchar(50) NOT NULL COMMENT 'namespaceId' AFTER `props`;

ALTER TABLE `shenyu`.`alert_receiver` ADD COLUMN `namespace_id` varchar(50) NOT NULL COMMENT 'namespaceId' AFTER `levels`;

UPDATE selector
SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385'
WHERE namespace_id IS NULL;
Expand Down Expand Up @@ -216,6 +218,10 @@ UPDATE proxy_selector
SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385'
WHERE namespace_id IS NULL;

UPDATE alert_receiver
SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385'
WHERE namespace_id IS NULL;

DROP TABLE IF EXISTS `scale_policy`;
CREATE TABLE IF NOT EXISTS `scale_policy`
(
Expand Down Expand Up @@ -260,8 +266,4 @@ CREATE TABLE IF NOT EXISTS `scale_history`
`date_created` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT 'create time',
`date_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT 'update time',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;




) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
8 changes: 6 additions & 2 deletions db/upgrade/2.6.1-upgrade-2.7.0-og.sql
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ COMMENT ON COLUMN "public"."discovery_upstream"."namespace_id" IS 'namespaceId';
ALTER TABLE "public"."proxy_selector" ADD COLUMN namespace_id VARCHAR(50) NOT NULL;
COMMENT ON COLUMN "public"."proxy_selector"."namespace_id" IS 'namespaceId';

ALTER TABLE "public"."alert_receiver" ADD COLUMN namespace_id VARCHAR(50) NOT NULL;
COMMENT ON COLUMN "public"."alert_receiver"."namespace_id" IS 'namespaceId';

UPDATE "public"."selector" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

UPDATE "public"."rule" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;
Expand All @@ -230,6 +233,8 @@ UPDATE "public"."discovery_upstream" SET namespace_id = '649330b6-c2d7-4edc-be8e

UPDATE "public"."proxy_selector" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

UPDATE "public"."alert_receiver" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

-- ----------------------------
-- Table structure for scale
-- ----------------------------
Expand Down Expand Up @@ -298,5 +303,4 @@ COMMENT ON COLUMN "public"."scale_history"."num" IS 'number of bootstrap';
COMMENT ON COLUMN "public"."scale_history"."action" IS 'status 1:enable 0:disable';
COMMENT ON COLUMN "public"."scale_history"."msg" IS 'message';
COMMENT ON COLUMN "public"."scale_history"."date_created" IS 'create time';
COMMENT ON COLUMN "public"."scale_history"."date_updated" IS 'update time';

COMMENT ON COLUMN "public"."scale_history"."date_updated" IS 'update time';
8 changes: 6 additions & 2 deletions db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ COMMENT ON COLUMN discovery_upstream.namespace_id IS 'namespaceId';
ALTER TABLE proxy_selector ADD namespace_id VARCHAR2(50) NOT NULL;
COMMENT ON COLUMN proxy_selector.namespace_id IS 'namespaceId';

ALTER TABLE alert_receiver ADD namespace_id VARCHAR2(50) NOT NULL;
COMMENT ON COLUMN alert_receiver.namespace_id IS 'namespaceId';

UPDATE selector SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

UPDATE rule SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;
Expand All @@ -263,6 +266,8 @@ UPDATE discovery_upstream SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb3

UPDATE proxy_selector SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

UPDATE alert_receiver SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

-- ----------------------------
-- Table structure for scale
-- ----------------------------
Expand Down Expand Up @@ -355,5 +360,4 @@ comment on column SCALE_HISTORY.msg
comment on column SCALE_HISTORY.date_created
is 'create time';
comment on column SCALE_HISTORY.date_updated
is 'update time';

is 'update time';
7 changes: 6 additions & 1 deletion db/upgrade/2.6.1-upgrade-2.7.0-pg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ COMMENT ON COLUMN "public"."discovery_upstream"."namespace_id" IS 'namespaceId';
ALTER TABLE "public"."proxy_selector" ADD COLUMN namespace_id VARCHAR(50) NOT NULL;
COMMENT ON COLUMN "public"."proxy_selector"."namespace_id" IS 'namespaceId';

ALTER TABLE "public"."alert_receiver" ADD COLUMN namespace_id VARCHAR(50) NOT NULL;
COMMENT ON COLUMN "public"."alert_receiver"."namespace_id" IS 'namespaceId';

UPDATE "public"."selector" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

UPDATE "public"."rule" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;
Expand All @@ -229,6 +232,8 @@ UPDATE "public"."discovery_upstream" SET namespace_id = '649330b6-c2d7-4edc-be8e

UPDATE "public"."proxy_selector" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

UPDATE "public"."alert_receiver" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

-- ----------------------------
-- Table structure for scale
-- ----------------------------
Expand Down Expand Up @@ -297,4 +302,4 @@ COMMENT ON COLUMN "public"."scale_history"."num" IS 'number of bootstrap';
COMMENT ON COLUMN "public"."scale_history"."action" IS 'status 1:enable 0:disable';
COMMENT ON COLUMN "public"."scale_history"."msg" IS 'message';
COMMENT ON COLUMN "public"."scale_history"."date_created" IS 'create time';
COMMENT ON COLUMN "public"."scale_history"."date_updated" IS 'update time';
COMMENT ON COLUMN "public"."scale_history"."date_updated" IS 'update time';
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,34 @@

package org.apache.shenyu.admin.controller;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.apache.shenyu.admin.aspect.annotation.RestApi;
import org.apache.shenyu.admin.mapper.NamespaceMapper;
import org.apache.shenyu.admin.model.dto.BatchNamespaceCommonDTO;
import org.apache.shenyu.admin.model.page.CommonPager;
import org.apache.shenyu.admin.model.page.PageParameter;
import org.apache.shenyu.admin.model.query.AlertReceiverQuery;
import org.apache.shenyu.admin.model.result.ShenyuAdminResult;
import org.apache.shenyu.admin.service.AlertReceiverService;
import org.apache.shenyu.admin.utils.ShenyuResultMessage;
import org.apache.shenyu.admin.validation.annotation.Existed;
import org.apache.shenyu.alert.model.AlertReceiverDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import org.springframework.web.bind.annotation.PathVariable;

/**
* Alert Receiver Controller.
*/
@RestApi("/alert/receiver")
public class AlertReceiverController {

@Autowired
private AlertReceiverService alertReceiverService;

Expand Down Expand Up @@ -76,37 +75,46 @@ public ShenyuAdminResult editReceiver(@Valid @RequestBody final AlertReceiverDTO
/**
* delete alert receiver.
*
* @param ids primary key.
* @param batchNamespaceCommonDTO batchNamespaceCommonDTO.
* @return result
*/
@DeleteMapping("/batch")
public ShenyuAdminResult deleteReceiver(@RequestBody @NotEmpty final List<@NotBlank String> ids) {
alertReceiverService.deleteReceiver(ids);
public ShenyuAdminResult deleteReceiver(@Valid @RequestBody final BatchNamespaceCommonDTO batchNamespaceCommonDTO) {
alertReceiverService.deleteByNamespaceId(batchNamespaceCommonDTO.getIds(), batchNamespaceCommonDTO.getNamespaceId());
return ShenyuAdminResult.success(ShenyuResultMessage.DELETE_SUCCESS);
}

/**
* delete alert receiver.
*
* @param id alertReceiver ID
* @param namespaceId namespaceId.
* @return result
*/
@GetMapping("/{id}")
public ShenyuAdminResult getReceiverDetail(@PathVariable("id") final String id) {
AlertReceiverDTO receiverDTO = alertReceiverService.detail(id);
@GetMapping("/{id}/{namespaceId}")
public ShenyuAdminResult getReceiverDetail(@PathVariable("id") final String id,
@PathVariable("namespaceId") @Valid
@Existed(provider = NamespaceMapper.class,
message = "namespaceId is not existed")
final String namespaceId) {
AlertReceiverDTO receiverDTO = alertReceiverService.detail(id, namespaceId);
return ShenyuAdminResult.success(receiverDTO);
}

/**
* query receiver.
* @param currentPage current page
* @param pageSize page size
* @param namespaceId namespaceId.
* @return receiver
*/
@GetMapping
public ShenyuAdminResult getReceivers(@RequestParam @NotNull final Integer currentPage,
@RequestParam @NotNull final Integer pageSize) {
CommonPager<AlertReceiverDTO> commonPager = alertReceiverService.listByPage(new AlertReceiverQuery(new PageParameter(currentPage, pageSize)));
@RequestParam @NotNull final Integer pageSize,
@Valid @Existed(message = "namespaceId is not existed",
provider = NamespaceMapper.class) final String namespaceId
) {
CommonPager<AlertReceiverDTO> commonPager = alertReceiverService.listByPage(new AlertReceiverQuery(new PageParameter(currentPage, pageSize), namespaceId));
return ShenyuAdminResult.success(commonPager);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ public interface AlertReceiverMapper extends ExistProvider {
* select by primary key.
*
* @param id primary key
* @param namespaceId namespaceId
* @return object by primary key
*/
AlertReceiverDO selectByPrimaryKey(String id);
AlertReceiverDO selectByPrimaryKey(String id, String namespaceId);

/**
* update record.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ public class AlertReceiverDO {
* match alert labels.
*/
private Map<String, String> labels;


/**
* namespaceId.
*/
private String namespaceId;

/**
* create time.
*/
Expand Down Expand Up @@ -562,7 +567,23 @@ public List<Byte> getLevels() {
public void setLevels(final List<Byte> levels) {
this.levels = levels;
}


/**
* get namespaceId.
* @return namespaceId
*/
public String getNamespaceId() {
return namespaceId;
}

/**
* set namespaceId.
* @param namespaceId namespaceId
*/
public void setNamespaceId(final String namespaceId) {
this.namespaceId = namespaceId;
}

/**
* get dateCreated.
*
Expand Down
Loading
Loading