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

[BUG] <title> After deleting the monitor, adding a monitor with the same name will report an error #1146

Closed
1 task done
wtjperi2003 opened this issue Aug 3, 2023 · 21 comments · Fixed by #1159
Closed
1 task done
Labels
bug Something isn't working

Comments

@wtjperi2003
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

比如新建了一个监控,监控名称是:操作日志_192.168.21.228 。 然后再新建名称一样就报错.
Snipaste_2023-08-03_09-35-21

Expected Behavior

不要报错

Steps To Reproduce

No response

Environment

HertzBeat version(s):v1.3.2

Debug logs

No response

Anything else?

No response

@wtjperi2003 wtjperi2003 added the bug Something isn't working label Aug 3, 2023
@hertzbeat hertzbeat changed the title [BUG] <title>删除监控后,在添加一个同名的会报错 [BUG] <title> After deleting the monitor, adding a monitor with the same name will report an error Aug 3, 2023
@tomsun28
Copy link
Contributor

tomsun28 commented Aug 3, 2023

谢谢反馈 收到

@hertzbeat
Copy link
Contributor

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Thank you for your feedback

@Ceilzcx
Copy link
Contributor

Ceilzcx commented Aug 3, 2023

image
你好监控名字重复会提示如上图,看报错是和标签表的操作有关(hzb_tag),能描述的更详细点吗?最好提供报错的error log日志

@hertzbeat
Copy link
Contributor

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


![image](https://github.com/dromara/hertzbeat/assets/48920254/28d59dd2-e7b0-4e52-b28e-dee4f8109e1
Hello, the monitoring name duplication will prompt as shown in the figure above. It can be seen that the error report is related to the operation of the tag table (hzb_tag). Can you describe it in more detail? It is best to provide the error log log of the error

@Ceilzcx
Copy link
Contributor

Ceilzcx commented Aug 3, 2023

麻烦顺带贴一下hzb_tag的表结构

@hertzbeat
Copy link
Contributor

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Please post the table structure of hzb_tag by the way

@wtjperi2003
Copy link
Author

麻烦顺带贴一下hzb_tag的表结构

标签我没用,数据是空的。

CREATE TABLE `hzb_tag`  (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'TAG ID',
  `name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'TAG标签名称',
  `value` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'TAG标签值(可为空)',
  `type` tinyint NOT NULL DEFAULT 0 COMMENT '标记类型 0:监控自动生成(monitorId,monitorName) 1: 用户生成 2: 系统预制',
  `color` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '#ffffff' COMMENT '标签颜色',
  `creator` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '创建者',
  `modifier` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最新修改者',
  `gmt_create` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
  `gmt_update` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'update time',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `unique_tag`(`name` ASC, `value` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 45 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

@hertzbeat
Copy link
Contributor

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Please post the table structure of hzb_tag by the way

The tags I have are useless and the data is empty.

CREATE TABLE `hzb_tag` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'TAG ID',
  `name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'TAG tag name',
  `value` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'TAG tag value (can be empty)',
  `type` tinyint NOT NULL DEFAULT 0 COMMENT 'Mark type 0: monitor auto-generated (monitorId,monitorName) 1: user-generated 2: system prefabricated',
  `color` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '#ffffff' COMMENT 'label color',
  `creator` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'creator',
  `modifier` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'latest modifier',
  `gmt_create` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
  `gmt_update` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'update time',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `unique_tag`(`name` ASC, `value` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 45 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

@wtjperi2003
Copy link
Author

奇怪,hzb_tag这个表里面有数据,这表不是对应管理后台里的标签管理吗。那边列表是空,为什么表里有数据?

@hertzbeat
Copy link
Contributor

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Strangely, there is data in the hzb_tag table. Doesn’t this table correspond to the tag management in the management background? The list over there is empty, why is there data in the table?

@Ceilzcx
Copy link
Contributor

Ceilzcx commented Aug 7, 2023

奇怪,hzb_tag这个表里面有数据,这表不是对应管理后台里的标签管理吗。那边列表是空,为什么表里有数据?

添加监控时默认会往hzb_tag表插入两行数据,name为monitorId和monitorName,看这个报错应该是插入hzb_tag表时name和value重复了,表结构存在:UNIQUE INDEX unique_tag(name ASC, value ASC) USING BTREE。
不清楚怎么走到插入hzb_tag那边的。org.dromara.hertzbeat.manager.service.MonitorService#validate会判断监控的name不能重复的,而且我也没有复现出来你这个问题(新建和修改都试过了)
image

@wtjperi2003
Copy link
Author

奇怪,hzb_tag这个表里面有数据,这表不是对应管理后台里的标签管理吗。那边列表是空,为什么表里有数据?

添加监控时默认会往hzb_tag表插入两行数据,name为monitorId和monitorName,看这个报错应该是插入hzb_tag表时name和value重复了,表结构存在:UNIQUE INDEX unique_tag(name ASC, value ASC) USING BTREE。 不清楚怎么走到插入hzb_tag那边的。org.dromara.hertzbeat.manager.service.MonitorService#validate会判断监控的name不能重复的,而且我也没有复现出来你这个问题(新建和修改都试过了) image

你这代码判断是在monitor表里是否有同名。但是异常是出在hzb_tag表。是不是删除监控时漏删了hzb_tag表里数据?另外这两张有中间表也要删把

@hertzbeat
Copy link
Contributor

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Strange, there is data in the hzb_tag table, isn't this table corresponding to the tag management in the management background. The list over there is empty, why is there data in the table?

When adding a monitor, two rows of data will be inserted into the hzb_tag table by default. The name is monitorId and monitorName. This error should be that the name and value are repeated when inserting into the hzb_tag table. The table structure exists: UNIQUE INDEX unique_tag(name ASC, value ASC) USING BTREE. I don't know how to get to the side where hzb_tag is inserted. org.dromara.hertzbeat.manager.service.MonitorService#validate will judge that the monitored name cannot be repeated, and I have not reproduced your problem (I have tried both new creation and modification) ![image](https:// user-images.githubusercontent.com/48920254/258685846-d13dd459-ab4b-40dd-9350-1dce18f1a358.png)

Your code judges whether there is the same name in the monitor table. But the exception is in the hzb_tag table. Is the data in the hzb_tag table omitted when deleting the monitoring? In addition, the two intermediate tables should also be deleted.

@Ceilzcx
Copy link
Contributor

Ceilzcx commented Aug 7, 2023

奇怪,hzb_tag这个表里面有数据,这表不是对应管理后台里的标签管理吗。那边列表是空,为什么表里有数据?

添加监控时默认会往hzb_tag表插入两行数据,name为monitorId和monitorName,看这个报错应该是插入hzb_tag表时name和value重复了,表结构存在:UNIQUE INDEX unique_tag(name ASC, value ASC) USING BTREE。 不清楚怎么走到插入hzb_tag那边的。org.dromara.hertzbeat.manager.service.MonitorService#validate会判断监控的name不能重复的,而且我也没有复现出来你这个问题(新建和修改都试过了) image

你这代码判断是在monitor表里是否有同名。但是异常是出在hzb_tag表。是不是删除监控时漏删了hzb_tag表里数据?另外这两张有中间表也要删把

代码是判断monitor表同名,问题是同名了直接抛异常了呀,不会走到下面插入hzb_tag表的操作;现在逻辑就是不支持插入同名的监控,按你这个描述走到代码位置就结束了,返回之前截图的报错,不是tag表插入失败的报错。
所以我也不知道你描述的情况是怎么走到下面插入tag表流程的,你可以先看一下数据库数据吧,可能存在你说的monitor表数据删了,tag表数据没删除的情况

@hertzbeat
Copy link
Contributor

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Strange, hzb_tag has data in the table, isn't this table corresponding to the tag management in the management background. The list over there is empty, why is there data in the table?

When adding a monitor, two rows of data will be inserted into the hzb_tag table by default. The name is monitorId and monitorName. This error should be that the name and value are repeated when inserting into the hzb_tag table. The table structure exists: UNIQUE INDEX unique_tag(name ASC , value ASC) USING BTREE. I don't know how to get to the side where hzb_tag is inserted. org.dromara.hertzbeat.manager.service.MonitorService#validate will judge that the monitored name cannot be repeated, and I have not reproduced your problem (I have tried both new creation and modification) ![image](https:// user-images.githubusercontent.com/48920254/258685846-d13dd459-ab4b-40dd-9350-1dce18f1a358.png)

Your code judges whether there is the same name in the monitor table. But the exception is in the hzb_tag table. Is the data in the hzb_tag table omitted when deleting the monitoring? In addition, the two intermediate tables should also be deleted.

The code is to judge that the monitor table has the same name. The problem is that if the name is the same, an exception will be thrown directly. It will not go to the operation of inserting the hzb_tag table below; the current logic does not support the insertion of monitors with the same name. According to your description, it will be over when you go to the code position. The error reported in the previous screenshot is returned, not the error reported by the tag table insertion failure.
So I don’t know how the situation you described led to the process of inserting the tag table below. You can look at the database data first. There may be cases where the data in the monitor table you mentioned was deleted but the data in the tag table was not deleted.

@wtjperi2003
Copy link
Author

奇怪,hzb_tag这个表里面有数据,这表不是对应管理后台里的标签管理吗。那边列表是空,为什么表里有数据?

添加监控时默认会往hzb_tag表插入两行数据,name为monitorId和monitorName,看这个报错应该是插入hzb_tag表时name和value重复了,表结构存在:UNIQUE INDEX unique_tag(name ASC, value ASC) USING BTREE。 不清楚怎么走到插入hzb_tag那边的。org.dromara.hertzbeat.manager.service.MonitorService#validate会判断监控的name不能重复的,而且我也没有复现出来你这个问题(新建和修改都试过了) image

你这代码判断是在monitor表里是否有同名。但是异常是出在hzb_tag表。是不是删除监控时漏删了hzb_tag表里数据?另外这两张有中间表也要删把

代码是判断monitor表同名,问题是同名了直接抛异常了呀,不会走到下面插入hzb_tag表的操作;现在逻辑就是不支持插入同名的监控,按你这个描述走到代码位置就结束了,返回之前截图的报错,不是tag表插入失败的报错。 所以我也不知道你描述的情况是怎么走到下面插入tag表流程的,你可以先看一下数据库数据吧,可能存在你说的monitor表数据删了,tag表数据没删除的情况

不好意思,我帖子上内容写漏了,但是我标题其实有写。我的操作是,建一个叫abc的监控。然后删除,在创建一个abc监控,就会报错。我回头录个视频把

@hertzbeat
Copy link
Contributor

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Strange, there is data in the hzb_tag table, isn't this table corresponding to the tag management in the management background. The list over there is empty, why is there data in the table?

When adding a monitor, two rows of data will be inserted into the hzb_tag table by default. The name is monitorId and monitorName. Seeing this error, it should be that the name and value are repeated when inserting into the hzb_tag table. The table structure exists: UNIQUE INDEX unique_tag(name ASC, value ASC) USING BTREE. I don't know how to get to the side where hzb_tag is inserted. org.dromara.hertzbeat.manager.service.MonitorService#validate will judge that the monitored name cannot be repeated, and I have not reproduced your problem (I have tried both new creation and modification) ![image](https:// user-images.githubusercontent.com/48920254/258685846-d13dd459-ab4b-40dd-9350-1dce18f1a358.png)

Your code judges whether there is the same name in the monitor table. But the exception is in the hzb_tag table. Is the data in the hzb_tag table omitted when deleting the monitoring? In addition, the two intermediate tables should also be deleted.

The code is to judge that the monitor table has the same name. The problem is that if the name is the same, an exception will be thrown directly. It will not go to the operation of inserting the hzb_tag table below; the current logic does not support the insertion of monitors with the same name. According to your description, it is over when you go to the code position , returns the error reported in the previous screenshot, not the error reported that the tag table insertion failed. So I don’t know how the situation you described led to the process of inserting the tag table below. You can look at the database data first. There may be cases where the data in the monitor table you mentioned was deleted but the data in the tag table was not deleted.

Sorry, I missed the content in the post, but I actually wrote it in the title. My operation is to build a monitor called abc. Then delete it, and when creating an abc monitor, an error will be reported. I'll go back and record a video

@Ceilzcx
Copy link
Contributor

Ceilzcx commented Aug 7, 2023

奇怪,hzb_tag这个表里面有数据,这表不是对应管理后台里的标签管理吗。那边列表是空,为什么表里有数据?

添加监控时默认会往hzb_tag表插入两行数据,name为monitorId和monitorName,看这个报错应该是插入hzb_tag表时name和value重复了,表结构存在:UNIQUE INDEX unique_tag(name ASC, value ASC) USING BTREE。 不清楚怎么走到插入hzb_tag那边的。org.dromara.hertzbeat.manager.service.MonitorService#validate会判断监控的name不能重复的,而且我也没有复现出来你这个问题(新建和修改都试过了) image

你这代码判断是在monitor表里是否有同名。但是异常是出在hzb_tag表。是不是删除监控时漏删了hzb_tag表里数据?另外这两张有中间表也要删把

代码是判断monitor表同名,问题是同名了直接抛异常了呀,不会走到下面插入hzb_tag表的操作;现在逻辑就是不支持插入同名的监控,按你这个描述走到代码位置就结束了,返回之前截图的报错,不是tag表插入失败的报错。 所以我也不知道你描述的情况是怎么走到下面插入tag表流程的,你可以先看一下数据库数据吧,可能存在你说的monitor表数据删了,tag表数据没删除的情况

不好意思,我帖子上内容写漏了,但是我标题其实有写。我的操作是,建一个叫abc的监控。然后删除,在创建一个abc监控,就会报错。我回头录个视频把

好的,了解了,不用录视频了,那是有问题,我们这边修复一下

@hertzbeat
Copy link
Contributor

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Strange, there is data in the table hzb_tag, isn’t this table corresponding to the tag management in the management background. The list over there is empty, why is there data in the table?

When adding a monitor, two rows of data will be inserted into the hzb_tag table by default. The name is monitorId and monitorName. Seeing this error, it should be that the name and value are repeated when inserting into the hzb_tag table. The table structure exists: UNIQUE INDEX unique_tag(name ASC, value ASC) USING BTREE. I don't know how to get to the side where hzb_tag is inserted. org.dromara.hertzbeat.manager.service.MonitorService#validate will judge that the monitored name cannot be repeated, and I have not reproduced your problem (I have tried both new creation and modification) ![image](https:// user-images.githubusercontent.com/48920254/258685846-d13dd459-ab4b-40dd-9350-1dce18f1a358.png)

Your code judges whether there is the same name in the monitor table. But the exception is in the hzb_tag table. Is the data in the hzb_tag table omitted when deleting the monitoring? In addition, the two intermediate tables should also be deleted.

The code is to judge that the monitor table has the same name. The problem is that if the name is the same, an exception will be thrown directly, and it will not go to the operation of inserting the hzb_tag table below; the current logic does not support the insertion of monitors with the same name. According to your description, go to the code position and end Yes, the error reported in the previous screenshot is returned, not the error reported that the tag table insertion failed. So I don’t know how the situation you described led to the process of inserting the tag table below. You can look at the database data first. There may be cases where the data in the monitor table you mentioned was deleted but the data in the tag table was not deleted.

Sorry, I missed the content of the post, but I actually wrote it in the title. My operation is to build a monitor called abc. Then delete it, and when creating an abc monitor, an error will be reported. I'll go back and make a video

Okay, I understand, there is no need to record video, there is a problem, let’s fix it here

@Ceilzcx Ceilzcx linked a pull request Aug 7, 2023 that will close this issue
3 tasks
@tomsun28
Copy link
Contributor

fix by v1.4.0

@hertzbeat
Copy link
Contributor

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


fix by v1.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants