Cancel health initialization if shutdown has been requested (#20318)
* Check service status during health initialization to determine if shutdown has been requested * Formatting * Fix some formatting Prevent a uv worker from registering as health service when netdatacli reload-health is executed
Stelios Fragkakis committed
May 21, 2025 at 18:21 UTC
6459420287588e5a92e3a72e5c15f694e806b3d1
4 files changed
+20
-4
src/daemon/libuv_workers.c
+1
-1
@@ -165,7 +165,7 @@ void init_cmd_pool(CmdPool *pool, int size) {
165
166
uv_mutex_init(&pool->lock);
167
uv_cond_init(&pool->not_full);
168
-;}
168
+}
169
170
bool push_cmd(CmdPool *pool, const cmd_data_t *cmd, bool wait_on_full)
171
{
src/database/sqlite/sqlite_aclk.c
+2
-2
@@ -326,7 +326,7 @@ static void aclk_run_query(struct aclk_sync_config_s *config, aclk_query_t *quer
326
http_api_v2(client, query);
327
ok_to_send = false;
328
break;
329
- case CTX_CHECKPOINT:;
329
+ case CTX_CHECKPOINT:
330
worker_is_busy(UV_EVENT_CTX_CHECKPOINT);
331
rrdcontext_hub_checkpoint_command(query->data.payload);
332
ok_to_send = false;
@@ -639,7 +639,7 @@ static void *aclk_synchronization_event_loop(void *arg)
639
640
sql_delete_aclk_table_list();
641
642
- int query_thread_count = netdata_conf_cloud_query_threads();
642
+ int query_thread_count = (int) netdata_conf_cloud_query_threads();
643
netdata_log_info("Starting ACLK synchronization thread with %d parallel query threads", query_thread_count);
644
645
//struct worker_data *worker_datadata;
src/health/health_event_loop.c
+11
-1
@@ -133,11 +133,17 @@ static void health_execute_delayed_initializations(RRDHOST *host) {
133
rrdhost_flag_clear(host, RRDHOST_FLAG_PENDING_HEALTH_INITIALIZATION);
134
135
rrdset_foreach_reentrant(st, host) {
136
- if(!rrdset_flag_check(st, RRDSET_FLAG_PENDING_HEALTH_INITIALIZATION)) continue;
136
+ if (!rrdset_flag_check(st, RRDSET_FLAG_PENDING_HEALTH_INITIALIZATION))
137
+ continue;
138
+
139
rrdset_flag_clear(st, RRDSET_FLAG_PENDING_HEALTH_INITIALIZATION);
140
141
worker_is_busy(WORKER_HEALTH_JOB_DELAYED_INIT_RRDSET);
142
+
143
health_prototype_alerts_for_rrdset_incrementally(st);
144
+
145
+ if (!service_running(SERVICE_HEALTH))
146
+ break;
147
}
148
rrdset_foreach_done(st);
149
}
@@ -163,6 +169,10 @@ static void health_initialize_rrdhost(RRDHOST *host) {
169
rw_spinlock_init(&host->health_log.spinlock);
170
rrdhost_flag_set(host, RRDHOST_FLAG_INITIALIZED_HEALTH);
171
172
+
173
+ if (!service_running(SERVICE_HEALTH))
174
+ return;
175
+
176
health_apply_prototypes_to_host(host);
177
}
178
src/health/health_prototypes.c
+6
@@ -617,9 +617,13 @@ static void health_prototype_apply_to_rrdset(RRDSET *st, RRD_ALERT_PROTOTYPE *ap
617
rw_spinlock_read_unlock(&ap->_internal.rw_spinlock);
618
}
619
620
+extern __thread bool is_health_thread;
621
+
622
void health_prototype_alerts_for_rrdset_incrementally(RRDSET *st) {
623
RRD_ALERT_PROTOTYPE *ap;
624
dfe_start_read(health_globals.prototypes.dict, ap) {
625
+ if (is_health_thread && !service_running(SERVICE_HEALTH))
626
+ break;
627
health_prototype_apply_to_rrdset(st, ap);
628
}
629
dfe_done(ap);
@@ -689,6 +693,8 @@ void health_apply_prototypes_to_host(RRDHOST *host) {
693
// apply all the prototypes for the charts of the host
694
RRDSET *st;
695
rrdset_foreach_reentrant(st, host) {
696
+ if (is_health_thread && !service_running(SERVICE_HEALTH))
697
+ break;
698
health_prototype_reset_alerts_for_rrdset(st);
699
}
700
rrdset_foreach_done(st);