From a26bc5d7b6e6204509bd680795d09514f08ba685 Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Tue, 10 Oct 2023 10:50:31 -0700 Subject: [PATCH] Refactored TransportGetRemoteIndexesAction to be more efficient. Signed-off-by: AWSHurneyt --- .../TransportGetRemoteIndexesAction.kt | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetRemoteIndexesAction.kt b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetRemoteIndexesAction.kt index 7dac2e7b9..57e8ec028 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetRemoteIndexesAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetRemoteIndexesAction.kt @@ -59,24 +59,25 @@ class TransportGetRemoteIndexesAction @Inject constructor( ) { log.info("hurneyt TransportGetRemoteIndexesAction START") client.threadPool().threadContext.stashContext().use { - scope.launch { - val clusterIndexesList = mutableListOf() + val clusterIndexesList = mutableListOf() - var resolveIndexResponse: ResolveIndexAction.Response? = null + var resolveIndexResponse: ResolveIndexAction.Response? = null + scope.launch { try { resolveIndexResponse = getRemoteClusters(request.indexes) } catch (e: Exception) { log.error("Failed to retrieve indexes for request $request", e) listener.onFailure(AlertingException.wrap(e)) } + } - val resolvedIndexes = resolveIndexResponse?.indices?.map { it.name } ?: emptyList() - log.info("hurneyt TransportGetRemoteIndexesAction::resolvedIndexes = {}", resolvedIndexes) - - val clusterIndexesMap = CrossClusterMonitorUtils.separateClusterIndexes(resolvedIndexes, clusterService) - log.info("hurneyt TransportGetRemoteIndexesAction::clusterIndexesMap = {}", clusterIndexesMap) + val resolvedIndexes = resolveIndexResponse?.indices?.map { it.name } ?: emptyList() + log.info("hurneyt TransportGetRemoteIndexesAction::resolvedIndexes = {}", resolvedIndexes) - clusterIndexesMap.forEach { (clusterName, indexes) -> + val clusterIndexesMap = CrossClusterMonitorUtils.separateClusterIndexes(resolvedIndexes, clusterService) + log.info("hurneyt TransportGetRemoteIndexesAction::clusterIndexesMap = {}", clusterIndexesMap) + clusterIndexesMap.forEach { (clusterName, indexes) -> + scope.launch { log.info("hurneyt TransportGetRemoteIndexesAction::clusterIndexesMap clusterName = {}", clusterName) log.info("hurneyt TransportGetRemoteIndexesAction::clusterIndexesMap indexes = {}", indexes) val targetClient = CrossClusterMonitorUtils.getClientForCluster(clusterName, client, clusterService) @@ -126,9 +127,9 @@ class TransportGetRemoteIndexesAction @Inject constructor( ) ) } - log.info("hurneyt TransportGetRemoteIndexesAction END") - listener.onResponse(GetRemoteIndexesResponse(clusterIndexes = clusterIndexesList)) } + log.info("hurneyt TransportGetRemoteIndexesAction END") + listener.onResponse(GetRemoteIndexesResponse(clusterIndexes = clusterIndexesList)) } } @@ -138,6 +139,7 @@ class TransportGetRemoteIndexesAction @Inject constructor( ResolveIndexAction.Request.DEFAULT_INDICES_OPTIONS ) return client.suspendUntil { + // TODO hurneyt: return aliases as well admin().indices().resolveIndex(resolveRequest, it) } }