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)
Stelios Fragkakis committed
Mar 23, 2023 at 10:23 UTC
c46b8e9fcc614ce08415b00ad4ba617e40b1443e
8 files changed
+31
-20
aclk/aclk.c
+4
-4
@@ -1221,9 +1221,9 @@ void add_aclk_host_labels(void) {
1221
#endif
1222
}
1223
1224
-void aclk_queue_node_info(RRDHOST *host) {
1224
+void aclk_queue_node_info(RRDHOST *host, bool immediate)
1225
+{
1226
struct aclk_sync_host_config *wc = (struct aclk_sync_host_config *) host->aclk_sync_host_config;
1226
- if (likely(wc)) {
1227
- wc->node_info_send = 1;
1228
- }
1227
+ if (likely(wc))
1228
+ wc->node_info_send_time = (host == localhost || immediate) ? 1 : now_realtime_sec();
1229
}
aclk/aclk.h
+1
-1
@@ -54,6 +54,6 @@ void aclk_send_bin_msg(char *msg, size_t msg_len, enum aclk_topics subtopic, con
54
char *aclk_state(void);
55
char *aclk_state_json(void);
56
void add_aclk_host_labels(void);
57
-void aclk_queue_node_info(RRDHOST *host);
57
+void aclk_queue_node_info(RRDHOST *host, bool immediate);
58
59
#endif /* ACLK_H */
database/rrdhost.c
+1
-1
@@ -1348,7 +1348,7 @@ void rrdhost_set_is_parent_label(int count) {
1348
//queue a node info
1349
#ifdef ENABLE_ACLK
1350
if (netdata_cloud_setting) {
1351
- aclk_queue_node_info(localhost);
1351
+ aclk_queue_node_info(localhost, false);
1352
}
1353
#endif
1354
}
database/sqlite/sqlite_aclk.c
+12
-3
@@ -90,7 +90,7 @@ enum {
90
91
static int create_host_callback(void *data, int argc, char **argv, char **column)
92
{
93
- UNUSED(data);
93
+ int *number_of_chidren = data;
94
UNUSED(argc);
95
UNUSED(column);
96
@@ -132,6 +132,8 @@ static int create_host_callback(void *data, int argc, char **argv, char **column
132
if (likely(host))
133
host->rrdlabels = sql_load_host_labels((uuid_t *)argv[IDX_HOST_ID]);
134
135
+ (*number_of_chidren)++;
136
+
137
#ifdef NETDATA_INTERNAL_CHECKS
138
char node_str[UUID_STR_LEN] = "<none>";
139
if (likely(host->node_id))
@@ -520,7 +522,8 @@ void sql_create_aclk_table(RRDHOST *host __maybe_unused, uuid_t *host_uuid __may
522
wc->host = host;
523
strcpy(wc->uuid_str, uuid_str);
524
wc->alert_updates = 0;
523
- wc->node_info_send = 1;
525
+ time_t now = now_realtime_sec();
526
+ wc->node_info_send_time = (host == localhost || NULL == localhost) ? now - 25 : now;
527
#endif
528
}
529
@@ -544,16 +547,22 @@ void sql_aclk_sync_init(void)
547
}
548
549
info("Creating archived hosts");
547
- rc = sqlite3_exec_monitored(db_meta, SQL_FETCH_ALL_HOSTS, create_host_callback, NULL, &err_msg);
550
+ int number_of_children = 0;
551
+ rc = sqlite3_exec_monitored(db_meta, SQL_FETCH_ALL_HOSTS, create_host_callback, &number_of_children, &err_msg);
552
553
if (rc != SQLITE_OK) {
554
error_report("SQLite error when loading archived hosts, rc = %d (%s)", rc, err_msg);
555
sqlite3_free(err_msg);
556
}
557
+
558
+ info("Created %d archived hosts", number_of_children);
559
// Trigger host context load for hosts that have been created
560
metadata_queue_load_host_context(NULL);
561
562
#ifdef ENABLE_ACLK
563
+ if (!number_of_children)
564
+ aclk_queue_node_info(localhost, true);
565
+
566
rc = sqlite3_exec_monitored(db_meta, SQL_FETCH_ALL_INSTANCES,aclk_config_parameters, NULL,&err_msg);
567
568
if (rc != SQLITE_OK) {
database/sqlite/sqlite_aclk.h
+1
-1
@@ -72,7 +72,7 @@ struct aclk_database_cmdqueue {
72
struct aclk_sync_host_config {
73
RRDHOST *host;
74
int alert_updates;
75
- int node_info_send;
75
+ time_t node_info_send_time;
76
time_t node_collectors_send;
77
char uuid_str[UUID_STR_LEN];
78
char node_id[UUID_STR_LEN];
database/sqlite/sqlite_aclk_node.c
+6
-9
@@ -73,8 +73,6 @@ static void build_node_info(char *node_id __maybe_unused)
73
return;
74
}
75
76
- wc->node_info_send = 1;
77
-
76
rrd_rdlock();
77
node_info.node_id = wc->node_id;
78
node_info.claim_id = get_agent_claimid();
@@ -148,20 +146,19 @@ void aclk_check_node_info_and_collectors(void)
146
147
dfe_start_reentrant(rrdhost_root_index, host) {
148
149
+ struct aclk_sync_host_config *wc = host->aclk_sync_host_config;
150
+ if (unlikely(!wc))
151
+ continue;
152
+
153
if (unlikely(rrdhost_flag_check(host, RRDHOST_FLAG_PENDING_CONTEXT_LOAD))) {
154
info("ACLK: 'host:%s' not sending node info, context load is pending", rrdhost_hostname(host));
155
continue;
156
}
157
156
- struct aclk_sync_host_config *wc = host->aclk_sync_host_config;
157
-
158
- if (unlikely(!wc))
159
- continue;
160
-
161
- if (wc->node_info_send) {
158
+ if (wc->node_info_send_time && wc->node_info_send_time + 30 < now_realtime_sec()) {
159
+ wc->node_info_send_time = 0;
160
build_node_info(strdupz(wc->node_id));
161
internal_error(true, "ACLK SYNC: Sending node info for %s", rrdhost_hostname(host));
164
- wc->node_info_send = 0;
162
}
163
164
if (wc->node_collectors_send && wc->node_collectors_send + 30 < now_realtime_sec()) {
database/sqlite/sqlite_metadata.c
+4
@@ -892,6 +892,10 @@ static void restore_host_context(void *arg)
892
893
rrdhost_flag_clear(host, RRDHOST_FLAG_PENDING_CONTEXT_LOAD | RRDHOST_FLAG_CONTEXT_LOAD_IN_PROGRESS);
894
895
+#ifdef ENABLE_ACLK
896
+ aclk_queue_node_info(host, false);
897
+#endif
898
+
899
internal_error(true, "METADATA: 'host:%s' context load in %0.2f ms", rrdhost_hostname(host),
900
(double)(ended_ut - started_ut) / USEC_PER_MS);
901
streaming/receiver.c
+2
-1
@@ -437,7 +437,7 @@ static void rrdpush_receiver_replication_reset(RRDHOST *host) {
437
rrdhost_receiver_replicating_charts_zero(host);
438
}
439
440
-bool rrdhost_set_receiver(RRDHOST *host, struct receiver_state *rpt) {
440
+static bool rrdhost_set_receiver(RRDHOST *host, struct receiver_state *rpt) {
441
bool signal_rrdcontext = false;
442
bool set_this = false;
443
@@ -472,6 +472,7 @@ bool rrdhost_set_receiver(RRDHOST *host, struct receiver_state *rpt) {
472
rrdpush_receiver_replication_reset(host);
473
474
rrdhost_flag_clear(rpt->host, RRDHOST_FLAG_RRDPUSH_RECEIVER_DISCONNECTED);
475
+ aclk_queue_node_info(rpt->host, true);
476
477
set_this = true;
478
}