diff options
Diffstat (limited to 'database/sqlite')
-rw-r--r-- | database/sqlite/sqlite3.c | 2 | ||||
-rw-r--r-- | database/sqlite/sqlite_aclk.c | 18 | ||||
-rw-r--r-- | database/sqlite/sqlite_aclk.h | 1 | ||||
-rw-r--r-- | database/sqlite/sqlite_aclk_alert.c | 30 | ||||
-rw-r--r-- | database/sqlite/sqlite_aclk_chart.c | 8 | ||||
-rw-r--r-- | database/sqlite/sqlite_aclk_node.c | 4 |
6 files changed, 56 insertions, 7 deletions
diff --git a/database/sqlite/sqlite3.c b/database/sqlite/sqlite3.c index 057ce52d8..61a74f059 100644 --- a/database/sqlite/sqlite3.c +++ b/database/sqlite/sqlite3.c @@ -124427,7 +124427,7 @@ insert_cleanup: /* This is the Walker callback from sqlite3ExprReferencesUpdatedColumn(). * Set bit 0x01 of pWalker->eCode if pWalker->eCode to 0 and if this ** expression node references any of the -** columns that are being modifed by an UPDATE statement. +** columns that are being modified by an UPDATE statement. */ static int checkConstraintExprNode(Walker *pWalker, Expr *pExpr){ if( pExpr->op==TK_COLUMN ){ diff --git a/database/sqlite/sqlite_aclk.c b/database/sqlite/sqlite_aclk.c index 6803092f2..63196a81e 100644 --- a/database/sqlite/sqlite_aclk.c +++ b/database/sqlite/sqlite_aclk.c @@ -189,6 +189,24 @@ int aclk_worker_enq_cmd(char *node_id, struct aclk_database_cmd *cmd) return (wc == NULL); } +struct aclk_database_worker_config *find_inactive_wc_by_node_id(char *node_id) +{ + if (unlikely(!node_id)) + return NULL; + + uv_mutex_lock(&aclk_async_lock); + struct aclk_database_worker_config *wc = aclk_thread_head; + + while (wc) { + if (!strcmp(wc->node_id, node_id)) + break; + wc = wc->next; + } + uv_mutex_unlock(&aclk_async_lock); + + return (wc); +} + void aclk_sync_exit_all() { rrd_wrlock(); diff --git a/database/sqlite/sqlite_aclk.h b/database/sqlite/sqlite_aclk.h index d554e1069..424949740 100644 --- a/database/sqlite/sqlite_aclk.h +++ b/database/sqlite/sqlite_aclk.h @@ -229,4 +229,5 @@ void sql_delete_aclk_table_list(struct aclk_database_worker_config *wc, struct a void sql_maint_aclk_sync_database(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd); int claimed(); void aclk_sync_exit_all(); +struct aclk_database_worker_config *find_inactive_wc_by_node_id(char *node_id); #endif //NETDATA_SQLITE_ACLK_H diff --git a/database/sqlite/sqlite_aclk_alert.c b/database/sqlite/sqlite_aclk_alert.c index 8d7694244..238b500a8 100644 --- a/database/sqlite/sqlite_aclk_alert.c +++ b/database/sqlite/sqlite_aclk_alert.c @@ -209,7 +209,7 @@ void aclk_push_alert_event(struct aclk_database_worker_config *wc, struct aclk_d char *edit_command = sqlite3_column_bytes(res, 16) > 0 ? health_edit_command_from_source((char *)sqlite3_column_text(res, 16)) : - strdupz("UNKNOWN=0"); + strdupz("UNKNOWN=0=UNKNOWN"); alarm_log.command = strdupz(edit_command); alarm_log.duration = (time_t) sqlite3_column_int64(res, 6); @@ -321,6 +321,22 @@ void aclk_push_alarm_health_log(struct aclk_database_worker_config *wc, struct a if (unlikely(!claim_id)) return; + RRDHOST *host = wc->host; + if (unlikely(!host)) { + rrd_wrlock(); + host = find_host_by_node_id(wc->node_id); + rrd_unlock(); + + if (unlikely(!host)) { + log_access( + "AC [%s (N/A)]: ACLK synchronization thread for %s is not yet linked to HOST.", + wc->node_id, + wc->host_guid); + freez(claim_id); + return; + } + } + uint64_t first_sequence = 0; uint64_t last_sequence = 0; struct timeval first_timestamp; @@ -370,7 +386,7 @@ void aclk_push_alarm_health_log(struct aclk_database_worker_config *wc, struct a alarm_log.node_id = wc->node_id; alarm_log.log_entries = log_entries; alarm_log.status = wc->alert_updates == 0 ? 2 : 1; - alarm_log.enabled = 1; + alarm_log.enabled = (int)host->health_enabled; wc->alert_sequence_id = last_sequence; @@ -546,7 +562,9 @@ void aclk_start_alert_streaming(char *node_id, uint64_t batch_id, uint64_t start rrd_wrlock(); RRDHOST *host = find_host_by_node_id(node_id); if (likely(host)) - wc = (struct aclk_database_worker_config *)host->dbsync_worker; + wc = (struct aclk_database_worker_config *)host->dbsync_worker ? + (struct aclk_database_worker_config *)host->dbsync_worker : + (struct aclk_database_worker_config *)find_inactive_wc_by_node_id(node_id); rrd_unlock(); if (unlikely(!host->health_enabled)) { @@ -589,6 +607,8 @@ void sql_process_queue_removed_alerts_to_aclk(struct aclk_database_worker_config db_execute(buffer_tostring(sql)); + log_access("AC [%s (%s)]: Queued removed alerts.", wc->node_id, wc->host ? wc->host->hostname : "N/A"); + buffer_free(sql); #endif return; @@ -677,7 +697,7 @@ void aclk_mark_alert_cloud_ack(char *uuid_str, uint64_t alerts_ack_sequence_id) #ifdef ENABLE_NEW_CLOUD_PROTOCOL void health_alarm_entry2proto_nolock(struct alarm_log_entry *alarm_log, ALARM_ENTRY *ae, RRDHOST *host) { - char *edit_command = ae->source ? health_edit_command_from_source(ae->source) : strdupz("UNKNOWN=0"); + char *edit_command = ae->source ? health_edit_command_from_source(ae->source) : strdupz("UNKNOWN=0=UNKNOWN"); char config_hash_id[GUID_LEN + 1]; uuid_unparse_lower(ae->config_hash_id, config_hash_id); @@ -724,6 +744,7 @@ void health_alarm_entry2proto_nolock(struct alarm_log_entry *alarm_log, ALARM_EN } #endif +#ifdef ENABLE_NEW_CLOUD_PROTOCOL static int have_recent_alarm(RRDHOST *host, uint32_t alarm_id, time_t mark) { ALARM_ENTRY *ae = host->health_log.alarms; @@ -737,6 +758,7 @@ static int have_recent_alarm(RRDHOST *host, uint32_t alarm_id, time_t mark) return 0; } +#endif #define ALARM_EVENTS_PER_CHUNK 10 void aclk_push_alert_snapshot_event(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd) diff --git a/database/sqlite/sqlite_aclk_chart.c b/database/sqlite/sqlite_aclk_chart.c index 4b887abaa..eea48a567 100644 --- a/database/sqlite/sqlite_aclk_chart.c +++ b/database/sqlite/sqlite_aclk_chart.c @@ -318,7 +318,7 @@ void aclk_send_chart_event(struct aclk_database_worker_config *wc, struct aclk_d uint64_t first_sequence; uint64_t last_sequence; - time_t last_timestamp; + time_t last_timestamp = 0; BUFFER *sql = buffer_create(1024); @@ -682,7 +682,9 @@ void aclk_start_streaming(char *node_id, uint64_t sequence_id, time_t created_at while(host) { if (host->node_id && !(uuid_compare(*host->node_id, node_uuid))) { rrd_unlock(); - wc = (struct aclk_database_worker_config *)host->dbsync_worker; + wc = (struct aclk_database_worker_config *)host->dbsync_worker ? + (struct aclk_database_worker_config *)host->dbsync_worker : + (struct aclk_database_worker_config *)find_inactive_wc_by_node_id(node_id); if (likely(wc)) { wc->chart_reset_count++; __sync_synchronize(); @@ -979,6 +981,8 @@ int queue_chart_to_aclk(RRDSET *st) #ifndef ENABLE_NEW_CLOUD_PROTOCOL #ifdef ENABLE_ACLK aclk_update_chart(st->rrdhost, st->id, 1); +#else + UNUSED(st); #endif return 0; #else diff --git a/database/sqlite/sqlite_aclk_node.c b/database/sqlite/sqlite_aclk_node.c index ba498c2a7..6261b9af5 100644 --- a/database/sqlite/sqlite_aclk_node.c +++ b/database/sqlite/sqlite_aclk_node.c @@ -22,6 +22,8 @@ void sql_build_node_info(struct aclk_database_worker_config *wc, struct aclk_dat node_info.claim_id = is_agent_claimed(); node_info.machine_guid = wc->host_guid; node_info.child = (wc->host != localhost); + node_info.ml_info.ml_capable = localhost->system_info->ml_capable; + node_info.ml_info.ml_enabled = wc->host->ml_host != NULL; now_realtime_timeval(&node_info.updated_at); RRDHOST *host = wc->host; @@ -46,6 +48,8 @@ void sql_build_node_info(struct aclk_database_worker_config *wc, struct aclk_dat node_info.data.services = NULL; // char ** node_info.data.service_count = 0; node_info.data.machine_guid = wc->host_guid; + node_info.data.ml_info.ml_capable = host->system_info->ml_capable; + node_info.data.ml_info.ml_enabled = host->system_info->ml_enabled; struct label_index *labels = &host->labels; netdata_rwlock_wrlock(&labels->labels_rwlock); |