forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize TransportNodesAction to not send DiscoveryNodes for NodeStat…
…s, NodesInfo and ClusterStats call Signed-off-by: Pranshu Shukla <[email protected]>
- Loading branch information
Showing
13 changed files
with
421 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...r/src/test/java/org/opensearch/action/support/nodes/TransportClusterStatsActionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action.support.nodes; | ||
|
||
import org.opensearch.action.admin.cluster.node.info.NodesInfoRequest; | ||
import org.opensearch.action.admin.cluster.node.info.TransportNodesInfoAction; | ||
import org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest; | ||
import org.opensearch.action.admin.cluster.stats.ClusterStatsRequest; | ||
import org.opensearch.action.admin.cluster.stats.TransportClusterStatsAction; | ||
import org.opensearch.action.support.ActionFilters; | ||
import org.opensearch.action.support.PlainActionFuture; | ||
import org.opensearch.cluster.node.DiscoveryNode; | ||
import org.opensearch.cluster.service.ClusterService; | ||
import org.opensearch.common.io.stream.BytesStreamOutput; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.indices.IndicesService; | ||
import org.opensearch.node.NodeService; | ||
import org.opensearch.test.transport.CapturingTransport; | ||
import org.opensearch.threadpool.ThreadPool; | ||
import org.opensearch.transport.TransportService; | ||
|
||
import java.io.IOException; | ||
import java.util.*; | ||
|
||
public class TransportClusterStatsActionTests extends TransportNodesActionTests { | ||
|
||
public void testOptimizedBehavior() { | ||
ClusterStatsRequest request = new ClusterStatsRequest(); | ||
request.populateDiscoveryNodesInTransportRequest(false); | ||
Map<String, List<MockClusterStatsNodeRequest>> combinedSentRequest = performNodesInfoAction(request); | ||
|
||
assertNotNull(combinedSentRequest); | ||
combinedSentRequest.forEach((node, capturedRequestList) -> { | ||
assertNotNull(capturedRequestList); | ||
capturedRequestList.forEach(sentRequest -> { | ||
assertNull(sentRequest.getDiscoveryNodes()); | ||
}); | ||
}); | ||
} | ||
|
||
public void testDefaultBehavior() { | ||
ClusterStatsRequest request = new ClusterStatsRequest(); | ||
request.populateDiscoveryNodesInTransportRequest(true); | ||
Map<String, List<MockClusterStatsNodeRequest>> combinedSentRequest = performNodesInfoAction(request); | ||
|
||
assertNotNull(combinedSentRequest); | ||
combinedSentRequest.forEach((node, capturedRequestList) -> { | ||
assertNotNull(capturedRequestList); | ||
capturedRequestList.forEach(sentRequest -> { | ||
assertNotNull(sentRequest.getDiscoveryNodes()); | ||
assertEquals(sentRequest.getDiscoveryNodes().length, clusterService.state().nodes().getSize() ); | ||
}); | ||
}); | ||
} | ||
|
||
private Map<String, List<MockClusterStatsNodeRequest>> performNodesInfoAction(ClusterStatsRequest request) { | ||
TransportNodesAction action = getTestTransportClusterStatsAction(); | ||
PlainActionFuture<NodesStatsRequest> listener = new PlainActionFuture<>(); | ||
action.new AsyncAction(null, request, listener).start(); | ||
Map<String, List<CapturingTransport.CapturedRequest>> capturedRequests = transport.getCapturedRequestsByTargetNodeAndClear(); | ||
Map<String, List<MockClusterStatsNodeRequest>> combinedSentRequest = new HashMap<>(); | ||
|
||
capturedRequests.forEach((node, capturedRequestList) -> { | ||
List<MockClusterStatsNodeRequest> sentRequestList = new ArrayList<>(); | ||
|
||
capturedRequestList.forEach(preSentRequest -> { | ||
BytesStreamOutput out = new BytesStreamOutput(); | ||
try { | ||
TransportClusterStatsAction.ClusterStatsNodeRequest clusterStatsNodeRequestFromCoordinator= (TransportClusterStatsAction.ClusterStatsNodeRequest) preSentRequest.request; | ||
clusterStatsNodeRequestFromCoordinator.writeTo(out); | ||
StreamInput in = out.bytes().streamInput(); | ||
MockClusterStatsNodeRequest mockClusterStatsNodeRequest = new MockClusterStatsNodeRequest(in); | ||
sentRequestList.add(mockClusterStatsNodeRequest); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
|
||
combinedSentRequest.put(node, sentRequestList); | ||
}); | ||
|
||
return combinedSentRequest; | ||
} | ||
|
||
public TestTransportClusterStatsAction getTestTransportClusterStatsAction() { | ||
return new TestTransportClusterStatsAction( | ||
THREAD_POOL, | ||
clusterService, | ||
transportService, | ||
nodeService, | ||
indicesService, | ||
new ActionFilters(Collections.emptySet()) | ||
); | ||
} | ||
|
||
private static class TestTransportClusterStatsAction extends TransportClusterStatsAction { | ||
public TestTransportClusterStatsAction( | ||
ThreadPool threadPool, | ||
ClusterService clusterService, | ||
TransportService transportService, | ||
NodeService nodeService, | ||
IndicesService indicesService, | ||
ActionFilters actionFilters) { | ||
super(threadPool, clusterService, transportService, nodeService, indicesService, actionFilters); | ||
} | ||
} | ||
|
||
private static class MockClusterStatsNodeRequest extends TransportClusterStatsAction.ClusterStatsNodeRequest{ | ||
|
||
public MockClusterStatsNodeRequest(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
public DiscoveryNode[] getDiscoveryNodes() { | ||
return this.request.concreteNodes(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.