You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@hertzbeat.apache.org by "pwallk (via GitHub)" <gi...@apache.org> on 2024/09/08 12:11:28 UTC
[PR] [feature] Support Collector Alarm [hertzbeat]
pwallk opened a new pull request, #2693:
URL: https://github.com/apache/hertzbeat/pull/2693
## What's changed?
<!-- Describe Your PR Here -->
#2652
<img width="1904" alt="Snipaste_2024-09-08_20-00-31" src="https://github.com/user-attachments/assets/cea2f1a7-7fcc-450a-af42-58116402216c">
## Checklist
- [x] I have read the [Contributing Guide](https://hertzbeat.apache.org/docs/community/code_style_and_quality_guide)
- [x] 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] [feature] Support Collector Alarm [hertzbeat]
Posted by "yangshuDBA (via GitHub)" <gi...@apache.org>.
yangshuDBA commented on PR #2693:
URL: https://github.com/apache/hertzbeat/pull/2693#issuecomment-2472655645
When will this PR plan be merged?
--
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] [feature] Support Collector Alarm [hertzbeat]
Posted by "tomsun28 (via GitHub)" <gi...@apache.org>.
tomsun28 commented on code in PR #2693:
URL: https://github.com/apache/hertzbeat/pull/2693#discussion_r1752971827
##########
alerter/src/main/java/org/apache/hertzbeat/alert/calculate/CollectorAlarmHandler.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.alert.calculate;
+
+import jakarta.persistence.criteria.Predicate;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.hertzbeat.alert.AlerterWorkerPool;
+import org.apache.hertzbeat.alert.dao.AlertCollectorDao;
+import org.apache.hertzbeat.alert.service.AlertService;
+import org.apache.hertzbeat.common.constants.CommonConstants;
+import org.apache.hertzbeat.common.entity.alerter.Alert;
+import org.apache.hertzbeat.common.entity.manager.Collector;
+import org.apache.hertzbeat.common.support.event.CollectorDeletedEvent;
+import org.apache.hertzbeat.common.support.event.SystemConfigChangeEvent;
+import org.apache.hertzbeat.common.util.ResourceBundleUtil;
+import org.springframework.context.event.EventListener;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+import static org.apache.hertzbeat.common.constants.CommonConstants.ALERT_STATUS_CODE_PENDING;
+
+/**
+ * handle collector alarm
+ */
+@Component
+@Slf4j
+public class CollectorAlarmHandler {
+
+ private final Map<String, Alert> offlineAlertMap;
+
+ private final AlertService alertService;
+
+ private final AlertCollectorDao alertCollectorDao;
+
+ private final AlerterWorkerPool workerPool;
+
+ private ResourceBundle bundle;
+
+ public CollectorAlarmHandler(AlertService alertService, AlertCollectorDao alertCollectorDao,
+ AlerterWorkerPool workerPool) {
+ this.offlineAlertMap = new ConcurrentHashMap<>(16);
+ this.alertService = alertService;
+ this.alertCollectorDao = alertCollectorDao;
+ this.workerPool = workerPool;
+ this.bundle = ResourceBundleUtil.getBundle("alerter");
+ List<Collector> collectors = this.alertCollectorDao.findCollectorsByStatus(CommonConstants.COLLECTOR_STATUS_OFFLINE);
+ if (!CollectionUtils.isEmpty(collectors)) {
+ for (Collector collector : collectors) {
+ Map<String, String> tags = new HashMap<>(8);
+ tags.put(CommonConstants.TAG_COLLECTOR_ID, String.valueOf(collector.getId()));
+ tags.put(CommonConstants.TAG_COLLECTOR_NAME, collector.getName());
+ this.offlineAlertMap.put(collector.getName(),
+ Alert.builder().tags(tags).target(CommonConstants.AVAILABILITY).status(ALERT_STATUS_CODE_PENDING).build());
+ }
+ }
+ }
+
+ /**
+ * handle collector online
+ *
+ * @param identity collector name
+ */
+ public void online(final String identity) {
+ Collector collector = alertCollectorDao.findCollectorByName(identity);
+ if (collector == null) {
+ return;
+ }
+ long currentTimeMill = System.currentTimeMillis();
+ Alert preAlert = offlineAlertMap.remove(identity);
+ if (preAlert != null) {
+ Map<String, String> tags = preAlert.getTags();
+ tags.put(CommonConstants.TAG_COLLECTOR_HOST, collector.getIp());
+ String content = this.bundle.getString("alerter.availability.collector.recover");
+ Alert resumeAlert = Alert.builder()
+ .tags(tags)
+ .target(CommonConstants.AVAILABILITY_COLLECTOR)
+ .content(content)
+ .priority(CommonConstants.ALERT_PRIORITY_CODE_WARNING)
+ .status(CommonConstants.ALERT_STATUS_CODE_RESTORED)
+ .firstAlarmTime(currentTimeMill)
+ .lastAlarmTime(preAlert.getLastAlarmTime())
+ .build();
+ workerPool.executeJob(() -> recoverAlarm(identity, resumeAlert));
+ }
+ }
+
+ private void recoverAlarm(String identity, Alert restoreAlert) {
+ List<Long> alertIds = queryAvailabilityAlerts(identity, restoreAlert)
+ .stream()
+ .filter(alert -> Objects.equals(alert.getTags().get(CommonConstants.TAG_COLLECTOR_NAME), identity))
+ .map(Alert::getId)
+ .toList();
+
+ if (!alertIds.isEmpty()) {
+ alertService.editAlertStatus(CommonConstants.ALERT_STATUS_CODE_SOLVED, alertIds);
+
+ // Recovery notifications are generated only after an alarm has occurred
+ alertService.addAlert(restoreAlert);
+ }
+ }
+
+ private List<Alert> queryAvailabilityAlerts(String identity, Alert restoreAlert) {
+ //create query condition
+ Specification<Alert> specification = (root, query, criteriaBuilder) -> {
+ List<Predicate> andList = new ArrayList<>();
+
+ Predicate predicateTags = criteriaBuilder.like(root.get("tags").as(String.class), "%" + identity + "%");
+ andList.add(predicateTags);
+
+ Predicate predicatePriority = criteriaBuilder.equal(root.get("priority"), CommonConstants.ALERT_PRIORITY_CODE_EMERGENCY);
+ andList.add(predicatePriority);
+
+ Predicate predicateStatus = criteriaBuilder.equal(root.get("status"), ALERT_STATUS_CODE_PENDING);
+ andList.add(predicateStatus);
+
+ Predicate predicateAlertTime = criteriaBuilder.lessThanOrEqualTo(root.get("lastAlarmTime"), restoreAlert.getLastAlarmTime());
+ andList.add(predicateAlertTime);
+
+ Predicate[] predicates = new Predicate[andList.size()];
+ return criteriaBuilder.and(andList.toArray(predicates));
+ };
+
+ //query results
+ return alertService.getAlerts(specification);
+ }
+
+ /**
+ * handle collector offline
+ *
+ * @param identity collector name
+ */
+ public void offline(final String identity) {
+ Collector collector = alertCollectorDao.findCollectorByName(identity);
+ if (collector == null) {
+ return;
+ }
+ long currentTimeMill = System.currentTimeMillis();
+
+ Alert preAlert = offlineAlertMap.get(identity);
+ if (preAlert == null) {
+ Map<String, String> tags = new HashMap<>();
+ tags.put(CommonConstants.TAG_COLLECTOR_ID, String.valueOf(collector.getId()));
+ tags.put(CommonConstants.TAG_COLLECTOR_NAME, collector.getName());
+ tags.put(CommonConstants.TAG_COLLECTOR_HOST, collector.getIp());
+ tags.put(CommonConstants.TAG_CODE, "OFFLINE");
+
+ String content = this.bundle.getString("alerter.availability.collector.offline");
+ Alert alert = Alert.builder()
+ .tags(tags)
+ .priority(CommonConstants.ALERT_PRIORITY_CODE_EMERGENCY)
+ .status(CommonConstants.ALERT_STATUS_CODE_PENDING)
+ .target(CommonConstants.AVAILABILITY_COLLECTOR)
+ .content(content)
+ .firstAlarmTime(currentTimeMill)
+ .lastAlarmTime(currentTimeMill)
+ .times(1)
+ .build();
+ this.offlineAlertMap.put(identity, alert);
+ this.alertService.addAlert(alert);
Review Comment:
same +1
--
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] [feature] Support Collector Alarm [hertzbeat]
Posted by "tomsun28 (via GitHub)" <gi...@apache.org>.
tomsun28 commented on code in PR #2693:
URL: https://github.com/apache/hertzbeat/pull/2693#discussion_r1770578376
##########
manager/src/main/java/org/apache/hertzbeat/manager/component/alerter/DispatcherAlarm.java:
##########
@@ -129,6 +130,9 @@ public void run() {
if (alert != null) {
// Determining alarm type storage
alertStoreHandler.store(alert);
+ if (alert.getTags() != null && alert.getTags().containsKey(CommonConstants.TAG_COLLECTOR_NAME)){
+ continue;
+ }
Review Comment:
Got it๐ It is recommended that we can merge after version 1.6.1 and then see how to solve the coupling problem between monitor and alarm.
--
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] [feature] Support Collector Alarm [hertzbeat]
Posted by "tomsun28 (via GitHub)" <gi...@apache.org>.
tomsun28 commented on PR #2693:
URL: https://github.com/apache/hertzbeat/pull/2693#issuecomment-2816540081
hi @pwallk are you interested as a community committer? We would like to invite you to become a HertzBeat committer.
--
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] [feature] Support Collector Alarm [hertzbeat]
Posted by "tomsun28 (via GitHub)" <gi...@apache.org>.
tomsun28 commented on code in PR #2693:
URL: https://github.com/apache/hertzbeat/pull/2693#discussion_r1752971484
##########
alerter/src/main/java/org/apache/hertzbeat/alert/calculate/CollectorAlarmHandler.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.alert.calculate;
+
+import jakarta.persistence.criteria.Predicate;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.hertzbeat.alert.AlerterWorkerPool;
+import org.apache.hertzbeat.alert.dao.AlertCollectorDao;
+import org.apache.hertzbeat.alert.service.AlertService;
+import org.apache.hertzbeat.common.constants.CommonConstants;
+import org.apache.hertzbeat.common.entity.alerter.Alert;
+import org.apache.hertzbeat.common.entity.manager.Collector;
+import org.apache.hertzbeat.common.support.event.CollectorDeletedEvent;
+import org.apache.hertzbeat.common.support.event.SystemConfigChangeEvent;
+import org.apache.hertzbeat.common.util.ResourceBundleUtil;
+import org.springframework.context.event.EventListener;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+import static org.apache.hertzbeat.common.constants.CommonConstants.ALERT_STATUS_CODE_PENDING;
+
+/**
+ * handle collector alarm
+ */
+@Component
+@Slf4j
+public class CollectorAlarmHandler {
+
+ private final Map<String, Alert> offlineAlertMap;
+
+ private final AlertService alertService;
+
+ private final AlertCollectorDao alertCollectorDao;
+
+ private final AlerterWorkerPool workerPool;
+
+ private ResourceBundle bundle;
+
+ public CollectorAlarmHandler(AlertService alertService, AlertCollectorDao alertCollectorDao,
+ AlerterWorkerPool workerPool) {
+ this.offlineAlertMap = new ConcurrentHashMap<>(16);
+ this.alertService = alertService;
+ this.alertCollectorDao = alertCollectorDao;
+ this.workerPool = workerPool;
+ this.bundle = ResourceBundleUtil.getBundle("alerter");
+ List<Collector> collectors = this.alertCollectorDao.findCollectorsByStatus(CommonConstants.COLLECTOR_STATUS_OFFLINE);
+ if (!CollectionUtils.isEmpty(collectors)) {
+ for (Collector collector : collectors) {
+ Map<String, String> tags = new HashMap<>(8);
+ tags.put(CommonConstants.TAG_COLLECTOR_ID, String.valueOf(collector.getId()));
+ tags.put(CommonConstants.TAG_COLLECTOR_NAME, collector.getName());
+ this.offlineAlertMap.put(collector.getName(),
+ Alert.builder().tags(tags).target(CommonConstants.AVAILABILITY).status(ALERT_STATUS_CODE_PENDING).build());
+ }
+ }
+ }
+
+ /**
+ * handle collector online
+ *
+ * @param identity collector name
+ */
+ public void online(final String identity) {
+ Collector collector = alertCollectorDao.findCollectorByName(identity);
+ if (collector == null) {
+ return;
+ }
+ long currentTimeMill = System.currentTimeMillis();
+ Alert preAlert = offlineAlertMap.remove(identity);
+ if (preAlert != null) {
+ Map<String, String> tags = preAlert.getTags();
+ tags.put(CommonConstants.TAG_COLLECTOR_HOST, collector.getIp());
+ String content = this.bundle.getString("alerter.availability.collector.recover");
+ Alert resumeAlert = Alert.builder()
+ .tags(tags)
+ .target(CommonConstants.AVAILABILITY_COLLECTOR)
+ .content(content)
+ .priority(CommonConstants.ALERT_PRIORITY_CODE_WARNING)
+ .status(CommonConstants.ALERT_STATUS_CODE_RESTORED)
+ .firstAlarmTime(currentTimeMill)
+ .lastAlarmTime(preAlert.getLastAlarmTime())
+ .build();
+ workerPool.executeJob(() -> recoverAlarm(identity, resumeAlert));
+ }
+ }
+
+ private void recoverAlarm(String identity, Alert restoreAlert) {
+ List<Long> alertIds = queryAvailabilityAlerts(identity, restoreAlert)
+ .stream()
+ .filter(alert -> Objects.equals(alert.getTags().get(CommonConstants.TAG_COLLECTOR_NAME), identity))
+ .map(Alert::getId)
+ .toList();
+
+ if (!alertIds.isEmpty()) {
+ alertService.editAlertStatus(CommonConstants.ALERT_STATUS_CODE_SOLVED, alertIds);
+
+ // Recovery notifications are generated only after an alarm has occurred
+ alertService.addAlert(restoreAlert);
Review Comment:
๐ hi, how about use `alarmCommonReduce.reduceAndSendAlarm(restoreAlert)` here? We send it for subsequent alarm convergence, alarm silencing, and alarm storage processing. But it needs to be tested, because before it was monitoring related alarms, I donโt know whether it is compatible with collector alarm.
--
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] [feature] Support Collector Alarm [hertzbeat]
Posted by "tomsun28 (via GitHub)" <gi...@apache.org>.
tomsun28 commented on PR #2693:
URL: https://github.com/apache/hertzbeat/pull/2693#issuecomment-2816536848
close #2652
--
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] [feature] Support Collector Alarm [hertzbeat]
Posted by "tomsun28 (via GitHub)" <gi...@apache.org>.
tomsun28 commented on PR #2693:
URL: https://github.com/apache/hertzbeat/pull/2693#issuecomment-2748564490
hi, sorry for missing this, suggest merge after release 1.7.0
--
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] [feature] Support Collector Alarm [hertzbeat]
Posted by "pwallk (via GitHub)" <gi...@apache.org>.
pwallk commented on code in PR #2693:
URL: https://github.com/apache/hertzbeat/pull/2693#discussion_r1753070240
##########
alerter/src/main/java/org/apache/hertzbeat/alert/calculate/CollectorAlarmHandler.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.alert.calculate;
+
+import jakarta.persistence.criteria.Predicate;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.hertzbeat.alert.AlerterWorkerPool;
+import org.apache.hertzbeat.alert.dao.AlertCollectorDao;
+import org.apache.hertzbeat.alert.service.AlertService;
+import org.apache.hertzbeat.common.constants.CommonConstants;
+import org.apache.hertzbeat.common.entity.alerter.Alert;
+import org.apache.hertzbeat.common.entity.manager.Collector;
+import org.apache.hertzbeat.common.support.event.CollectorDeletedEvent;
+import org.apache.hertzbeat.common.support.event.SystemConfigChangeEvent;
+import org.apache.hertzbeat.common.util.ResourceBundleUtil;
+import org.springframework.context.event.EventListener;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+import static org.apache.hertzbeat.common.constants.CommonConstants.ALERT_STATUS_CODE_PENDING;
+
+/**
+ * handle collector alarm
+ */
+@Component
+@Slf4j
+public class CollectorAlarmHandler {
+
+ private final Map<String, Alert> offlineAlertMap;
+
+ private final AlertService alertService;
+
+ private final AlertCollectorDao alertCollectorDao;
+
+ private final AlerterWorkerPool workerPool;
+
+ private ResourceBundle bundle;
+
+ public CollectorAlarmHandler(AlertService alertService, AlertCollectorDao alertCollectorDao,
+ AlerterWorkerPool workerPool) {
+ this.offlineAlertMap = new ConcurrentHashMap<>(16);
+ this.alertService = alertService;
+ this.alertCollectorDao = alertCollectorDao;
+ this.workerPool = workerPool;
+ this.bundle = ResourceBundleUtil.getBundle("alerter");
+ List<Collector> collectors = this.alertCollectorDao.findCollectorsByStatus(CommonConstants.COLLECTOR_STATUS_OFFLINE);
+ if (!CollectionUtils.isEmpty(collectors)) {
+ for (Collector collector : collectors) {
+ Map<String, String> tags = new HashMap<>(8);
+ tags.put(CommonConstants.TAG_COLLECTOR_ID, String.valueOf(collector.getId()));
+ tags.put(CommonConstants.TAG_COLLECTOR_NAME, collector.getName());
+ this.offlineAlertMap.put(collector.getName(),
+ Alert.builder().tags(tags).target(CommonConstants.AVAILABILITY).status(ALERT_STATUS_CODE_PENDING).build());
+ }
+ }
+ }
+
+ /**
+ * handle collector online
+ *
+ * @param identity collector name
+ */
+ public void online(final String identity) {
+ Collector collector = alertCollectorDao.findCollectorByName(identity);
+ if (collector == null) {
+ return;
+ }
+ long currentTimeMill = System.currentTimeMillis();
+ Alert preAlert = offlineAlertMap.remove(identity);
+ if (preAlert != null) {
+ Map<String, String> tags = preAlert.getTags();
+ tags.put(CommonConstants.TAG_COLLECTOR_HOST, collector.getIp());
+ String content = this.bundle.getString("alerter.availability.collector.recover");
+ Alert resumeAlert = Alert.builder()
+ .tags(tags)
+ .target(CommonConstants.AVAILABILITY_COLLECTOR)
+ .content(content)
+ .priority(CommonConstants.ALERT_PRIORITY_CODE_WARNING)
+ .status(CommonConstants.ALERT_STATUS_CODE_RESTORED)
+ .firstAlarmTime(currentTimeMill)
+ .lastAlarmTime(preAlert.getLastAlarmTime())
+ .build();
+ workerPool.executeJob(() -> recoverAlarm(identity, resumeAlert));
+ }
+ }
+
+ private void recoverAlarm(String identity, Alert restoreAlert) {
+ List<Long> alertIds = queryAvailabilityAlerts(identity, restoreAlert)
+ .stream()
+ .filter(alert -> Objects.equals(alert.getTags().get(CommonConstants.TAG_COLLECTOR_NAME), identity))
+ .map(Alert::getId)
+ .toList();
+
+ if (!alertIds.isEmpty()) {
+ alertService.editAlertStatus(CommonConstants.ALERT_STATUS_CODE_SOLVED, alertIds);
+
+ // Recovery notifications are generated only after an alarm has occurred
+ alertService.addAlert(restoreAlert);
Review Comment:
Good idea, I will try to reuse AlarmCommonReduce
--
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] [feature] Support Collector Alarm [hertzbeat]
Posted by "pwallk (via GitHub)" <gi...@apache.org>.
pwallk commented on PR #2693:
URL: https://github.com/apache/hertzbeat/pull/2693#issuecomment-2816607442
> hi @pwallk are you interested as a community committer? We would like to invite you to become a HertzBeat committer.
my pleasure!
--
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] [feature] Support Collector Alarm [hertzbeat]
Posted by "tomsun28 (via GitHub)" <gi...@apache.org>.
tomsun28 commented on code in PR #2693:
URL: https://github.com/apache/hertzbeat/pull/2693#discussion_r1765288437
##########
manager/src/main/java/org/apache/hertzbeat/manager/component/alerter/DispatcherAlarm.java:
##########
@@ -129,6 +130,9 @@ public void run() {
if (alert != null) {
// Determining alarm type storage
alertStoreHandler.store(alert);
+ if (alert.getTags() != null && alert.getTags().containsKey(CommonConstants.TAG_COLLECTOR_NAME)){
+ continue;
+ }
Review Comment:
hi, here has a question that why ignore to send notify the collector alarm message
--
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] [feature] Support Collector Alarm [hertzbeat]
Posted by "pwallk (via GitHub)" <gi...@apache.org>.
pwallk commented on code in PR #2693:
URL: https://github.com/apache/hertzbeat/pull/2693#discussion_r1765973044
##########
manager/src/main/java/org/apache/hertzbeat/manager/component/alerter/DispatcherAlarm.java:
##########
@@ -129,6 +130,9 @@ public void run() {
if (alert != null) {
// Determining alarm type storage
alertStoreHandler.store(alert);
+ if (alert.getTags() != null && alert.getTags().containsKey(CommonConstants.TAG_COLLECTOR_NAME)){
+ continue;
+ }
Review Comment:
`AlertNotifyHandler` and`Monitor` are heavily coupled and the changes are large. Therefore, `send notify` is skipped for now
--
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] [feature] Support Collector Alarm [hertzbeat]
Posted by "tomsun28 (via GitHub)" <gi...@apache.org>.
tomsun28 merged PR #2693:
URL: https://github.com/apache/hertzbeat/pull/2693
--
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] [feature] Support Collector Alarm [hertzbeat]
Posted by "tomsun28 (via GitHub)" <gi...@apache.org>.
tomsun28 commented on PR #2693:
URL: https://github.com/apache/hertzbeat/pull/2693#issuecomment-2823001182
> > hi @pwallk are you interested as a community committer? We would like to invite you to become a HertzBeat committer.
>
> my pleasure!
Can you send a email with concact info to tomsun28@outlook.com ? I can't get your concact.
--
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] [feature] Support Collector Alarm [hertzbeat]
Posted by "pwallk (via GitHub)" <gi...@apache.org>.
pwallk commented on PR #2693:
URL: https://github.com/apache/hertzbeat/pull/2693#issuecomment-2823064525
> > > hi @pwallk are you interested as a community committer? We would like to invite you to become a HertzBeat committer.
> >
> >
> > my pleasure!
>
> Can you send a email with concact info to [tomsun28@outlook.com](mailto:tomsun28@outlook.com) ? I can't get your concact.
Already sent over.
--
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] [feature] Support Collector Alarm [hertzbeat]
Posted by "Aias00 (via GitHub)" <gi...@apache.org>.
Aias00 commented on PR #2693:
URL: https://github.com/apache/hertzbeat/pull/2693#issuecomment-2487231922
> When will this PR plan be merged?
pls fix the conflicts
--
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