Improve ml thread termination during agent shutdown (#17889)
* Signal ML to terminate first without waiting for the threads to terminate Add additional check if we need to stop within the per host ML processing * Check for SERVICE_COLLECTORS running for the PREDICTION thread * Function void param * Function void param
Stelios Fragkakis committed
Jun 14, 2024 at 18:49 UTC
7450f4d7a121a7243ae5e3b4534a73b556eba2ed
1 file changed
+5
-1
src/ml/ml.cc
+5
-1
@@ -1220,7 +1220,7 @@ ml_detect_main(void *arg)
1220
heartbeat_t hb;
1221
heartbeat_init(&hb);
1222
1223
- while (!Cfg.detection_stop) {
1223
+ while (!Cfg.detection_stop && service_running(SERVICE_COLLECTORS)) {
1224
worker_is_idle();
1225
heartbeat_next(&hb, USEC_PER_SEC);
1226
@@ -1230,6 +1230,9 @@ ml_detect_main(void *arg)
1230
if (!rh->ml_host)
1231
continue;
1232
1233
+ if (!service_running(SERVICE_COLLECTORS))
1234
+ break;
1235
+
1236
ml_host_detect_once((ml_host_t *) rh->ml_host);
1237
}
1238
rrd_rdunlock();
@@ -1266,6 +1269,7 @@ ml_detect_main(void *arg)
1269
}
1270
}
1271
}
1272
+ Cfg.training_stop = true;
1273
1274
return NULL;
1275
}