Skip to content

Commit

Permalink
add method to stop traking index execution
Browse files Browse the repository at this point in the history
  • Loading branch information
piergm committed Feb 11, 2025
1 parent 2ce21d8 commit 28c9677
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

package org.elasticsearch.common.util.concurrent;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.ExponentiallyWeightedMovingAverage;
import org.elasticsearch.core.Tuple;

Expand All @@ -25,6 +27,7 @@
* This executor provides detailed metrics on task execution times per index, which can be useful for performance monitoring and debugging.
*/
public class TaskExecutionTimeTrackingPerIndexEsThreadPoolExecutor extends TaskExecutionTimeTrackingEsThreadPoolExecutor {
private static final Logger logger = LogManager.getLogger(TaskExecutionTimeTrackingPerIndexEsThreadPoolExecutor.class);
private final ConcurrentHashMap<String, Tuple<LongAdder, ExponentiallyWeightedMovingAverage>> indexExecutionTime;
private final ConcurrentHashMap<Runnable, String> runnableToIndexName;

Expand Down Expand Up @@ -90,6 +93,14 @@ public void registerIndexNameForRunnable(String indexName, Runnable r) {
runnableToIndexName.put(r, indexName);
}

public void stopTrackingIndex(String indexName) {
try {
indexExecutionTime.remove(indexName);
} catch (NullPointerException e) {
logger.debug("Trying to stop tracking index [{}] that was never tracked", indexName);
}
}

@Override
protected void trackExecutionTime(Runnable r, long taskTime) {
try {
Expand Down

0 comments on commit 28c9677

Please sign in to comment.