Skip to content

Commit

Permalink
Health transition saving optimization (netdata#19245)
Browse files Browse the repository at this point in the history
Choose health transition save mode
  • Loading branch information
stelfrag authored Dec 18, 2024
1 parent 6128e50 commit d22fbaf
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/health/health.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/health/health_event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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].",
Expand Down
13 changes: 8 additions & 5 deletions src/health/health_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand All @@ -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
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/health/health_notifications.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions src/health/rrdcalc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit d22fbaf

Please sign in to comment.