diff --git a/src/health/health.h b/src/health/health.h index cdd089623f54af..b6790b4d5852f7 100644 --- a/src/health/health.h +++ b/src/health/health.h @@ -58,7 +58,7 @@ void health_api_v1_chart_variables2json(RRDSET *st, BUFFER *wb); void health_api_v1_chart_custom_variables2json(RRDSET *st, BUFFER *buf); int health_alarm_log_open(RRDHOST *host); -void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae); +void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae, bool async); void health_alarm_log_load(RRDHOST *host); ALARM_ENTRY* health_create_alarm_entry( @@ -73,7 +73,7 @@ ALARM_ENTRY* health_create_alarm_entry( int delay, HEALTH_ENTRY_FLAGS flags); -void health_alarm_log_add_entry(RRDHOST *host, ALARM_ENTRY *ae); +void health_alarm_log_add_entry(RRDHOST *host, ALARM_ENTRY *ae, bool async); const char *health_user_config_dir(void); const char *health_stock_config_dir(void); diff --git a/src/health/health_event_loop.c b/src/health/health_event_loop.c index d20d99d35d9c16..2b6d2529da0103 100644 --- a/src/health/health_event_loop.c +++ b/src/health/health_event_loop.c @@ -303,7 +303,7 @@ static void health_event_loop_for_host(RRDHOST *host, bool apply_hibernation_del if (ae) { health_log_alert(host, ae); - health_alarm_log_add_entry(host, ae); + health_alarm_log_add_entry(host, ae, false); rc->old_status = rc->status; rc->status = RRDCALC_STATUS_REMOVED; rc->last_status_change = now_tmp; @@ -506,7 +506,7 @@ static void health_event_loop_for_host(RRDHOST *host, bool apply_hibernation_del ); health_log_alert(host, ae); - health_alarm_log_add_entry(host, ae); + health_alarm_log_add_entry(host, ae, false); nd_log(NDLS_DAEMON, NDLP_DEBUG, "[%s]: Alert event for [%s.%s], value [%s], status [%s].", diff --git a/src/health/health_log.c b/src/health/health_log.c index d5f8b9b9acf288..e8c66f0402be3b 100644 --- a/src/health/health_log.c +++ b/src/health/health_log.c @@ -5,9 +5,12 @@ // ---------------------------------------------------------------------------- -inline void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae) +inline void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae, bool async) { - metadata_queue_ae_save(host, ae); + if (async) + metadata_queue_ae_save(host, ae); + else + sql_health_alarm_log_save(host, ae); } void health_log_alert_transition_with_trace(RRDHOST *host, ALARM_ENTRY *ae, int line, const char *file, const char *function) { @@ -168,7 +171,7 @@ inline ALARM_ENTRY* health_create_alarm_entry( return ae; } -inline void health_alarm_log_add_entry(RRDHOST *host, ALARM_ENTRY *ae) +inline void health_alarm_log_add_entry(RRDHOST *host, ALARM_ENTRY *ae, bool async) { netdata_log_debug(D_HEALTH, "Health adding alarm log entry with id: %u", ae->unique_id); @@ -195,7 +198,7 @@ inline void health_alarm_log_add_entry(RRDHOST *host, ALARM_ENTRY *ae) (t->old_status == RRDCALC_STATUS_WARNING || t->old_status == RRDCALC_STATUS_CRITICAL)) ae->non_clear_duration += t->non_clear_duration; - health_alarm_log_save(host, t); + health_alarm_log_save(host, t, async); } // no need to continue @@ -204,7 +207,7 @@ inline void health_alarm_log_add_entry(RRDHOST *host, ALARM_ENTRY *ae) } rw_spinlock_read_unlock(&host->health_log.spinlock); - health_alarm_log_save(host, ae); + health_alarm_log_save(host, ae, async); } inline void health_alarm_log_free_one_nochecks_nounlink(ALARM_ENTRY *ae) { diff --git a/src/health/health_notifications.c b/src/health/health_notifications.c index 2b11b5bf2f3cb2..13e9ef8e4f84ec 100644 --- a/src/health/health_notifications.c +++ b/src/health/health_notifications.c @@ -485,7 +485,7 @@ void health_send_notification(RRDHOST *host, ALARM_ENTRY *ae, struct health_rais else netdata_log_error("Failed to execute alarm notification"); - health_alarm_log_save(host, ae); + health_alarm_log_save(host, ae, false); } else netdata_log_error("Failed to format command arguments"); @@ -497,7 +497,7 @@ void health_send_notification(RRDHOST *host, ALARM_ENTRY *ae, struct health_rais return; //health_alarm_wait_for_execution done: - health_alarm_log_save(host, ae); + health_alarm_log_save(host, ae, false); } bool health_alarm_log_get_global_id_and_transition_id_for_rrdcalc(RRDCALC *rc, usec_t *global_id, nd_uuid_t *transitions_id) { diff --git a/src/health/rrdcalc.c b/src/health/rrdcalc.c index 645bab24a73f25..cd499b8e2b8ba9 100644 --- a/src/health/rrdcalc.c +++ b/src/health/rrdcalc.c @@ -243,9 +243,8 @@ static void rrdcalc_link_to_rrdset(RRDCALC *rc) { rrdcalc_isrepeating(rc)?HEALTH_ENTRY_FLAG_IS_REPEATING:0); health_log_alert(host, ae); - health_alarm_log_add_entry(host, ae); + health_alarm_log_add_entry(host, ae, false); rrdset_flag_set(st, RRDSET_FLAG_HAS_RRDCALC_LINKED); - } static void rrdcalc_unlink_from_rrdset(RRDCALC *rc, bool having_ll_wrlock) { @@ -277,7 +276,7 @@ static void rrdcalc_unlink_from_rrdset(RRDCALC *rc, bool having_ll_wrlock) { 0); health_log_alert(host, ae); - health_alarm_log_add_entry(host, ae); + health_alarm_log_add_entry(host, ae, true); } }