@cryptotaxi247 / netdata-1 / commits / 9676eff1b

insert into aclk_alert instead of queuing (#11769)

Emmanuel Vasilakis committed Nov 11, 2021 at 15:06 UTC 9676eff1bc6dfc28e8f1c4857786ec05613b2646
4 files changed +22 -34
database/sqlite/sqlite_aclk.c
-4
@@ -426,10 +426,6 @@ void aclk_database_worker(void *arg)
426 break;
427 #endif
428 // ALERTS
429 - case ACLK_DATABASE_ADD_ALERT:
430 - debug(D_ACLK_SYNC,"Adding alert event for %s", wc->host_guid);
431 - aclk_add_alert_event(wc, cmd);
432 - break;
429 case ACLK_DATABASE_PUSH_ALERT_CONFIG:
430 debug(D_ACLK_SYNC,"Pushing chart config info to the cloud for %s", wc->host_guid);
431 aclk_push_alert_config_event(wc, cmd);
database/sqlite/sqlite_aclk.h
-1
@@ -114,7 +114,6 @@ static inline char *get_str_from_uuid(uuid_t *uuid)
114
115 enum aclk_database_opcode {
116 ACLK_DATABASE_NOOP = 0,
117 - ACLK_DATABASE_ADD_ALERT,
117
118 #ifdef ENABLE_NEW_CLOUD_PROTOCOL
119 ACLK_DATABASE_ADD_CHART,
database/sqlite/sqlite_aclk_alert.c
+21 -28
@@ -10,7 +10,7 @@
10
11 // will replace call to aclk_update_alarm in health/health_log.c
12 // and handle both cases
13 -void sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae)
13 +int sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae)
14 {
15 //check aclk architecture and handle old json alarm update to cloud
16 //include also the valid statuses for this case
@@ -23,54 +23,38 @@ void sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae)
23 ((ae->old_status == RRDCALC_STATUS_WARNING || ae->old_status == RRDCALC_STATUS_CRITICAL))) {
24 aclk_update_alarm(host, ae);
25 }
26 - return;
26 + return 0;
27 #endif
28 #ifdef ENABLE_NEW_CLOUD_PROTOCOL
29 }
30
31 if (ae->flags & HEALTH_ENTRY_FLAG_ACLK_QUEUED)
32 - return;
32 + return 0;
33
34 if (ae->new_status == RRDCALC_STATUS_REMOVED || ae->new_status == RRDCALC_STATUS_UNINITIALIZED)
35 - return;
35 + return 0;
36
37 if (unlikely(!host->dbsync_worker))
38 - return;
38 + return 1;
39
40 if (unlikely(uuid_is_null(ae->config_hash_id)))
41 - return;
42 -
43 - struct aclk_database_cmd cmd;
44 - memset(&cmd, 0, sizeof(cmd));
45 - cmd.opcode = ACLK_DATABASE_ADD_ALERT;
46 - cmd.data = ae;
47 - cmd.completion = NULL;
48 - aclk_database_enq_cmd((struct aclk_database_worker_config *) host->dbsync_worker, &cmd);
49 - ae->flags |= HEALTH_ENTRY_FLAG_ACLK_QUEUED;
50 -#else
51 - UNUSED(host);
52 - UNUSED(ae);
53 -#endif
54 - return;
55 -}
41 + return 0;
42
57 -// stores an alert entry to aclk_alert_ table
58 -int aclk_add_alert_event(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd)
59 -{
43 int rc = 0;
44
45 CHECK_SQLITE_CONNECTION(db_meta);
46
47 sqlite3_stmt *res_alert = NULL;
65 - ALARM_ENTRY *ae = cmd.data;
48 + char uuid_str[GUID_LEN + 1];
49 + uuid_unparse_lower_fix(&host->host_uuid, uuid_str);
50
51 BUFFER *sql = buffer_create(1024);
52
53 buffer_sprintf(
54 sql,
55 "INSERT INTO aclk_alert_%s (alert_unique_id, date_created) "
72 - "VALUES (@alert_unique_id, strftime('%%s')); ",
73 - wc->uuid_str);
56 + "VALUES (@alert_unique_id, strftime('%%s')) on conflict (alert_unique_id) do nothing; ",
57 + uuid_str);
58
59 rc = sqlite3_prepare_v2(db_meta, buffer_tostring(sql), -1, &res_alert, 0);
60 if (unlikely(rc != SQLITE_OK)) {
@@ -84,15 +68,24 @@ int aclk_add_alert_event(struct aclk_database_worker_config *wc, struct aclk_dat
68 goto bind_fail;
69
70 rc = execute_insert(res_alert);
87 - if (unlikely(rc != SQLITE_DONE))
71 + if (unlikely(rc != SQLITE_DONE)) {
72 error_report("Failed to store alert event %u, rc = %d", ae->unique_id, rc);
73 + goto bind_fail;
74 + }
75 +
76 + ae->flags |= HEALTH_ENTRY_FLAG_ACLK_QUEUED;
77
78 bind_fail:
79 if (unlikely(sqlite3_finalize(res_alert) != SQLITE_OK))
80 error_report("Failed to reset statement in store alert event, rc = %d", rc);
81
82 buffer_free(sql);
95 - return (rc != SQLITE_DONE);
83 + return 0;
84 +#else
85 + UNUSED(host);
86 + UNUSED(ae);
87 +#endif
88 + return 0;
89 }
90
91 int rrdcalc_status_to_proto_enum(RRDCALC_STATUS status)
database/sqlite/sqlite_aclk_chart.h
+1 -1
@@ -19,7 +19,7 @@ extern sqlite3 *db_meta;
19 extern int queue_chart_to_aclk(RRDSET *st);
20 extern int queue_dimension_to_aclk(RRDDIM *rd);
21 extern void sql_create_aclk_table(RRDHOST *host, uuid_t *host_uuid, uuid_t *node_id);
22 -extern void sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae);
22 +extern int sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae);
23 int aclk_add_chart_event(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd);
24 int aclk_add_dimension_event(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd);
25 int aclk_send_chart_config(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd);