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.
[Workload Management] QueryGroup Stats API Logic (opensearch-project#…
…15777) * changelog Signed-off-by: Ruirui Zhang <[email protected]> * address comments Signed-off-by: Ruirui Zhang <[email protected]> * add tests Signed-off-by: Ruirui Zhang <[email protected]> * modify uri Signed-off-by: Ruirui Zhang <[email protected]> * address comments Signed-off-by: Ruirui Zhang <[email protected]> * modify based on comments Signed-off-by: Ruirui Zhang <[email protected]> * changelog Signed-off-by: Ruirui Zhang <[email protected]> * address comments Signed-off-by: Ruirui Zhang <[email protected]> * add tests Signed-off-by: Ruirui Zhang <[email protected]> * modify uri Signed-off-by: Ruirui Zhang <[email protected]> * modify based on comments Signed-off-by: Ruirui Zhang <[email protected]> * modify based on comments Signed-off-by: Ruirui Zhang <[email protected]> * revise Signed-off-by: Ruirui Zhang <[email protected]> * address comments Signed-off-by: Ruirui Zhang <[email protected]> * changelog Signed-off-by: Ruirui Zhang <[email protected]> * address comments Signed-off-by: Ruirui Zhang <[email protected]> * add tests Signed-off-by: Ruirui Zhang <[email protected]> * modify uri Signed-off-by: Ruirui Zhang <[email protected]> * modify based on comments Signed-off-by: Ruirui Zhang <[email protected]> * modify based on comments Signed-off-by: Ruirui Zhang <[email protected]> * git pull Signed-off-by: Ruirui Zhang <[email protected]> * rebase Signed-off-by: Ruirui Zhang <[email protected]> * encapsulate querygroupstats in wlmstats Signed-off-by: Ruirui Zhang <[email protected]> * fix UT Signed-off-by: Ruirui Zhang <[email protected]>
- Loading branch information
Showing
19 changed files
with
731 additions
and
16 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
79 changes: 79 additions & 0 deletions
79
server/src/main/java/org/opensearch/action/admin/cluster/wlm/TransportWlmStatsAction.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,79 @@ | ||
/* | ||
* 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.WlmStats; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* Transport action for obtaining WlmStats | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public class TransportWlmStatsAction extends TransportNodesAction<WlmStatsRequest, WlmStatsResponse, WlmStatsRequest, WlmStats> { | ||
|
||
final QueryGroupService queryGroupService; | ||
|
||
@Inject | ||
public TransportWlmStatsAction( | ||
ThreadPool threadPool, | ||
ClusterService clusterService, | ||
TransportService transportService, | ||
QueryGroupService queryGroupService, | ||
ActionFilters actionFilters | ||
) { | ||
super( | ||
WlmStatsAction.NAME, | ||
threadPool, | ||
clusterService, | ||
transportService, | ||
actionFilters, | ||
WlmStatsRequest::new, | ||
WlmStatsRequest::new, | ||
ThreadPool.Names.MANAGEMENT, | ||
WlmStats.class | ||
); | ||
this.queryGroupService = queryGroupService; | ||
} | ||
|
||
@Override | ||
protected WlmStatsResponse newResponse(WlmStatsRequest request, List<WlmStats> wlmStats, List<FailedNodeException> failures) { | ||
return new WlmStatsResponse(clusterService.getClusterName(), wlmStats, failures); | ||
} | ||
|
||
@Override | ||
protected WlmStatsRequest newNodeRequest(WlmStatsRequest request) { | ||
return request; | ||
} | ||
|
||
@Override | ||
protected WlmStats newNodeResponse(StreamInput in) throws IOException { | ||
return new WlmStats(in); | ||
} | ||
|
||
@Override | ||
protected WlmStats nodeOperation(WlmStatsRequest wlmStatsRequest) { | ||
assert transportService.getLocalNode() != null; | ||
return new WlmStats( | ||
transportService.getLocalNode(), | ||
queryGroupService.nodeStats(wlmStatsRequest.getQueryGroupIds(), wlmStatsRequest.isBreach()) | ||
); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
server/src/main/java/org/opensearch/action/admin/cluster/wlm/WlmStatsAction.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,25 @@ | ||
/* | ||
* 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 Workload Management Stats. | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public class WlmStatsAction extends ActionType<WlmStatsResponse> { | ||
public static final WlmStatsAction INSTANCE = new WlmStatsAction(); | ||
public static final String NAME = "cluster:monitor/wlm/stats"; | ||
|
||
private WlmStatsAction() { | ||
super(NAME, WlmStatsResponse::new); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
server/src/main/java/org/opensearch/action/admin/cluster/wlm/WlmStatsRequest.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,65 @@ | ||
/* | ||
* 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 Workload Management Stats | ||
*/ | ||
@ExperimentalApi | ||
public class WlmStatsRequest extends BaseNodesRequest<WlmStatsRequest> { | ||
|
||
private final Set<String> queryGroupIds; | ||
private final Boolean breach; | ||
|
||
public WlmStatsRequest(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 WlmStatsRequest(String[] nodesIds, Set<String> queryGroupIds, Boolean breach) { | ||
super(false, nodesIds); | ||
this.queryGroupIds = queryGroupIds; | ||
this.breach = breach; | ||
} | ||
|
||
public WlmStatsRequest() { | ||
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<String> getQueryGroupIds() { | ||
return queryGroupIds; | ||
} | ||
|
||
public Boolean isBreach() { | ||
return breach; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
server/src/main/java/org/opensearch/action/admin/cluster/wlm/WlmStatsResponse.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,73 @@ | ||
/* | ||
* 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 org.opensearch.wlm.stats.WlmStats; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* A response for obtaining Workload Management Stats | ||
*/ | ||
@ExperimentalApi | ||
public class WlmStatsResponse extends BaseNodesResponse<WlmStats> implements ToXContentFragment { | ||
|
||
WlmStatsResponse(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
WlmStatsResponse(ClusterName clusterName, List<WlmStats> nodes, List<FailedNodeException> failures) { | ||
super(clusterName, nodes, failures); | ||
} | ||
|
||
@Override | ||
protected List<WlmStats> readNodesFrom(StreamInput in) throws IOException { | ||
return in.readList(WlmStats::new); | ||
} | ||
|
||
@Override | ||
protected void writeNodesTo(StreamOutput out, List<WlmStats> nodes) throws IOException { | ||
out.writeList(nodes); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
for (WlmStats wlmStats : getNodes()) { | ||
builder.startObject(wlmStats.getNode().getId()); | ||
QueryGroupStats queryGroupStats = wlmStats.getQueryGroupStats(); | ||
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() + "\"}"; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
server/src/main/java/org/opensearch/action/admin/cluster/wlm/package-info.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,10 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** WlmStats transport handlers. */ | ||
package org.opensearch.action.admin.cluster.wlm; |
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
Oops, something went wrong.