summaryrefslogtreecommitdiffstats
path: root/database
diff options
context:
space:
mode:
authorEmmanuel Vasilakis <mrzammler@mm.st>2021-11-11 15:06:04 +0200
committerGitHub <noreply@github.com>2021-11-11 15:06:04 +0200
commit9676eff1bc6dfc28e8f1c4857786ec05613b2646 (patch)
treecb2bc7e6c39332bae344fe8148823578c43072a9 /database
parente20c0237fdb73483e678eb49d72e3f6adeb108c9 (diff)
insert into aclk_alert instead of queuing (#11769)
Diffstat (limited to 'database')
-rw-r--r--database/sqlite/sqlite_aclk.c4
-rw-r--r--database/sqlite/sqlite_aclk.h1
-rw-r--r--database/sqlite/sqlite_aclk_alert.c49
-rw-r--r--database/sqlite/sqlite_aclk_chart.h2
4 files changed, 22 insertions, 34 deletions
diff --git a/database/sqlite/sqlite_aclk.c b/database/sqlite/sqlite_aclk.c
index 5af3607555..1f1b0b3191 100644
--- a/database/sqlite/sqlite_aclk.c
+++ b/database/sqlite/sqlite_aclk.c
@@ -426,10 +426,6 @@ void aclk_database_worker(void *arg)
break;
#endif
// ALERTS
- case ACLK_DATABASE_ADD_ALERT:
- debug(D_ACLK_SYNC,"Adding alert event for %s", wc->host_guid);
- aclk_add_alert_event(wc, cmd);
- break;
case ACLK_DATABASE_PUSH_ALERT_CONFIG:
debug(D_ACLK_SYNC,"Pushing chart config info to the cloud for %s", wc->host_guid);
aclk_push_alert_config_event(wc, cmd);
diff --git a/database/sqlite/sqlite_aclk.h b/database/sqlite/sqlite_aclk.h
index 53cda32235..9424a00b7c 100644
--- a/database/sqlite/sqlite_aclk.h
+++ b/database/sqlite/sqlite_aclk.h
@@ -114,7 +114,6 @@ static inline char *get_str_from_uuid(uuid_t *uuid)
enum aclk_database_opcode {
ACLK_DATABASE_NOOP = 0,
- ACLK_DATABASE_ADD_ALERT,
#ifdef ENABLE_NEW_CLOUD_PROTOCOL
ACLK_DATABASE_ADD_CHART,
diff --git a/database/sqlite/sqlite_aclk_alert.c b/database/sqlite/sqlite_aclk_alert.c
index 1b58b4231d..079fc16ea0 100644
--- a/database/sqlite/sqlite_aclk_alert.c
+++ b/database/sqlite/sqlite_aclk_alert.c
@@ -10,7 +10,7 @@
// will replace call to aclk_update_alarm in health/health_log.c
// and handle both cases
-void sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae)
+int sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae)
{
//check aclk architecture and handle old json alarm update to cloud
//include also the valid statuses for this case
@@ -23,54 +23,38 @@ void sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae)
((ae->old_status == RRDCALC_STATUS_WARNING || ae->old_status == RRDCALC_STATUS_CRITICAL))) {
aclk_update_alarm(host, ae);
}
- return;
+ return 0;
#endif
#ifdef ENABLE_NEW_CLOUD_PROTOCOL
}
if (ae->flags & HEALTH_ENTRY_FLAG_ACLK_QUEUED)
- return;
+ return 0;
if (ae->new_status == RRDCALC_STATUS_REMOVED || ae->new_status == RRDCALC_STATUS_UNINITIALIZED)
- return;
+ return 0;
if (unlikely(!host->dbsync_worker))
- return;
+ return 1;
if (unlikely(uuid_is_null(ae->config_hash_id)))
- return;
-
- struct aclk_database_cmd cmd;
- memset(&cmd, 0, sizeof(cmd));
- cmd.opcode = ACLK_DATABASE_ADD_ALERT;
- cmd.data = ae;
- cmd.completion = NULL;
- aclk_database_enq_cmd((struct aclk_database_worker_config *) host->dbsync_worker, &cmd);
- ae->flags |= HEALTH_ENTRY_FLAG_ACLK_QUEUED;
-#else
- UNUSED(host);
- UNUSED(ae);
-#endif
- return;
-}
+ return 0;
-// stores an alert entry to aclk_alert_ table
-int aclk_add_alert_event(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd)
-{
int rc = 0;
CHECK_SQLITE_CONNECTION(db_meta);
sqlite3_stmt *res_alert = NULL;
- ALARM_ENTRY *ae = cmd.data;
+ char uuid_str[GUID_LEN + 1];
+ uuid_unparse_lower_fix(&host->host_uuid, uuid_str);
BUFFER *sql = buffer_create(1024);
buffer_sprintf(
sql,
"INSERT INTO aclk_alert_%s (alert_unique_id, date_created) "
- "VALUES (@alert_unique_id, strftime('%%s')); ",
- wc->uuid_str);
+ "VALUES (@alert_unique_id, strftime('%%s')) on conflict (alert_unique_id) do nothing; ",
+ uuid_str);
rc = sqlite3_prepare_v2(db_meta, buffer_tostring(sql), -1, &res_alert, 0);
if (unlikely(rc != SQLITE_OK)) {
@@ -84,15 +68,24 @@ int aclk_add_alert_event(struct aclk_database_worker_config *wc, struct aclk_dat
goto bind_fail;
rc = execute_insert(res_alert);
- if (unlikely(rc != SQLITE_DONE))
+ if (unlikely(rc != SQLITE_DONE)) {
error_report("Failed to store alert event %u, rc = %d", ae->unique_id, rc);
+ goto bind_fail;
+ }
+
+ ae->flags |= HEALTH_ENTRY_FLAG_ACLK_QUEUED;
bind_fail:
if (unlikely(sqlite3_finalize(res_alert) != SQLITE_OK))
error_report("Failed to reset statement in store alert event, rc = %d", rc);
buffer_free(sql);
- return (rc != SQLITE_DONE);
+ return 0;
+#else
+ UNUSED(host);
+ UNUSED(ae);
+#endif
+ return 0;
}
int rrdcalc_status_to_proto_enum(RRDCALC_STATUS status)
diff --git a/database/sqlite/sqlite_aclk_chart.h b/database/sqlite/sqlite_aclk_chart.h
index cd545f70d4..67d81a534e 100644
--- a/database/sqlite/sqlite_aclk_chart.h
+++ b/database/sqlite/sqlite_aclk_chart.h
@@ -19,7 +19,7 @@ extern sqlite3 *db_meta;
extern int queue_chart_to_aclk(RRDSET *st);
extern int queue_dimension_to_aclk(RRDDIM *rd);
extern void sql_create_aclk_table(RRDHOST *host, uuid_t *host_uuid, uuid_t *node_id);
-extern void sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae);
+extern int sql_queue_alarm_to_aclk(RRDHOST *host, ALARM_ENTRY *ae);
int aclk_add_chart_event(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd);
int aclk_add_dimension_event(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd);
int aclk_send_chart_config(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd);