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.
Optimise TransportNodesAction to not send DiscoveryNodes for NodeStat… (
opensearch-project#14749) * Optimize TransportNodesAction to not send DiscoveryNodes for NodeStats, NodesInfo and ClusterStats call Signed-off-by: Pranshu Shukla <[email protected]>
- Loading branch information
1 parent
3a397f5
commit 9fffb4d
Showing
15 changed files
with
528 additions
and
11 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
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
59 changes: 59 additions & 0 deletions
59
server/src/test/java/org/opensearch/action/RestStatsActionTests.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,59 @@ | ||
/* | ||
* 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; | ||
|
||
import org.opensearch.client.node.NodeClient; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.settings.SettingsFilter; | ||
import org.opensearch.rest.action.admin.cluster.RestClusterStatsAction; | ||
import org.opensearch.rest.action.admin.cluster.RestNodesInfoAction; | ||
import org.opensearch.rest.action.admin.cluster.RestNodesStatsAction; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
import org.opensearch.test.rest.FakeRestRequest; | ||
import org.opensearch.threadpool.TestThreadPool; | ||
import org.junit.After; | ||
|
||
import java.util.Collections; | ||
|
||
public class RestStatsActionTests extends OpenSearchTestCase { | ||
private final TestThreadPool threadPool = new TestThreadPool(RestStatsActionTests.class.getName()); | ||
private final NodeClient client = new NodeClient(Settings.EMPTY, threadPool); | ||
|
||
@After | ||
public void terminateThreadPool() { | ||
terminate(threadPool); | ||
} | ||
|
||
public void testClusterStatsActionPrepareRequestNoError() { | ||
RestClusterStatsAction action = new RestClusterStatsAction(); | ||
try { | ||
action.prepareRequest(new FakeRestRequest(), client); | ||
} catch (Throwable t) { | ||
fail(t.getMessage()); | ||
} | ||
} | ||
|
||
public void testNodesStatsActionPrepareRequestNoError() { | ||
RestNodesStatsAction action = new RestNodesStatsAction(); | ||
try { | ||
action.prepareRequest(new FakeRestRequest(), client); | ||
} catch (Throwable t) { | ||
fail(t.getMessage()); | ||
} | ||
} | ||
|
||
public void testNodesInfoActionPrepareRequestNoError() { | ||
RestNodesInfoAction action = new RestNodesInfoAction(new SettingsFilter(Collections.singleton("foo.filtered"))); | ||
try { | ||
action.prepareRequest(new FakeRestRequest(), client); | ||
} catch (Throwable t) { | ||
fail(t.getMessage()); | ||
} | ||
} | ||
} |
165 changes: 165 additions & 0 deletions
165
...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,165 @@ | ||
/* | ||
* 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.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.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class TransportClusterStatsActionTests extends TransportNodesActionTests { | ||
|
||
/** | ||
* By default, we send discovery nodes list to each request that is sent across from the coordinator node. This | ||
* behavior is asserted in this test. | ||
*/ | ||
public void testClusterStatsActionWithRetentionOfDiscoveryNodesList() { | ||
ClusterStatsRequest request = new ClusterStatsRequest(); | ||
request.setIncludeDiscoveryNodes(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()); | ||
}); | ||
}); | ||
} | ||
|
||
public void testClusterStatsActionWithPreFilledConcreteNodesAndWithRetentionOfDiscoveryNodesList() { | ||
ClusterStatsRequest request = new ClusterStatsRequest(); | ||
Collection<DiscoveryNode> discoveryNodes = clusterService.state().getNodes().getNodes().values(); | ||
request.setConcreteNodes(discoveryNodes.toArray(DiscoveryNode[]::new)); | ||
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()); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* In the optimized ClusterStats Request, we do not send the DiscoveryNodes List to each node. This behavior is | ||
* asserted in this test. | ||
*/ | ||
public void testClusterStatsActionWithoutRetentionOfDiscoveryNodesList() { | ||
ClusterStatsRequest request = new ClusterStatsRequest(); | ||
request.setIncludeDiscoveryNodes(false); | ||
Map<String, List<MockClusterStatsNodeRequest>> combinedSentRequest = performNodesInfoAction(request); | ||
|
||
assertNotNull(combinedSentRequest); | ||
combinedSentRequest.forEach((node, capturedRequestList) -> { | ||
assertNotNull(capturedRequestList); | ||
capturedRequestList.forEach(sentRequest -> { assertNull(sentRequest.getDiscoveryNodes()); }); | ||
}); | ||
} | ||
|
||
public void testClusterStatsActionWithPreFilledConcreteNodesAndWithoutRetentionOfDiscoveryNodesList() { | ||
ClusterStatsRequest request = new ClusterStatsRequest(); | ||
Collection<DiscoveryNode> discoveryNodes = clusterService.state().getNodes().getNodes().values(); | ||
request.setConcreteNodes(discoveryNodes.toArray(DiscoveryNode[]::new)); | ||
request.setIncludeDiscoveryNodes(false); | ||
Map<String, List<MockClusterStatsNodeRequest>> combinedSentRequest = performNodesInfoAction(request); | ||
|
||
assertNotNull(combinedSentRequest); | ||
combinedSentRequest.forEach((node, capturedRequestList) -> { | ||
assertNotNull(capturedRequestList); | ||
capturedRequestList.forEach(sentRequest -> { assertNull(sentRequest.getDiscoveryNodes()); }); | ||
}); | ||
} | ||
|
||
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; | ||
} | ||
|
||
private 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.