Always queue alerts to aclk_alert (#11806)
* always queue to aclk_alert * proper function name
Emmanuel Vasilakis committed
Nov 18, 2021 at 20:14 UTC
14507c95979aff73b4359d92a7d4e6aacdbb4a47
6 files changed
+35
-4
database/sqlite/sqlite_aclk.c
+1
-1
@@ -30,7 +30,7 @@ const char *aclk_sync_config[] = {
30
uv_mutex_t aclk_async_lock;
31
struct aclk_database_worker_config *aclk_thread_head = NULL;
32
33
-static inline int claimed()
33
+int claimed()
34
{
35
int rc;
36
rrdhost_aclk_state_lock(localhost);
database/sqlite/sqlite_aclk.h
+1
@@ -226,4 +226,5 @@ void sql_aclk_sync_init(void);
226
void sql_check_aclk_table_list(struct aclk_database_worker_config *wc);
227
void sql_delete_aclk_table_list(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd);
228
void sql_maint_aclk_sync_database(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd);
229
+int claimed();
230
#endif //NETDATA_SQLITE_ACLK_H
database/sqlite/sqlite_aclk_alert.c
+29
-2
@@ -16,18 +16,20 @@ int sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae)
16
//include also the valid statuses for this case
17
#ifdef ENABLE_ACLK
18
#ifdef ENABLE_NEW_CLOUD_PROTOCOL
19
- if (!aclk_use_new_cloud_arch) {
19
+ if (!aclk_use_new_cloud_arch && aclk_connected) {
20
#endif
21
22
if ((ae->new_status == RRDCALC_STATUS_WARNING || ae->new_status == RRDCALC_STATUS_CRITICAL) ||
23
((ae->old_status == RRDCALC_STATUS_WARNING || ae->old_status == RRDCALC_STATUS_CRITICAL))) {
24
aclk_update_alarm(host, ae);
25
}
26
- return 0;
26
#endif
27
#ifdef ENABLE_NEW_CLOUD_PROTOCOL
28
}
29
30
+ if (!claimed())
31
+ return 0;
32
+
33
if (ae->flags & HEALTH_ENTRY_FLAG_ACLK_QUEUED)
34
return 0;
35
@@ -846,3 +848,28 @@ void aclk_push_alert_snapshot_event(struct aclk_database_worker_config *wc, stru
848
#endif
849
return;
850
}
851
+
852
+void sql_aclk_alert_clean_dead_entries(RRDHOST *host)
853
+{
854
+#ifdef ENABLE_NEW_CLOUD_PROTOCOL
855
+ if (!claimed())
856
+ return;
857
+
858
+ if (unlikely(!host->dbsync_worker))
859
+ return;
860
+
861
+ char uuid_str[GUID_LEN + 1];
862
+ uuid_unparse_lower_fix(&host->host_uuid, uuid_str);
863
+
864
+ BUFFER *sql = buffer_create(1024);
865
+
866
+ buffer_sprintf(sql,"delete from aclk_alert_%s where alert_unique_id not in "
867
+ " (select unique_id from health_log_%s); ", uuid_str, uuid_str);
868
+
869
+ db_execute(buffer_tostring(sql));
870
+
871
+ buffer_free(sql);
872
+#else
873
+ UNUSED(host);
874
+#endif
875
+}
database/sqlite/sqlite_health.c
+2
@@ -392,6 +392,8 @@ void sql_health_alarm_log_cleanup(RRDHOST *host) {
392
error_report("Failed to finalize the prepared statement to cleanup health log table");
393
394
host->health_log_entries_written = rotate_every;
395
+
396
+ sql_aclk_alert_clean_dead_entries(host);
397
}
398
399
/* Health related SQL queries
database/sqlite/sqlite_health.h
+1
@@ -13,4 +13,5 @@ extern void sql_health_alarm_log_insert(RRDHOST *host, ALARM_ENTRY *ae);
13
extern void sql_health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae);
14
extern void sql_health_alarm_log_cleanup(RRDHOST *host);
15
extern int alert_hash_and_store_config(uuid_t hash_id, struct alert_config *cfg);
16
+extern void sql_aclk_alert_clean_dead_entries(RRDHOST *host);
17
#endif //NETDATA_SQLITE_HEALTH_H
health/health.c
+1
-1
@@ -1040,7 +1040,7 @@ void *health_main(void *ptr) {
1040
1041
#ifdef ENABLE_ACLK
1042
#ifdef ENABLE_NEW_CLOUD_PROTOCOL
1043
- if (netdata_cloud_setting && unlikely(aclk_alert_reloaded)) {
1043
+ if (netdata_cloud_setting && unlikely(aclk_alert_reloaded) && loop > 2) {
1044
sql_queue_removed_alerts_to_aclk(host);
1045
}
1046
#endif