File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
server/src/main/java/org/elasticsearch/health/node
x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/datafeed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -262,7 +262,7 @@ private Monitoring(
262262 * Schedule the first run of the monitor.
263263 */
264264 public void start () {
265- scheduledRun = threadPool . schedule ( this , TimeValue .ZERO , executor );
265+ scheduleNextRun ( TimeValue .ZERO );
266266 }
267267
268268 /**
@@ -383,8 +383,14 @@ private void scheduleNextRunIfNecessary() {
383383 if (cancelled ) {
384384 return ;
385385 }
386- try {
387- scheduledRun = threadPool .schedule (this , interval , executor );
386+ scheduleNextRun (interval );
387+ }
388+
389+ private void scheduleNextRun (TimeValue delay ) {
390+ // Prevent the propagation of the trace context here to not create everlasting APM transactions.
391+ // Such a trace context is created when executing a transport action.
392+ try (var ignored = threadPool .getThreadContext ().newEmptySystemContext ()) {
393+ scheduledRun = threadPool .schedule (this , delay , executor );
388394 } catch (final EsRejectedExecutionException e ) {
389395 logger .debug (() -> format ("Scheduled health monitoring was rejected on thread pool [%s]" , executor ), e );
390396 }
Original file line number Diff line number Diff line change @@ -338,7 +338,11 @@ protected void doRun() {
338338 }
339339 holder .problemTracker .finishReport ();
340340 if (nextDelayInMsSinceEpoch >= 0 ) {
341- doDatafeedRealtime (nextDelayInMsSinceEpoch , jobId , holder );
341+ // Prevent the propagation of the trace context here to not create everlasting APM transactions.
342+ // Such a trace context is created when executing any transport action.
343+ try (var ignored = threadPool .getThreadContext ().clearTraceContext ()) {
344+ doDatafeedRealtime (nextDelayInMsSinceEpoch , jobId , holder );
345+ }
342346 }
343347 }
344348 }, delay , threadPool .executor (MachineLearning .DATAFEED_THREAD_POOL_NAME ));
You can’t perform that action at this time.
0 commit comments