diff options
author | Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> | 2023-03-23 10:23:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-23 10:23:19 +0200 |
commit | c46b8e9fcc614ce08415b00ad4ba617e40b1443e (patch) | |
tree | 872523bdac6daefd5f5082c4a160e577d762a921 /database/sqlite/sqlite_aclk.c | |
parent | 62d63229b55f71c4db0eaae73819c203c490c061 (diff) |
Schedule node info to the cloud after child connection (#14790)
* Schedule node info to the cloud after child connection
* Remove debug code
* Schedule localhost node info within 5 seconds of startup. If no children are detected Or a child connects (switch to immediate localhost node info update)
Diffstat (limited to 'database/sqlite/sqlite_aclk.c')
-rw-r--r-- | database/sqlite/sqlite_aclk.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/database/sqlite/sqlite_aclk.c b/database/sqlite/sqlite_aclk.c index ae6f24e31d..060f29be88 100644 --- a/database/sqlite/sqlite_aclk.c +++ b/database/sqlite/sqlite_aclk.c @@ -90,7 +90,7 @@ enum { static int create_host_callback(void *data, int argc, char **argv, char **column) { - UNUSED(data); + int *number_of_chidren = data; UNUSED(argc); UNUSED(column); @@ -132,6 +132,8 @@ static int create_host_callback(void *data, int argc, char **argv, char **column if (likely(host)) host->rrdlabels = sql_load_host_labels((uuid_t *)argv[IDX_HOST_ID]); + (*number_of_chidren)++; + #ifdef NETDATA_INTERNAL_CHECKS char node_str[UUID_STR_LEN] = "<none>"; if (likely(host->node_id)) @@ -520,7 +522,8 @@ void sql_create_aclk_table(RRDHOST *host __maybe_unused, uuid_t *host_uuid __may wc->host = host; strcpy(wc->uuid_str, uuid_str); wc->alert_updates = 0; - wc->node_info_send = 1; + time_t now = now_realtime_sec(); + wc->node_info_send_time = (host == localhost || NULL == localhost) ? now - 25 : now; #endif } @@ -544,16 +547,22 @@ void sql_aclk_sync_init(void) } info("Creating archived hosts"); - rc = sqlite3_exec_monitored(db_meta, SQL_FETCH_ALL_HOSTS, create_host_callback, NULL, &err_msg); + int number_of_children = 0; + rc = sqlite3_exec_monitored(db_meta, SQL_FETCH_ALL_HOSTS, create_host_callback, &number_of_children, &err_msg); if (rc != SQLITE_OK) { error_report("SQLite error when loading archived hosts, rc = %d (%s)", rc, err_msg); sqlite3_free(err_msg); } + + info("Created %d archived hosts", number_of_children); // Trigger host context load for hosts that have been created metadata_queue_load_host_context(NULL); #ifdef ENABLE_ACLK + if (!number_of_children) + aclk_queue_node_info(localhost, true); + rc = sqlite3_exec_monitored(db_meta, SQL_FETCH_ALL_INSTANCES,aclk_config_parameters, NULL,&err_msg); if (rc != SQLITE_OK) { |