@cryptotaxi247 / netdata-1 / commits / d22fbaf17

Health transition saving optimization (#19245)

Choose health transition save mode

Stelios Fragkakis committed Dec 19, 2024 at 00:34 UTC d22fbaf1735584d3b1ae76e5b1c1b8de5473721c
5 files changed +16 -14
src/health/health.h
+2 -2
@@ -58,7 +58,7 @@ void health_api_v1_chart_variables2json(RRDSET *st, BUFFER *wb);
58 void health_api_v1_chart_custom_variables2json(RRDSET *st, BUFFER *buf);
59
60 int health_alarm_log_open(RRDHOST *host);
61 -void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae);
61 +void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae, bool async);
62 void health_alarm_log_load(RRDHOST *host);
63
64 ALARM_ENTRY* health_create_alarm_entry(
@@ -73,7 +73,7 @@ ALARM_ENTRY* health_create_alarm_entry(
73 int delay,
74 HEALTH_ENTRY_FLAGS flags);
75
76 -void health_alarm_log_add_entry(RRDHOST *host, ALARM_ENTRY *ae);
76 +void health_alarm_log_add_entry(RRDHOST *host, ALARM_ENTRY *ae, bool async);
77
78 const char *health_user_config_dir(void);
79 const char *health_stock_config_dir(void);
src/health/health_event_loop.c
+2 -2
@@ -303,7 +303,7 @@ static void health_event_loop_for_host(RRDHOST *host, bool apply_hibernation_del
303
304 if (ae) {
305 health_log_alert(host, ae);
306 - health_alarm_log_add_entry(host, ae);
306 + health_alarm_log_add_entry(host, ae, false);
307 rc->old_status = rc->status;
308 rc->status = RRDCALC_STATUS_REMOVED;
309 rc->last_status_change = now_tmp;
@@ -506,7 +506,7 @@ static void health_event_loop_for_host(RRDHOST *host, bool apply_hibernation_del
506 );
507
508 health_log_alert(host, ae);
509 - health_alarm_log_add_entry(host, ae);
509 + health_alarm_log_add_entry(host, ae, false);
510
511 nd_log(NDLS_DAEMON, NDLP_DEBUG,
512 "[%s]: Alert event for [%s.%s], value [%s], status [%s].",
src/health/health_log.c
+8 -5
@@ -5,9 +5,12 @@
5
6 // ----------------------------------------------------------------------------
7
8 -inline void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae)
8 +inline void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae, bool async)
9 {
10 - metadata_queue_ae_save(host, ae);
10 + if (async)
11 + metadata_queue_ae_save(host, ae);
12 + else
13 + sql_health_alarm_log_save(host, ae);
14 }
15
16 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(
171 return ae;
172 }
173
171 -inline void health_alarm_log_add_entry(RRDHOST *host, ALARM_ENTRY *ae)
174 +inline void health_alarm_log_add_entry(RRDHOST *host, ALARM_ENTRY *ae, bool async)
175 {
176 netdata_log_debug(D_HEALTH, "Health adding alarm log entry with id: %u", ae->unique_id);
177
@@ -195,7 +198,7 @@ inline void health_alarm_log_add_entry(RRDHOST *host, ALARM_ENTRY *ae)
198 (t->old_status == RRDCALC_STATUS_WARNING || t->old_status == RRDCALC_STATUS_CRITICAL))
199 ae->non_clear_duration += t->non_clear_duration;
200
198 - health_alarm_log_save(host, t);
201 + health_alarm_log_save(host, t, async);
202 }
203
204 // no need to continue
@@ -204,7 +207,7 @@ inline void health_alarm_log_add_entry(RRDHOST *host, ALARM_ENTRY *ae)
207 }
208 rw_spinlock_read_unlock(&host->health_log.spinlock);
209
207 - health_alarm_log_save(host, ae);
210 + health_alarm_log_save(host, ae, async);
211 }
212
213 inline void health_alarm_log_free_one_nochecks_nounlink(ALARM_ENTRY *ae) {
src/health/health_notifications.c
+2 -2
@@ -485,7 +485,7 @@ void health_send_notification(RRDHOST *host, ALARM_ENTRY *ae, struct health_rais
485 else
486 netdata_log_error("Failed to execute alarm notification");
487
488 - health_alarm_log_save(host, ae);
488 + health_alarm_log_save(host, ae, false);
489 }
490 else
491 netdata_log_error("Failed to format command arguments");
@@ -497,7 +497,7 @@ void health_send_notification(RRDHOST *host, ALARM_ENTRY *ae, struct health_rais
497
498 return; //health_alarm_wait_for_execution
499 done:
500 - health_alarm_log_save(host, ae);
500 + health_alarm_log_save(host, ae, false);
501 }
502
503 bool health_alarm_log_get_global_id_and_transition_id_for_rrdcalc(RRDCALC *rc, usec_t *global_id, nd_uuid_t *transitions_id) {
src/health/rrdcalc.c
+2 -3
@@ -243,9 +243,8 @@ static void rrdcalc_link_to_rrdset(RRDCALC *rc) {
243 rrdcalc_isrepeating(rc)?HEALTH_ENTRY_FLAG_IS_REPEATING:0);
244
245 health_log_alert(host, ae);
246 - health_alarm_log_add_entry(host, ae);
246 + health_alarm_log_add_entry(host, ae, false);
247 rrdset_flag_set(st, RRDSET_FLAG_HAS_RRDCALC_LINKED);
248 -
248 }
249
250 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) {
276 0);
277
278 health_log_alert(host, ae);
280 - health_alarm_log_add_entry(host, ae);
279 + health_alarm_log_add_entry(host, ae, true);
280 }
281 }
282