@cryptotaxi247 / netdata-1 / commits / f29145fe2

Misc alert fixes (#15274)

* rebase * proper pointer

Emmanuel Vasilakis committed Jun 29, 2023 at 17:20 UTC f29145fe2b45096dd802ed3e9326c6b4f21062da
6 files changed +32 -27
database/rrdcalc.c
+4 -4
@@ -61,13 +61,13 @@ inline const char *rrdcalc_status2string(RRDCALC_STATUS status) {
61 }
62 }
63
64 -uint32_t rrdcalc_get_unique_id(RRDHOST *host, STRING *chart, STRING *name, uint32_t *next_event_id) {
64 +uint32_t rrdcalc_get_unique_id(RRDHOST *host, STRING *chart, STRING *name, uint32_t *next_event_id, uuid_t *config_hash_id) {
65 netdata_rwlock_rdlock(&host->health_log.alarm_log_rwlock);
66
67 // re-use old IDs, by looking them up in the alarm log
68 ALARM_ENTRY *ae = NULL;
69 for(ae = host->health_log.alarms; ae ;ae = ae->next) {
70 - if(unlikely(name == ae->name && chart == ae->chart)) {
70 + if(unlikely(name == ae->name && chart == ae->chart && !uuid_memcmp(&ae->config_hash_id, config_hash_id))) {
71 if(next_event_id) *next_event_id = ae->alarm_event_id + 1;
72 break;
73 }
@@ -79,7 +79,7 @@ uint32_t rrdcalc_get_unique_id(RRDHOST *host, STRING *chart, STRING *name, uint3
79 alarm_id = ae->alarm_id;
80
81 else {
82 - alarm_id = sql_get_alarm_id(host, chart, name, next_event_id);
82 + alarm_id = sql_get_alarm_id(host, chart, name, next_event_id, config_hash_id);
83
84 if (!alarm_id) {
85 if (unlikely(!host->health_log.next_alarm_id))
@@ -531,7 +531,7 @@ static void rrdcalc_rrdhost_insert_callback(const DICTIONARY_ITEM *item __maybe_
531 ;
532 }
533
534 - rc->id = rrdcalc_get_unique_id(host, rc->chart, rc->name, &rc->next_event_id);
534 + rc->id = rrdcalc_get_unique_id(host, rc->chart, rc->name, &rc->next_event_id, &rc->config_hash_id);
535
536 if(rc->calculation) {
537 rc->calculation->status = &rc->status;
database/rrdcalc.h
+1 -1
@@ -240,7 +240,7 @@ const char *rrdcalc_status2string(RRDCALC_STATUS status);
240
241 void rrdcalc_free_unused_rrdcalc_loaded_from_config(RRDCALC *rc);
242
243 -uint32_t rrdcalc_get_unique_id(RRDHOST *host, STRING *chart, STRING *name, uint32_t *next_event_id);
243 +uint32_t rrdcalc_get_unique_id(RRDHOST *host, STRING *chart, STRING *name, uint32_t *next_event_id, uuid_t *config_hash_id);
244 void rrdcalc_add_from_rrdcalctemplate(RRDHOST *host, RRDCALCTEMPLATE *rt, RRDSET *st, const char *overwrite_alert_name, const char *overwrite_dimensions);
245 int rrdcalc_add_from_config(RRDHOST *host, RRDCALC *rc);
246
database/sqlite/sqlite_aclk_alert.c
+3 -7
@@ -69,7 +69,7 @@ int should_send_to_cloud(RRDHOST *host, ALARM_ENTRY *ae)
69 return 0;
70 }
71
72 - if (unlikely(uuid_is_null(ae->config_hash_id)))
72 + if (unlikely(uuid_is_null(ae->config_hash_id)))
73 return 0;
74
75 char sql[ACLK_SYNC_QUERY_SIZE];
@@ -101,7 +101,6 @@ int should_send_to_cloud(RRDHOST *host, ALARM_ENTRY *ae)
101 if (sqlite3_column_type(res, 1) != SQLITE_NULL)
102 uuid_copy(config_hash_id, *((uuid_t *) sqlite3_column_blob(res, 1)));
103 unique_id = (uint32_t) sqlite3_column_int64(res, 2);
104 -
104 } else {
105 send = 1;
106 goto done;
@@ -118,11 +117,8 @@ int should_send_to_cloud(RRDHOST *host, ALARM_ENTRY *ae)
117 }
118
119 //same status, same config
121 - if (ae->new_status == RRDCALC_STATUS_CLEAR || ae->new_status == RRDCALC_STATUS_UNDEFINED) {
122 - send = 0;
123 - update_filtered(ae, unique_id, uuid_str);
124 - goto done;
125 - }
120 + send = 0;
121 + update_filtered(ae, unique_id, uuid_str);
122
123 done:
124 rc = sqlite3_finalize(res);
database/sqlite/sqlite_health.c
+9 -2
@@ -1612,9 +1612,9 @@ int health_migrate_old_health_log_table(char *table) {
1612 return 1;
1613 }
1614
1615 -#define SQL_GET_ALARM_ID "select alarm_id, health_log_id from health_log where host_id = @host_id and chart = @chart and name = @name"
1615 +#define SQL_GET_ALARM_ID "select alarm_id, health_log_id from health_log where host_id = @host_id and chart = @chart and name = @name and config_hash_id = @config_hash_id"
1616 #define SQL_GET_EVENT_ID "select max(alarm_event_id) + 1 from health_log_detail where health_log_id = @health_log_id and alarm_id = @alarm_id"
1617 -uint32_t sql_get_alarm_id(RRDHOST *host, STRING *chart, STRING *name, uint32_t *next_event_id)
1617 +uint32_t sql_get_alarm_id(RRDHOST *host, STRING *chart, STRING *name, uint32_t *next_event_id, uuid_t *config_hash_id)
1618 {
1619 int rc = 0;
1620 sqlite3_stmt *res = NULL;
@@ -1648,6 +1648,13 @@ uint32_t sql_get_alarm_id(RRDHOST *host, STRING *chart, STRING *name, uint32_t *
1648 return alarm_id;
1649 }
1650
1651 + rc = sqlite3_bind_blob(res, 4, config_hash_id, sizeof(*config_hash_id), SQLITE_STATIC);
1652 + if (unlikely(rc != SQLITE_OK)) {
1653 + error_report("Failed to bind config_hash_id parameter for SQL_GET_ALARM_ID.");
1654 + sqlite3_finalize(res);
1655 + return alarm_id;
1656 + }
1657 +
1658 while (sqlite3_step_monitored(res) == SQLITE_ROW) {
1659 alarm_id = (uint32_t) sqlite3_column_int64(res, 0);
1660 health_log_id = (uint64_t) sqlite3_column_int64(res, 1);
database/sqlite/sqlite_health.h
+1 -1
@@ -16,7 +16,7 @@ void sql_aclk_alert_clean_dead_entries(RRDHOST *host);
16 int sql_health_get_last_executed_event(RRDHOST *host, ALARM_ENTRY *ae, RRDCALC_STATUS *last_executed_status);
17 void sql_health_alarm_log2json(RRDHOST *host, BUFFER *wb, uint32_t after, char *chart);
18 int health_migrate_old_health_log_table(char *table);
19 -uint32_t sql_get_alarm_id(RRDHOST *host, STRING *chart, STRING *name, uint32_t *next_event_id);
19 +uint32_t sql_get_alarm_id(RRDHOST *host, STRING *chart, STRING *name, uint32_t *next_event_id, uuid_t *config_hash_id);
20 void sql_health_alarm_log2json_v3(BUFFER *wb, DICTIONARY *alert_instances, time_t after, time_t before, const char *transition, uint32_t max, bool debug);
21 bool sql_find_alert_transition(const char *transition, void (*cb)(const char *machine_guid, const char *context, time_t alert_id, void *data), void *data);
22 #endif //NETDATA_SQLITE_HEALTH_H
health/health.c
+14 -12
@@ -448,7 +448,7 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
448
449 if (likely(ret == 1)) {
450 // we have executed this alarm notification in the past
451 - if(last_executed_status == ae->new_status) {
451 + if(last_executed_status == ae->new_status && !(ae->flags & HEALTH_ENTRY_FLAG_IS_REPEATING)) {
452 // don't send the notification for the same status again
453 debug(D_HEALTH, "Health not sending again notification for alarm '%s.%s' status %s", ae_chart_name(ae), ae_name(ae)
454 , rrdcalc_status2string(ae->new_status));
@@ -563,7 +563,7 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
563 ae->old_value,
564 ae->source?ae_source(ae):"UNKNOWN",
565 (uint32_t)ae->duration,
566 - (uint32_t)ae->non_clear_duration,
566 + (ae->flags & HEALTH_ENTRY_FLAG_IS_REPEATING && ae->new_status >= RRDCALC_STATUS_WARNING) ? (uint32_t)ae->duration : (uint32_t)ae->non_clear_duration,
567 ae_units(ae),
568 ae_info(ae),
569 ae_new_value_string(ae),
@@ -636,17 +636,15 @@ static inline void health_alarm_log_process(RRDHOST *host) {
636
637 ALARM_ENTRY *ae;
638 for(ae = host->health_log.alarms; ae && ae->unique_id >= host->health_last_processed_id; ae = ae->next) {
639 - if(likely(!(ae->flags & HEALTH_ENTRY_FLAG_IS_REPEATING))) {
640 - if(unlikely(
639 + if(unlikely(
640 !(ae->flags & HEALTH_ENTRY_FLAG_PROCESSED) &&
641 !(ae->flags & HEALTH_ENTRY_FLAG_UPDATED)
643 - )) {
644 - if(unlikely(ae->unique_id < first_waiting))
645 - first_waiting = ae->unique_id;
642 + )) {
643 + if(unlikely(ae->unique_id < first_waiting))
644 + first_waiting = ae->unique_id;
645
647 - if(likely(now >= ae->delay_up_to_timestamp))
648 - health_process_notifications(host, ae);
649 - }
646 + if(likely(now >= ae->delay_up_to_timestamp))
647 + health_process_notifications(host, ae);
648 }
649 }
650
@@ -1431,6 +1429,12 @@ void *health_main(void *ptr) {
1429 rc->old_status = rc->status;
1430 rc->status = status;
1431 rc->ae = ae;
1432 +
1433 + if(unlikely(rrdcalc_isrepeating(rc))) {
1434 + rc->last_repeat = now;
1435 + if (rc->status == RRDCALC_STATUS_CLEAR)
1436 + rc->run_flags |= RRDCALC_FLAG_RUN_ONCE;
1437 + }
1438 }
1439
1440 rc->last_updated = now;
@@ -1471,7 +1475,6 @@ void *health_main(void *ptr) {
1475 worker_is_busy(WORKER_HEALTH_JOB_ALARM_LOG_ENTRY);
1476 rc->last_repeat = now;
1477 if (likely(rc->times_repeat < UINT32_MAX)) rc->times_repeat++;
1474 -
1478 ALARM_ENTRY *ae = health_create_alarm_entry(
1479 host,
1480 rc->id,
@@ -1508,7 +1511,6 @@ void *health_main(void *ptr) {
1511 ae->flags |= HEALTH_ENTRY_RUN_ONCE;
1512 }
1513 rc->run_flags |= RRDCALC_FLAG_RUN_ONCE;
1511 - rc->ae = ae;
1514 health_process_notifications(host, ae);
1515 debug(D_HEALTH, "Notification sent for the repeating alarm %u.", ae->alarm_id);
1516 health_alarm_wait_for_execution(ae);