diff --git a/server/src/main/java/org/opensearch/action/ActionModule.java b/server/src/main/java/org/opensearch/action/ActionModule.java index e8a11c2a2229e..e3b44564b62da 100644 --- a/server/src/main/java/org/opensearch/action/ActionModule.java +++ b/server/src/main/java/org/opensearch/action/ActionModule.java @@ -369,7 +369,6 @@ import org.opensearch.rest.action.admin.cluster.RestPendingClusterTasksAction; import org.opensearch.rest.action.admin.cluster.RestPutRepositoryAction; import org.opensearch.rest.action.admin.cluster.RestPutStoredScriptAction; -import org.opensearch.rest.action.admin.cluster.RestQueryGroupStatsAction; import org.opensearch.rest.action.admin.cluster.RestReloadSecureSettingsAction; import org.opensearch.rest.action.admin.cluster.RestRemoteClusterInfoAction; import org.opensearch.rest.action.admin.cluster.RestRemoteStoreStatsAction; @@ -615,11 +614,8 @@ public void reg actions.register(NodesInfoAction.INSTANCE, TransportNodesInfoAction.class); actions.register(RemoteInfoAction.INSTANCE, TransportRemoteInfoAction.class); actions.register(NodesStatsAction.INSTANCE, TransportNodesStatsAction.class); -<<<<<<< HEAD actions.register(WlmStatsAction.INSTANCE, TransportWlmStatsAction.class); -======= - actions.register(QueryGroupStatsAction.INSTANCE, TransportQueryGroupStatsAction.class); ->>>>>>> 986882eb641 (changelog) + actions.register(WlmStatsAction.INSTANCE, TransportWlmStatsAction.class); actions.register(RemoteStoreStatsAction.INSTANCE, TransportRemoteStoreStatsAction.class); actions.register(NodesUsageAction.INSTANCE, TransportNodesUsageAction.class); actions.register(NodesHotThreadsAction.INSTANCE, TransportNodesHotThreadsAction.class); @@ -821,11 +817,8 @@ public void initRestHandlers(Supplier nodesInCluster) { registerHandler.accept(new RestClearVotingConfigExclusionsAction()); registerHandler.accept(new RestMainAction()); registerHandler.accept(new RestNodesInfoAction(settingsFilter)); -<<<<<<< HEAD registerHandler.accept(new RestWlmStatsAction()); -======= - registerHandler.accept(new RestQueryGroupStatsAction()); ->>>>>>> 986882eb641 (changelog) + registerHandler.accept(new RestWlmStatsAction()); registerHandler.accept(new RestRemoteClusterInfoAction()); registerHandler.accept(new RestNodesStatsAction()); registerHandler.accept(new RestNodesUsageAction()); diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/wlm/QueryGroupStatsAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/wlm/QueryGroupStatsAction.java deleted file mode 100644 index bb865aab28521..0000000000000 --- a/server/src/main/java/org/opensearch/action/admin/cluster/wlm/QueryGroupStatsAction.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.admin.cluster.wlm; - -import org.opensearch.action.ActionType; - -/** - * Transport action for obtaining QueryGroup Stats. - * - * @opensearch.experimental - */ -public class QueryGroupStatsAction extends ActionType { - public static final QueryGroupStatsAction INSTANCE = new QueryGroupStatsAction(); - public static final String NAME = "cluster:monitor/query_group_stats"; - - private QueryGroupStatsAction() { - super(NAME, QueryGroupStatsResponse::new); - } -} diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/wlm/QueryGroupStatsRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/wlm/QueryGroupStatsRequest.java deleted file mode 100644 index 66bd7df5a1adc..0000000000000 --- a/server/src/main/java/org/opensearch/action/admin/cluster/wlm/QueryGroupStatsRequest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.admin.cluster.wlm; - -import org.opensearch.action.support.nodes.BaseNodesRequest; -import org.opensearch.common.annotation.ExperimentalApi; -import org.opensearch.core.common.io.stream.StreamInput; -import org.opensearch.core.common.io.stream.StreamOutput; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; - -/** - * A request to get QueryGroupStats - */ -@ExperimentalApi -public class QueryGroupStatsRequest extends BaseNodesRequest { - - private final Set queryGroupIds; - private final Boolean breach; - - public QueryGroupStatsRequest(StreamInput in) throws IOException { - super(in); - this.queryGroupIds = new HashSet<>(Set.of(in.readStringArray())); - this.breach = in.readOptionalBoolean(); - } - - /** - * Get QueryGroup stats from nodes based on the nodes ids specified. If none are passed, stats - * for all nodes will be returned. - */ - public QueryGroupStatsRequest(String[] nodesIds, Set queryGroupIds, boolean breach) { - super(false, nodesIds); - this.queryGroupIds = queryGroupIds; - this.breach = breach; - } - - public QueryGroupStatsRequest() { - super(false, (String[]) null); - queryGroupIds = new HashSet<>(); - this.breach = false; - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeStringArray(queryGroupIds.toArray(new String[0])); - out.writeOptionalBoolean(breach); - } - - public Set getQueryGroupIds() { - return queryGroupIds; - } - - public boolean isBreach() { - return breach; - } -} diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/wlm/QueryGroupStatsResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/wlm/QueryGroupStatsResponse.java deleted file mode 100644 index 8fa958a97634f..0000000000000 --- a/server/src/main/java/org/opensearch/action/admin/cluster/wlm/QueryGroupStatsResponse.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.admin.cluster.wlm; - -import org.opensearch.action.FailedNodeException; -import org.opensearch.action.support.nodes.BaseNodesResponse; -import org.opensearch.cluster.ClusterName; -import org.opensearch.common.annotation.ExperimentalApi; -import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.core.common.io.stream.StreamInput; -import org.opensearch.core.common.io.stream.StreamOutput; -import org.opensearch.core.xcontent.ToXContentFragment; -import org.opensearch.core.xcontent.XContentBuilder; -import org.opensearch.wlm.stats.QueryGroupStats; - -import java.io.IOException; -import java.util.List; - -/** - * A response for obtaining QueryGroupStats - */ -@ExperimentalApi -public class QueryGroupStatsResponse extends BaseNodesResponse implements ToXContentFragment { - - QueryGroupStatsResponse(StreamInput in) throws IOException { - super(in); - } - - QueryGroupStatsResponse(ClusterName clusterName, List nodes, List failures) { - super(clusterName, nodes, failures); - } - - @Override - protected List readNodesFrom(StreamInput in) throws IOException { - return in.readList(QueryGroupStats::new); - } - - @Override - protected void writeNodesTo(StreamOutput out, List nodes) throws IOException { - out.writeList(nodes); - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - for (QueryGroupStats queryGroupStats : getNodes()) { - builder.startObject(queryGroupStats.getNode().getId()); - queryGroupStats.toXContent(builder, params); - builder.endObject(); - } - return builder; - } - - @Override - public String toString() { - try { - XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint(); - builder.startObject(); - toXContent(builder, EMPTY_PARAMS); - builder.endObject(); - return builder.toString(); - } catch (IOException e) { - return "{ \"error\" : \"" + e.getMessage() + "\"}"; - } - } -} diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/wlm/TransportQueryGroupStatsAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/wlm/TransportQueryGroupStatsAction.java deleted file mode 100644 index 583f06d08967f..0000000000000 --- a/server/src/main/java/org/opensearch/action/admin/cluster/wlm/TransportQueryGroupStatsAction.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.admin.cluster.wlm; - -import org.opensearch.action.FailedNodeException; -import org.opensearch.action.support.ActionFilters; -import org.opensearch.action.support.nodes.TransportNodesAction; -import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.inject.Inject; -import org.opensearch.core.common.io.stream.StreamInput; -import org.opensearch.threadpool.ThreadPool; -import org.opensearch.transport.TransportService; -import org.opensearch.wlm.QueryGroupService; -import org.opensearch.wlm.stats.QueryGroupStats; - -import java.io.IOException; -import java.util.List; - -/** - * Transport action for obtaining QueryGroupStats - * - * @opensearch.experimental - */ -public class TransportQueryGroupStatsAction extends TransportNodesAction< - QueryGroupStatsRequest, - QueryGroupStatsResponse, - QueryGroupStatsRequest, - QueryGroupStats> { - - QueryGroupService queryGroupService; - - @Inject - public TransportQueryGroupStatsAction( - ThreadPool threadPool, - ClusterService clusterService, - TransportService transportService, - QueryGroupService queryGroupService, - ActionFilters actionFilters - ) { - super( - QueryGroupStatsAction.NAME, - threadPool, - clusterService, - transportService, - actionFilters, - QueryGroupStatsRequest::new, - QueryGroupStatsRequest::new, - ThreadPool.Names.MANAGEMENT, - QueryGroupStats.class - ); - this.queryGroupService = queryGroupService; - } - - @Override - protected QueryGroupStatsResponse newResponse( - QueryGroupStatsRequest request, - List queryGroupStats, - List failures - ) { - return new QueryGroupStatsResponse(clusterService.getClusterName(), queryGroupStats, failures); - } - - @Override - protected QueryGroupStatsRequest newNodeRequest(QueryGroupStatsRequest request) { - return request; - } - - @Override - protected QueryGroupStats newNodeResponse(StreamInput in) throws IOException { - return new QueryGroupStats(in); - } - - @Override - protected QueryGroupStats nodeOperation(QueryGroupStatsRequest queryGroupStatsRequest) { - return queryGroupService.nodeStats(queryGroupStatsRequest.getQueryGroupIds(), queryGroupStatsRequest.isBreach()); - } -} diff --git a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestQueryGroupStatsAction.java b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestQueryGroupStatsAction.java deleted file mode 100644 index 9def1a278f03e..0000000000000 --- a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestQueryGroupStatsAction.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.rest.action.admin.cluster; - -import org.opensearch.action.admin.cluster.wlm.QueryGroupStatsRequest; -import org.opensearch.client.node.NodeClient; -import org.opensearch.core.common.Strings; -import org.opensearch.rest.BaseRestHandler; -import org.opensearch.rest.RestRequest; -import org.opensearch.rest.action.RestActions; - -import java.io.IOException; -import java.util.List; -import java.util.Set; - -import static java.util.Arrays.asList; -import static java.util.Collections.unmodifiableList; -import static org.opensearch.rest.RestRequest.Method.GET; - -/** - * Transport action to get QueryGroup stats - * - * @opensearch.experimental - */ -public class RestQueryGroupStatsAction extends BaseRestHandler { - - @Override - public List routes() { - return unmodifiableList( - asList( - new Route(GET, "_wlm/stats"), - new Route(GET, "_wlm/{nodeId}/stats"), - new Route(GET, "_wlm/stats/{queryGroupId}"), - new Route(GET, "_wlm/{nodeId}/stats/{queryGroupId}") - ) - ); - } - - @Override - public String getName() { - return "query_group_stats_action"; - } - - @Override - protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { - String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId")); - Set queryGroupIds = Strings.tokenizeByCommaToSet(request.param("queryGroupId", "_all")); - Boolean breach = request.hasParam("breach") ? Boolean.parseBoolean(request.param("boolean")) : null; - QueryGroupStatsRequest queryGroupStatsRequest = new QueryGroupStatsRequest(nodesIds, queryGroupIds, breach); - return channel -> client.admin() - .cluster() - .queryGroupStats(queryGroupStatsRequest, new RestActions.NodesResponseRestListener<>(channel)); - } -} diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/wlm/QueryGroupStatsResponseTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/wlm/QueryGroupStatsResponseTests.java deleted file mode 100644 index b09f05e839ac3..0000000000000 --- a/server/src/test/java/org/opensearch/action/admin/cluster/wlm/QueryGroupStatsResponseTests.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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.admin.cluster.wlm; - -import org.opensearch.Version; -import org.opensearch.action.FailedNodeException; -import org.opensearch.cluster.ClusterName; -import org.opensearch.cluster.node.DiscoveryNode; -import org.opensearch.cluster.node.DiscoveryNodeRole; -import org.opensearch.common.io.stream.BytesStreamOutput; -import org.opensearch.core.common.io.stream.StreamInput; -import org.opensearch.test.OpenSearchTestCase; -import org.opensearch.wlm.ResourceType; -import org.opensearch.wlm.stats.QueryGroupStats; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class QueryGroupStatsResponseTests extends OpenSearchTestCase { - ClusterName clusterName = new ClusterName("test-cluster"); - String testQueryGroupId = "safjgagnaeekg-3r3fads"; - DiscoveryNode node = new DiscoveryNode( - "node-1", - buildNewFakeTransportAddress(), - new HashMap<>(), - Set.of(DiscoveryNodeRole.DATA_ROLE), - Version.CURRENT - ); - Map statsHolderMap = new HashMap<>(); - QueryGroupStats queryGroupStats = new QueryGroupStats( - node, - Map.of( - testQueryGroupId, - new QueryGroupStats.QueryGroupStatsHolder( - 0, - 0, - 1, - 0, - Map.of( - ResourceType.CPU, - new QueryGroupStats.ResourceStats(0, 0, 0), - ResourceType.MEMORY, - new QueryGroupStats.ResourceStats(0, 0, 0) - ) - ) - ) - ); - List queryGroupStatsList = List.of(queryGroupStats); - List failedNodeExceptionList = new ArrayList<>(); - - public void testSerializationAndDeserialization() throws IOException { - QueryGroupStatsResponse queryGroupStatsResponse = new QueryGroupStatsResponse( - clusterName, - queryGroupStatsList, - failedNodeExceptionList - ); - BytesStreamOutput out = new BytesStreamOutput(); - queryGroupStatsResponse.writeTo(out); - StreamInput in = out.bytes().streamInput(); - QueryGroupStatsResponse deserializedResponse = new QueryGroupStatsResponse(in); - assertEquals(queryGroupStatsResponse.getClusterName(), deserializedResponse.getClusterName()); - assertEquals(queryGroupStatsResponse.getNodes().size(), deserializedResponse.getNodes().size()); - } - - public void testToString() { - QueryGroupStatsResponse queryGroupStatsResponse = new QueryGroupStatsResponse( - clusterName, - queryGroupStatsList, - failedNodeExceptionList - ); - String responseString = queryGroupStatsResponse.toString(); - assertEquals( - "{\n" - + " \"node-1\" : {\n" - + " \"query_groups\" : {\n" - + " \"safjgagnaeekg-3r3fads\" : {\n" - + " \"completions\" : 0,\n" - + " \"rejections\" : 0,\n" - + " \"failures\" : 1,\n" - + " \"total_cancellations\" : 0,\n" - + " \"cpu\" : {\n" - + " \"current_usage\" : 0.0,\n" - + " \"cancellations\" : 0,\n" - + " \"rejections\" : 0\n" - + " },\n" - + " \"memory\" : {\n" - + " \"current_usage\" : 0.0,\n" - + " \"cancellations\" : 0,\n" - + " \"rejections\" : 0\n" - + " }\n" - + " }\n" - + " }\n" - + " }\n" - + "}", - responseString - ); - } -} diff --git a/server/src/test/java/org/opensearch/action/support/nodes/TransportQueryGroupStatsActionTests.java b/server/src/test/java/org/opensearch/action/support/nodes/TransportQueryGroupStatsActionTests.java deleted file mode 100644 index 9079410983dfd..0000000000000 --- a/server/src/test/java/org/opensearch/action/support/nodes/TransportQueryGroupStatsActionTests.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.wlm.QueryGroupStatsRequest; -import org.opensearch.action.admin.cluster.wlm.TransportQueryGroupStatsAction; -import org.opensearch.action.support.ActionFilters; -import org.opensearch.action.support.PlainActionFuture; -import org.opensearch.common.io.stream.BytesStreamOutput; -import org.opensearch.core.common.io.stream.StreamInput; -import org.opensearch.test.transport.CapturingTransport; -import org.opensearch.wlm.QueryGroupService; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.mockito.Mockito.mock; - -public class TransportQueryGroupStatsActionTests extends TransportNodesActionTests { - - /** - * We don't want to send discovery nodes list to each request that is sent across from the coordinator node. - * This behavior is asserted in this test. - */ - public void testQueryGroupStatsActionWithRetentionOfDiscoveryNodesList() { - QueryGroupStatsRequest request = new QueryGroupStatsRequest(); - Map> combinedSentRequest = performQueryGroupStatsAction(request); - - assertNotNull(combinedSentRequest); - combinedSentRequest.forEach((node, capturedRequestList) -> { - assertNotNull(capturedRequestList); - capturedRequestList.forEach(sentRequest -> { assertNull(sentRequest.concreteNodes()); }); - }); - } - - private Map> performQueryGroupStatsAction(QueryGroupStatsRequest request) { - TransportNodesAction action = new TransportQueryGroupStatsAction( - THREAD_POOL, - clusterService, - transportService, - mock(QueryGroupService.class), - new ActionFilters(Collections.emptySet()) - ); - PlainActionFuture listener = new PlainActionFuture<>(); - action.new AsyncAction(null, request, listener).start(); - Map> capturedRequests = transport.getCapturedRequestsByTargetNodeAndClear(); - Map> combinedSentRequest = new HashMap<>(); - - capturedRequests.forEach((node, capturedRequestList) -> { - List sentRequestList = new ArrayList<>(); - - capturedRequestList.forEach(preSentRequest -> { - BytesStreamOutput out = new BytesStreamOutput(); - try { - QueryGroupStatsRequest QueryGroupStatsRequestFromCoordinator = (QueryGroupStatsRequest) preSentRequest.request; - QueryGroupStatsRequestFromCoordinator.writeTo(out); - StreamInput in = out.bytes().streamInput(); - QueryGroupStatsRequest QueryGroupStatsRequest = new QueryGroupStatsRequest(in); - sentRequestList.add(QueryGroupStatsRequest); - } catch (IOException e) { - throw new RuntimeException(e); - } - }); - - combinedSentRequest.put(node, sentRequestList); - }); - - return combinedSentRequest; - } -}