diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-11-25 17:33:56 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-11-25 17:34:10 +0000 |
commit | 83ba6762cc43d9db581b979bb5e3445669e46cc2 (patch) | |
tree | 2e69833b43f791ed253a7a20318b767ebe56cdb8 /src/database/sqlite/sqlite_aclk_alert.c | |
parent | Releasing debian version 1.47.5-1. (diff) | |
download | netdata-83ba6762cc43d9db581b979bb5e3445669e46cc2.tar.xz netdata-83ba6762cc43d9db581b979bb5e3445669e46cc2.zip |
Merging upstream version 2.0.3+dfsg (Closes: #923993, #1042533, #1045145).
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/database/sqlite/sqlite_aclk_alert.c')
-rw-r--r-- | src/database/sqlite/sqlite_aclk_alert.c | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/src/database/sqlite/sqlite_aclk_alert.c b/src/database/sqlite/sqlite_aclk_alert.c index dbe5a5045..4aa640484 100644 --- a/src/database/sqlite/sqlite_aclk_alert.c +++ b/src/database/sqlite/sqlite_aclk_alert.c @@ -3,7 +3,6 @@ #include "sqlite_functions.h" #include "sqlite_aclk_alert.h" -#ifdef ENABLE_ACLK #include "../../aclk/aclk_alarm_api.h" #define SQLITE3_COLUMN_STRDUPZ_OR_NULL(res, param) \ @@ -116,14 +115,14 @@ static int insert_alert_to_submit_queue(RRDHOST *host, int64_t health_log_id, ui return 1; } - if (is_event_from_alert_variable_config(unique_id, &host->host_uuid)) + if (is_event_from_alert_variable_config(unique_id, &host->host_id.uuid)) return 2; if (!PREPARE_COMPILED_STATEMENT(db_meta, SQL_QUEUE_ALERT_TO_CLOUD, &res)) return -1; int param = 0; - SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_uuid, sizeof(host->host_uuid), SQLITE_STATIC)); + SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_id.uuid, sizeof(host->host_id.uuid), SQLITE_STATIC)); SQLITE_BIND_FAIL(done, sqlite3_bind_int64(res, ++param, health_log_id)); SQLITE_BIND_FAIL(done, sqlite3_bind_int64(res, ++param, (int64_t) unique_id)); @@ -152,7 +151,7 @@ static int delete_alert_from_submit_queue(RRDHOST *host, int64_t first_seq_id, i return -1; int param = 0; - SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_uuid, sizeof(host->host_uuid), SQLITE_STATIC)); + SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_id.uuid, sizeof(host->host_id.uuid), SQLITE_STATIC)); SQLITE_BIND_FAIL(done, sqlite3_bind_int64(res, ++param, first_seq_id)); SQLITE_BIND_FAIL(done, sqlite3_bind_int64(res, ++param, last_seq_id)); @@ -266,7 +265,7 @@ static void commit_alert_events(RRDHOST *host) return; int param = 0; - SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_uuid, sizeof(host->host_uuid), SQLITE_STATIC)); + SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_id.uuid, sizeof(host->host_id.uuid), SQLITE_STATIC)); int64_t first_sequence_id = 0; int64_t last_sequence_id = 0; @@ -424,27 +423,25 @@ void health_alarm_log_populate( static void aclk_push_alert_event(RRDHOST *host __maybe_unused) { + CLAIM_ID claim_id = claim_id_get(); - char *claim_id = get_agent_claimid(); - if (!claim_id || !host->node_id) + if (!claim_id_is_set(claim_id) || UUIDiszero(host->node_id)) return; sqlite3_stmt *res = NULL; - if (!PREPARE_STATEMENT(db_meta, SQL_SELECT_ALERT_TO_PUSH, &res)) { - freez(claim_id); + if (!PREPARE_STATEMENT(db_meta, SQL_SELECT_ALERT_TO_PUSH, &res)) return; - } int param = 0; - SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_uuid, sizeof(host->host_uuid), SQLITE_STATIC)); + SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_id.uuid, sizeof(host->host_id.uuid), SQLITE_STATIC)); char node_id_str[UUID_STR_LEN]; - uuid_unparse_lower(*host->node_id, node_id_str); + uuid_unparse_lower(host->node_id.uuid, node_id_str); struct alarm_log_entry alarm_log; alarm_log.node_id = node_id_str; - alarm_log.claim_id = claim_id; + alarm_log.claim_id = claim_id.str; int64_t first_id = 0; int64_t last_id = 0; @@ -484,8 +481,6 @@ static void aclk_push_alert_event(RRDHOST *host __maybe_unused) done: REPORT_BIND_FAIL(res, param); SQLITE_FINALIZE(res); - - freez(claim_id); } #define SQL_DELETE_PROCESSED_ROWS "DELETE FROM alert_queue WHERE host_id = @host_id AND rowid = @row" @@ -498,7 +493,7 @@ static void delete_alert_from_pending_queue(RRDHOST *host, int64_t row) return; int param = 0; - SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_uuid, sizeof(host->host_uuid), SQLITE_STATIC)); + SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_id.uuid, sizeof(host->host_id.uuid), SQLITE_STATIC)); SQLITE_BIND_FAIL(done, sqlite3_bind_int64(res, ++param, row)); param = 0; @@ -528,7 +523,7 @@ void rebuild_host_alert_version_table(RRDHOST *host) return; int param = 0; - SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_uuid, sizeof(host->host_uuid), SQLITE_STATIC)); + SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_id.uuid, sizeof(host->host_id.uuid), SQLITE_STATIC)); param = 0; int rc = execute_insert(res); @@ -541,7 +536,7 @@ void rebuild_host_alert_version_table(RRDHOST *host) if (!PREPARE_STATEMENT(db_meta, SQL_REBUILD_HOST_ALERT_VERSION_TABLE, &res)) return; - SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_uuid, sizeof(host->host_uuid), SQLITE_STATIC)); + SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_id.uuid, sizeof(host->host_id.uuid), SQLITE_STATIC)); param = 0; rc = execute_insert(res); @@ -566,7 +561,7 @@ bool process_alert_pending_queue(RRDHOST *host) int param = 0; int added =0, count = 0; - SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_uuid, sizeof(host->host_uuid), SQLITE_STATIC)); + SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_id.uuid, sizeof(host->host_id.uuid), SQLITE_STATIC)); param = 0; while (sqlite3_step_monitored(res) == SQLITE_ROW) { @@ -777,7 +772,7 @@ static uint64_t calculate_node_alert_version(RRDHOST *host) uint64_t version = 0; int param = 0; - SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_uuid, sizeof(host->host_uuid), SQLITE_STATIC)); + SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_id.uuid, sizeof(host->host_id.uuid), SQLITE_STATIC)); param = 0; while (sqlite3_step_monitored(res) == SQLITE_ROW) { @@ -792,6 +787,16 @@ done: static void schedule_alert_snapshot_if_needed(struct aclk_sync_cfg_t *wc, uint64_t cloud_version) { + if (cloud_version == 1) { + nd_log( + NDLS_ACCESS, + NDLP_NOTICE, + "Cloud requested to skip alert version verification for host \"%s\", node \"%s\"", + rrdhost_hostname(wc->host), + wc->node_id); + return; + } + uint64_t local_version = calculate_node_alert_version(wc->host); if (local_version != cloud_version) { nd_log( @@ -899,23 +904,21 @@ void send_alert_snapshot_to_cloud(RRDHOST *host __maybe_unused) return; } - char *claim_id = get_agent_claimid(); - if (unlikely(!claim_id)) + CLAIM_ID claim_id = claim_id_get(); + if (unlikely(!claim_id_is_set(claim_id))) return; - // Check database for this node to see how many alerts we will need to put in the snapshot - int cnt = calculate_alert_snapshot_entries(&host->host_uuid); - if (!cnt) { - freez(claim_id); + // Check the database for this node to see how many alerts we will need to put in the snapshot + int cnt = calculate_alert_snapshot_entries(&host->host_id.uuid); + if (!cnt) return; - } sqlite3_stmt *res = NULL; if (!PREPARE_STATEMENT(db_meta, SQL_GET_SNAPSHOT_ENTRIES, &res)) return; int param = 0; - SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_uuid, sizeof(host->host_uuid), SQLITE_STATIC)); + SQLITE_BIND_FAIL(done, sqlite3_bind_blob(res, ++param, &host->host_id.uuid, sizeof(host->host_id.uuid), SQLITE_STATIC)); nd_uuid_t local_snapshot_uuid; char snapshot_uuid_str[UUID_STR_LEN]; @@ -935,13 +938,13 @@ void send_alert_snapshot_to_cloud(RRDHOST *host __maybe_unused) struct alarm_log_entry alarm_log; alarm_snap.node_id = wc->node_id; - alarm_snap.claim_id = claim_id; + alarm_snap.claim_id = claim_id.str; alarm_snap.snapshot_uuid = snapshot_uuid; alarm_snap.chunks = chunks; alarm_snap.chunk = 1; alarm_log.node_id = wc->node_id; - alarm_log.claim_id = claim_id; + alarm_log.claim_id = claim_id.str; cnt = 0; param = 0; @@ -960,7 +963,7 @@ void send_alert_snapshot_to_cloud(RRDHOST *host __maybe_unused) version += alarm_log.version; if (cnt == ALARM_EVENTS_PER_CHUNK) { - if (aclk_connected) + if (aclk_online_for_alerts()) aclk_send_alarm_snapshot(snapshot_proto); cnt = 0; if (alarm_snap.chunk < chunks) { @@ -986,8 +989,6 @@ void send_alert_snapshot_to_cloud(RRDHOST *host __maybe_unused) done: REPORT_BIND_FAIL(res, param); SQLITE_FINALIZE(res); - - freez(claim_id); } // Start streaming alerts @@ -1021,25 +1022,24 @@ void aclk_alert_version_check(char *node_id, char *claim_id, uint64_t cloud_vers { nd_uuid_t node_uuid; - if (unlikely(!node_id || !claim_id || !claimed() || uuid_parse(node_id, node_uuid))) + if (unlikely(!node_id || !claim_id || !is_agent_claimed() || uuid_parse(node_id, node_uuid))) return; - char *agent_claim_id = get_agent_claimid(); - if (claim_id && agent_claim_id && strcmp(agent_claim_id, claim_id) != 0) { - nd_log(NDLS_ACCESS, NDLP_NOTICE, "ACLK REQ [%s (N/A)]: ALERTS CHECKPOINT VALIDATION REQUEST RECEIVED WITH INVALID CLAIM ID", node_id); - goto done; + CLAIM_ID agent_claim_id = claim_id_get(); + if (claim_id && claim_id_is_set(agent_claim_id) && strcmp(agent_claim_id.str, claim_id) != 0) { + nd_log(NDLS_ACCESS, NDLP_NOTICE, + "ACLK REQ [%s (N/A)]: ALERTS CHECKPOINT VALIDATION REQUEST RECEIVED WITH INVALID CLAIM ID", + node_id); + return; } struct aclk_sync_cfg_t *wc; RRDHOST *host = find_host_by_node_id(node_id); if ((!host || !(wc = host->aclk_config))) - nd_log(NDLS_ACCESS, NDLP_NOTICE, "ACLK REQ [%s (N/A)]: ALERTS CHECKPOINT VALIDATION REQUEST RECEIVED FOR INVALID NODE", node_id); + nd_log(NDLS_ACCESS, NDLP_NOTICE, + "ACLK REQ [%s (N/A)]: ALERTS CHECKPOINT VALIDATION REQUEST RECEIVED FOR INVALID NODE", + node_id); else schedule_alert_snapshot_if_needed(wc, cloud_version); - -done: - freez(agent_claim_id); } - -#endif |