|
41 | 41 | import org.elasticsearch.cluster.coordination.CoordinationDiagnosticsService; |
42 | 42 | import org.elasticsearch.cluster.coordination.Coordinator; |
43 | 43 | import org.elasticsearch.cluster.coordination.MasterHistoryService; |
| 44 | +import org.elasticsearch.cluster.coordination.SearchIndexTimeTrackingCleanupService; |
44 | 45 | import org.elasticsearch.cluster.coordination.StableMasterHealthIndicatorService; |
45 | 46 | import org.elasticsearch.cluster.metadata.DataStreamFailureStoreSettings; |
46 | 47 | import org.elasticsearch.cluster.metadata.DataStreamGlobalRetentionSettings; |
|
79 | 80 | import org.elasticsearch.common.settings.SettingsModule; |
80 | 81 | import org.elasticsearch.common.util.BigArrays; |
81 | 82 | import org.elasticsearch.common.util.PageCacheRecycler; |
| 83 | +import org.elasticsearch.common.util.concurrent.TaskExecutionTimeTrackingEsThreadPoolExecutor; |
| 84 | +import org.elasticsearch.common.util.concurrent.TaskExecutionTimeTrackingPerIndexEsThreadPoolExecutor; |
82 | 85 | import org.elasticsearch.common.util.set.Sets; |
83 | 86 | import org.elasticsearch.core.IOUtils; |
84 | 87 | import org.elasticsearch.core.SuppressForbidden; |
|
235 | 238 | import java.util.Objects; |
236 | 239 | import java.util.Optional; |
237 | 240 | import java.util.Set; |
| 241 | +import java.util.Timer; |
| 242 | +import java.util.TimerTask; |
238 | 243 | import java.util.concurrent.TimeUnit; |
239 | 244 | import java.util.function.Function; |
240 | 245 | import java.util.function.UnaryOperator; |
@@ -700,6 +705,12 @@ private void construct( |
700 | 705 | ClusterService clusterService = createClusterService(settingsModule, threadPool, taskManager); |
701 | 706 | clusterService.addStateApplier(scriptService); |
702 | 707 |
|
| 708 | + // TODO DR - this is a bit of a hack to get the cluster service into the plugins |
| 709 | + var executor = (TaskExecutionTimeTrackingEsThreadPoolExecutor) threadPool.executor(ThreadPool.Names.SEARCH); |
| 710 | + TaskExecutionTimeTrackingPerIndexEsThreadPoolExecutor perIndexEsThreadPoolExecutor = (TaskExecutionTimeTrackingPerIndexEsThreadPoolExecutor) executor; |
| 711 | + searchLoadMetricsReporter(perIndexEsThreadPoolExecutor); |
| 712 | + clusterService.addListener(new SearchIndexTimeTrackingCleanupService(perIndexEsThreadPoolExecutor)); |
| 713 | + |
703 | 714 | modules.bindToInstance(DocumentParsingProvider.class, documentParsingProvider); |
704 | 715 |
|
705 | 716 | FailureStoreMetrics failureStoreMetrics = new FailureStoreMetrics(telemetryProvider.getMeterRegistry()); |
@@ -1253,6 +1264,26 @@ public Map<String, String> searchFields() { |
1253 | 1264 | postInjection(clusterModule, actionModule, clusterService, transportService, featureService); |
1254 | 1265 | } |
1255 | 1266 |
|
| 1267 | + private void searchLoadMetricsReporter(TaskExecutionTimeTrackingPerIndexEsThreadPoolExecutor executor) { |
| 1268 | + Timer timer = new Timer(); |
| 1269 | + TimerTask task = new TimerTask() { |
| 1270 | + @Override |
| 1271 | + public void run() { |
| 1272 | + if(executor.indexExecutionTime.size() > 0) { |
| 1273 | + logger.info("Number of reported indices: {}", executor.indexExecutionTime.size()); |
| 1274 | + logger.info("Number of runnables: {}", executor.runnableToIndexName.size()); |
| 1275 | + executor.indexExecutionTime.forEach((index, tuple) -> { |
| 1276 | + logger.info("Index: {}, Total execution time: {}, EWMA: {}", index, tuple.v1().sum(), tuple.v2().getAverage()); |
| 1277 | + }); |
| 1278 | + logger.info("Total task execution time: {}", executor.getTotalTaskExecutionTime()); |
| 1279 | + logger.info("----------------------------------------------------------------------------------"); |
| 1280 | + } |
| 1281 | + } |
| 1282 | + }; |
| 1283 | + |
| 1284 | + timer.scheduleAtFixedRate(task, 0, 4000); |
| 1285 | + } |
| 1286 | + |
1256 | 1287 | /** |
1257 | 1288 | * For each "component" (getter) <em>c</em> of a {@link Record}, |
1258 | 1289 | * calls {@link org.elasticsearch.injection.Injector#addInstance(Object) Injector.addInstance} |
|
0 commit comments