-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Optimise TransportNodesAction to not send DiscoveryNodes for NodeStat… #14749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shwetathareja
merged 15 commits into
opensearch-project:main
from
Pranshu-S:TransportNodesActionOptimisation-DiscoveryNodeFix2
Jul 22, 2024
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d2ef37d
Optimize TransportNodesAction to not send DiscoveryNodes for NodeStat…
Pranshu-S 33af363
Retry Build
Pranshu-S 2de5f30
Retry Build
Pranshu-S 4a61334
Merge remote-tracking branch 'origin/main' into TransportNodesActionO…
Pranshu-S 556da0e
Add ChangeLogs
Pranshu-S bd2cc8f
Fix test naming and refactoring
Pranshu-S b53c772
Adding code coverage
Pranshu-S 5fffc47
fix naming and simplifying code
Pranshu-S a43d725
Removing unncessary methods after refactoring
Pranshu-S bfce85e
refactor naming
Pranshu-S f6a911c
Merge remote-tracking branch 'origin/main' into TransportNodesActionO…
Pranshu-S 9da507b
Update ChangeLog
Pranshu-S 3f7bca1
minor refactoring of AsyncAction
Pranshu-S a69f7e7
change variable naming
Pranshu-S 3a8e7ef
Retry Build
Pranshu-S File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.sendDiscoveryNodes(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() { | ||
Pranshu-S marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.sendDiscoveryNodes(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.sendDiscoveryNodes(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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.