You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@hertzbeat.apache.org by "yunfan24 (via GitHub)" <gi...@apache.org> on 2025/02/06 14:14:19 UTC
[PR] [bugfix] Fix the issue where the monitoring status is not updated. [hertzbeat]
yunfan24 opened a new pull request, #3056:
URL: https://github.com/apache/hertzbeat/pull/3056
## What's changed?
<!-- Describe Your PR Here -->
fix #3047
## Checklist
- [ ] I have read the [Contributing Guide](https://hertzbeat.apache.org/docs/community/code_style_and_quality_guide)
- [ ] I have written the necessary doc or comment.
- [ ] I have added the necessary unit tests and all cases have passed.
## Add or update API
- [ ] I have added the necessary [e2e tests](https://github.com/apache/hertzbeat/tree/master/e2e) and all cases have passed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@hertzbeat.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@hertzbeat.apache.org
For additional commands, e-mail: notifications-help@hertzbeat.apache.org
Re: [PR] [bugfix] Fix the issue where the monitoring status is not updated. [hertzbeat]
Posted by "tomsun28 (via GitHub)" <gi...@apache.org>.
tomsun28 merged PR #3056:
URL: https://github.com/apache/hertzbeat/pull/3056
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@hertzbeat.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@hertzbeat.apache.org
For additional commands, e-mail: notifications-help@hertzbeat.apache.org
Re: [PR] [bugfix] Fix the issue where the monitoring status is not updated. [hertzbeat]
Posted by "tomsun28 (via GitHub)" <gi...@apache.org>.
tomsun28 commented on code in PR #3056:
URL: https://github.com/apache/hertzbeat/pull/3056#discussion_r1945867278
##########
hertzbeat-warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/DataStorageDispatch.java:
##########
@@ -87,24 +91,16 @@ protected void calculateMonitorStatus(CollectRep.MetricsData metricsData) {
if (metricsData.getPriority() == 0) {
long id = metricsData.getId();
CollectRep.Code code = metricsData.getCode();
- // query current status
- String queryStatusSql = "SELECT status FROM hzb_monitor WHERE id = ?";
try {
- int currentStatus = jdbcTemplate.queryForObject(queryStatusSql, Integer.class, id);
- if (code == CollectRep.Code.SUCCESS && currentStatus == CommonConstants.MONITOR_DOWN_CODE) {
- // if collect success and current status is DOWN, update to UP
- String sql = "UPDATE hzb_monitor SET status = ? WHERE id = ?";
- jdbcTemplate.update(sql, CommonConstants.MONITOR_UP_CODE, id);
- } else if (code != CollectRep.Code.SUCCESS && currentStatus == CommonConstants.MONITOR_UP_CODE) {
- // if collect failed and current status is UP, update to DOWN
- String sql = "UPDATE hzb_monitor SET status = ? WHERE id = ?";
- jdbcTemplate.update(sql, CommonConstants.MONITOR_DOWN_CODE, id);
+ String sql = "UPDATE hzb_monitor SET status = ? WHERE id = ? AND status != ?";
+ int status = code == CollectRep.Code.SUCCESS ? CommonConstants.MONITOR_UP_CODE : CommonConstants.MONITOR_DOWN_CODE;
+ int matchedRows = jdbcTemplate.update(sql, status, id, status);
Review Comment:
👍 hi, how about this? `status=?` can use the database index, and ignore case when status is PAUSED
```suggestion
String sql = "UPDATE hzb_monitor SET status = ? WHERE id = ? AND status = ?";
int status = code == CollectRep.Code.SUCCESS ? CommonConstants.MONITOR_UP_CODE : CommonConstants.MONITOR_DOWN_CODE;
int preStatus = code == CollectRep.Code.SUCCESS ? CommonConstants.MONITOR_DOWN_CODE : CommonConstants.MONITOR_UP_CODE;
int matchedRows = jdbcTemplate.update(sql, status, id, preStatus);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@hertzbeat.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@hertzbeat.apache.org
For additional commands, e-mail: notifications-help@hertzbeat.apache.org
Re: [PR] [bugfix] Fix the issue where the monitoring status is not updated. [hertzbeat]
Posted by "yunfan24 (via GitHub)" <gi...@apache.org>.
yunfan24 commented on code in PR #3056:
URL: https://github.com/apache/hertzbeat/pull/3056#discussion_r1945897696
##########
hertzbeat-warehouse/src/main/java/org/apache/hertzbeat/warehouse/store/DataStorageDispatch.java:
##########
@@ -87,24 +91,16 @@ protected void calculateMonitorStatus(CollectRep.MetricsData metricsData) {
if (metricsData.getPriority() == 0) {
long id = metricsData.getId();
CollectRep.Code code = metricsData.getCode();
- // query current status
- String queryStatusSql = "SELECT status FROM hzb_monitor WHERE id = ?";
try {
- int currentStatus = jdbcTemplate.queryForObject(queryStatusSql, Integer.class, id);
- if (code == CollectRep.Code.SUCCESS && currentStatus == CommonConstants.MONITOR_DOWN_CODE) {
- // if collect success and current status is DOWN, update to UP
- String sql = "UPDATE hzb_monitor SET status = ? WHERE id = ?";
- jdbcTemplate.update(sql, CommonConstants.MONITOR_UP_CODE, id);
- } else if (code != CollectRep.Code.SUCCESS && currentStatus == CommonConstants.MONITOR_UP_CODE) {
- // if collect failed and current status is UP, update to DOWN
- String sql = "UPDATE hzb_monitor SET status = ? WHERE id = ?";
- jdbcTemplate.update(sql, CommonConstants.MONITOR_DOWN_CODE, id);
+ String sql = "UPDATE hzb_monitor SET status = ? WHERE id = ? AND status != ?";
+ int status = code == CollectRep.Code.SUCCESS ? CommonConstants.MONITOR_UP_CODE : CommonConstants.MONITOR_DOWN_CODE;
+ int matchedRows = jdbcTemplate.update(sql, status, id, status);
Review Comment:
👍hi, I think it's very good
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@hertzbeat.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@hertzbeat.apache.org
For additional commands, e-mail: notifications-help@hertzbeat.apache.org