summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStelios Fragkakis <52996999+stelfrag@users.noreply.github.com>2024-01-15 20:31:23 +0200
committerGitHub <noreply@github.com>2024-01-15 20:31:23 +0200
commit1973e70b62f75bc11dfdc8cb7c6ca1fd3d3f10fc (patch)
treecaf0889053853db0e34fc6034842405f70468307
parent10721be4ec3feaf72ff45856a7c447fe95a4b435 (diff)
Use original summary for alert transition (#16793)
Use original summary for alert Fetch transaction and global id for transitions safely
-rw-r--r--database/contexts/api_v2.c7
-rw-r--r--database/rrdcalc.c2
-rw-r--r--database/rrdcalc.h1
-rw-r--r--health/health.c30
-rw-r--r--health/health.h1
5 files changed, 32 insertions, 9 deletions
diff --git a/database/contexts/api_v2.c b/database/contexts/api_v2.c
index 3d2a954547..f9e20d407e 100644
--- a/database/contexts/api_v2.c
+++ b/database/contexts/api_v2.c
@@ -319,7 +319,7 @@ static void alerts_v2_insert_callback(const DICTIONARY_ITEM *item __maybe_unused
struct alert_v2_entry *t = value;
RRDCALC *rc = t->tmp;
t->name = rc->name;
- t->summary = rc->summary;
+ t->summary = rc->original_summary;
t->ati = ctl->alerts.ati++;
t->nodes = dictionary_create(DICT_OPTION_SINGLE_THREADED|DICT_OPTION_VALUE_LINK_DONT_CLONE|DICT_OPTION_NAME_LINK_DONT_CLONE);
@@ -368,12 +368,11 @@ static void alert_instances_v2_insert_callback(const DICTIONARY_ITEM *item __may
t->host = rc->rrdset->rrdhost;
t->alarm_id = rc->id;
t->ni = ctl->nodes.ni;
- t->global_id = rc->ae ? rc->ae->global_id : 0;
t->name = rc->name;
uuid_copy(t->config_hash_id, rc->config_hash_id);
- if(rc->ae)
- uuid_copy(t->last_transition_id, rc->ae->transition_id);
+
+ health_alarm_log_get_global_id_and_transition_id_for_rrdcalc(rc, &t->global_id, &t->last_transition_id);
}
static bool alert_instances_v2_conflict_callback(const DICTIONARY_ITEM *item __maybe_unused, void *old_value __maybe_unused, void *new_value __maybe_unused, void *data __maybe_unused) {
diff --git a/database/rrdcalc.c b/database/rrdcalc.c
index 2fabcb54c5..d17f2b12d6 100644
--- a/database/rrdcalc.c
+++ b/database/rrdcalc.c
@@ -328,7 +328,6 @@ static void rrdcalc_link_to_rrdset(RRDSET *st, RRDCALC *rc) {
0,
rrdcalc_isrepeating(rc)?HEALTH_ENTRY_FLAG_IS_REPEATING:0);
- rc->ae = ae;
health_alarm_log_add_entry(host, ae);
rrdset_flag_set(st, RRDSET_FLAG_HAS_RRDCALC_LINKED);
}
@@ -374,7 +373,6 @@ static void rrdcalc_unlink_from_rrdset(RRDCALC *rc, bool having_ll_wrlock) {
0,
0);
- rc->ae = ae;
health_alarm_log_add_entry(host, ae);
}
diff --git a/database/rrdcalc.h b/database/rrdcalc.h
index 71f43633c4..534f811c40 100644
--- a/database/rrdcalc.h
+++ b/database/rrdcalc.h
@@ -141,7 +141,6 @@ struct rrdcalc {
int delay_up_current; // the current up notification delay duration
int delay_down_current; // the current down notification delay duration
int delay_last; // the last delay we used
- ALARM_ENTRY *ae; // last alarm entry
// ------------------------------------------------------------------------
// variables this alarm exposes to the rest of the alarms
diff --git a/health/health.c b/health/health.c
index c1a11167c7..2eb782cb44 100644
--- a/health/health.c
+++ b/health/health.c
@@ -22,6 +22,34 @@ char *silencers_filename;
SIMPLE_PATTERN *conf_enabled_alarms = NULL;
DICTIONARY *health_rrdvars;
+bool health_alarm_log_get_global_id_and_transition_id_for_rrdcalc(RRDCALC *rc, usec_t *global_id, uuid_t *transitions_id) {
+ if(!rc->rrdset)
+ return false;
+
+ RRDHOST *host = rc->rrdset->rrdhost;
+
+ rw_spinlock_read_lock(&host->health_log.spinlock);
+
+ ALARM_ENTRY *ae;
+ for(ae = host->health_log.alarms; ae ; ae = ae->next) {
+ if(unlikely(ae->alarm_id == rc->id))
+ break;
+ }
+
+ if(ae) {
+ *global_id = ae->global_id;
+ uuid_copy(*transitions_id, ae->transition_id);
+ }
+ else {
+ *global_id = 0;
+ uuid_clear(*transitions_id);
+ }
+
+ rw_spinlock_read_unlock(&host->health_log.spinlock);
+
+ return ae != NULL;
+}
+
void health_entry_flags_to_json_array(BUFFER *wb, const char *key, HEALTH_ENTRY_FLAGS flags) {
buffer_json_member_add_array(wb, key);
@@ -1220,7 +1248,6 @@ void *health_main(void *ptr) {
rc->last_status_change_value = rc->value;
rc->last_updated = now;
rc->value = NAN;
- rc->ae = ae;
#ifdef ENABLE_ACLK
if (netdata_cloud_enabled)
@@ -1496,7 +1523,6 @@ void *health_main(void *ptr) {
rc->last_status_change = now;
rc->old_status = rc->status;
rc->status = status;
- rc->ae = ae;
if(unlikely(rrdcalc_isrepeating(rc))) {
rc->last_repeat = now;
diff --git a/health/health.h b/health/health.h
index ef24624465..a107500b3b 100644
--- a/health/health.h
+++ b/health/health.h
@@ -106,5 +106,6 @@ void health_string2json(BUFFER *wb, const char *prefix, const char *label, const
void health_log_alert_transition_with_trace(RRDHOST *host, ALARM_ENTRY *ae, int line, const char *file, const char *function);
#define health_log_alert(host, ae) health_log_alert_transition_with_trace(host, ae, __LINE__, __FILE__, __FUNCTION__)
+bool health_alarm_log_get_global_id_and_transition_id_for_rrdcalc(RRDCALC *rc, usec_t *global_id, uuid_t *transitions_id);
#endif //NETDATA_HEALTH_H