Use original summary for alert transition (#16793)
Use original summary for alert Fetch transaction and global id for transitions safely
Stelios Fragkakis committed
Jan 15, 2024 at 20:31 UTC
1973e70b62f75bc11dfdc8cb7c6ca1fd3d3f10fc
5 files changed
+32
-9
database/contexts/api_v2.c
+3
-4
@@ -319,7 +319,7 @@ static void alerts_v2_insert_callback(const DICTIONARY_ITEM *item __maybe_unused
319
struct alert_v2_entry *t = value;
320
RRDCALC *rc = t->tmp;
321
t->name = rc->name;
322
- t->summary = rc->summary;
322
+ t->summary = rc->original_summary;
323
t->ati = ctl->alerts.ati++;
324
325
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
368
t->host = rc->rrdset->rrdhost;
369
t->alarm_id = rc->id;
370
t->ni = ctl->nodes.ni;
371
- t->global_id = rc->ae ? rc->ae->global_id : 0;
371
t->name = rc->name;
372
373
uuid_copy(t->config_hash_id, rc->config_hash_id);
375
- if(rc->ae)
376
- uuid_copy(t->last_transition_id, rc->ae->transition_id);
374
+
375
+ health_alarm_log_get_global_id_and_transition_id_for_rrdcalc(rc, &t->global_id, &t->last_transition_id);
376
}
377
378
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) {
database/rrdcalc.c
-2
@@ -328,7 +328,6 @@ static void rrdcalc_link_to_rrdset(RRDSET *st, RRDCALC *rc) {
328
0,
329
rrdcalc_isrepeating(rc)?HEALTH_ENTRY_FLAG_IS_REPEATING:0);
330
331
- rc->ae = ae;
331
health_alarm_log_add_entry(host, ae);
332
rrdset_flag_set(st, RRDSET_FLAG_HAS_RRDCALC_LINKED);
333
}
@@ -374,7 +373,6 @@ static void rrdcalc_unlink_from_rrdset(RRDCALC *rc, bool having_ll_wrlock) {
373
0,
374
0);
375
377
- rc->ae = ae;
376
health_alarm_log_add_entry(host, ae);
377
}
378
database/rrdcalc.h
-1
@@ -141,7 +141,6 @@ struct rrdcalc {
141
int delay_up_current; // the current up notification delay duration
142
int delay_down_current; // the current down notification delay duration
143
int delay_last; // the last delay we used
144
- ALARM_ENTRY *ae; // last alarm entry
144
145
// ------------------------------------------------------------------------
146
// variables this alarm exposes to the rest of the alarms
health/health.c
+28
-2
@@ -22,6 +22,34 @@ char *silencers_filename;
22
SIMPLE_PATTERN *conf_enabled_alarms = NULL;
23
DICTIONARY *health_rrdvars;
24
25
+bool health_alarm_log_get_global_id_and_transition_id_for_rrdcalc(RRDCALC *rc, usec_t *global_id, uuid_t *transitions_id) {
26
+ if(!rc->rrdset)
27
+ return false;
28
+
29
+ RRDHOST *host = rc->rrdset->rrdhost;
30
+
31
+ rw_spinlock_read_lock(&host->health_log.spinlock);
32
+
33
+ ALARM_ENTRY *ae;
34
+ for(ae = host->health_log.alarms; ae ; ae = ae->next) {
35
+ if(unlikely(ae->alarm_id == rc->id))
36
+ break;
37
+ }
38
+
39
+ if(ae) {
40
+ *global_id = ae->global_id;
41
+ uuid_copy(*transitions_id, ae->transition_id);
42
+ }
43
+ else {
44
+ *global_id = 0;
45
+ uuid_clear(*transitions_id);
46
+ }
47
+
48
+ rw_spinlock_read_unlock(&host->health_log.spinlock);
49
+
50
+ return ae != NULL;
51
+}
52
+
53
void health_entry_flags_to_json_array(BUFFER *wb, const char *key, HEALTH_ENTRY_FLAGS flags) {
54
buffer_json_member_add_array(wb, key);
55
@@ -1220,7 +1248,6 @@ void *health_main(void *ptr) {
1248
rc->last_status_change_value = rc->value;
1249
rc->last_updated = now;
1250
rc->value = NAN;
1223
- rc->ae = ae;
1251
1252
#ifdef ENABLE_ACLK
1253
if (netdata_cloud_enabled)
@@ -1496,7 +1523,6 @@ void *health_main(void *ptr) {
1523
rc->last_status_change = now;
1524
rc->old_status = rc->status;
1525
rc->status = status;
1499
- rc->ae = ae;
1526
1527
if(unlikely(rrdcalc_isrepeating(rc))) {
1528
rc->last_repeat = now;
health/health.h
+1
@@ -106,5 +106,6 @@ void health_string2json(BUFFER *wb, const char *prefix, const char *label, const
106
107
void health_log_alert_transition_with_trace(RRDHOST *host, ALARM_ENTRY *ae, int line, const char *file, const char *function);
108
#define health_log_alert(host, ae) health_log_alert_transition_with_trace(host, ae, __LINE__, __FILE__, __FUNCTION__)
109
+bool health_alarm_log_get_global_id_and_transition_id_for_rrdcalc(RRDCALC *rc, usec_t *global_id, uuid_t *transitions_id);
110
111
#endif //NETDATA_HEALTH_H