Skip to content

Commit c0bcacb

Browse files
Add query group stats constructs (#15343)
* add query group stats constructs Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * add changelog entry Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * add packageinfo for stats Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * add total cancellations Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * add more granular level rejections Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * add toXContent test cases Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * move ResourceType enum to wlm Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * update the comment for query group stats Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> --------- Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com>
1 parent 8d17c8d commit c0bcacb

22 files changed

+517
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2929
- [Streaming Indexing] Introduce bulk HTTP API streaming flavor ([#15381](https://github.com/opensearch-project/OpenSearch/pull/15381))
3030
- Add support for centralize snapshot creation with pinned timestamp ([#15124](https://github.com/opensearch-project/OpenSearch/pull/15124))
3131
- Add concurrent search support for Derived Fields ([#15326](https://github.com/opensearch-project/OpenSearch/pull/15326))
32+
- [Workload Management] Add query group stats constructs ([#15343](https://github.com/opensearch-project/OpenSearch/pull/15343)))
3233

3334
### Dependencies
3435
- Bump `netty` from 4.1.111.Final to 4.1.112.Final ([#15081](https://github.com/opensearch-project/OpenSearch/pull/15081))

plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/service/QueryGroupPersistenceService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.opensearch.core.rest.RestStatus;
3030
import org.opensearch.plugin.wlm.action.CreateQueryGroupResponse;
3131
import org.opensearch.plugin.wlm.action.DeleteQueryGroupRequest;
32-
import org.opensearch.search.ResourceType;
32+
import org.opensearch.wlm.ResourceType;
3333

3434
import java.util.Collection;
3535
import java.util.EnumMap;

plugins/workload-management/src/test/java/org/opensearch/plugin/wlm/QueryGroupTestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import java.util.Set;
3232

3333
import static org.opensearch.cluster.metadata.QueryGroup.builder;
34-
import static org.opensearch.search.ResourceType.fromName;
34+
import static org.opensearch.wlm.ResourceType.fromName;
3535
import static org.junit.Assert.assertEquals;
3636
import static org.junit.Assert.assertFalse;
3737
import static org.junit.Assert.assertTrue;

plugins/workload-management/src/test/java/org/opensearch/plugin/wlm/service/QueryGroupPersistenceServiceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import org.opensearch.plugin.wlm.QueryGroupTestUtils;
2525
import org.opensearch.plugin.wlm.action.CreateQueryGroupResponse;
2626
import org.opensearch.plugin.wlm.action.DeleteQueryGroupRequest;
27-
import org.opensearch.search.ResourceType;
2827
import org.opensearch.test.OpenSearchTestCase;
2928
import org.opensearch.threadpool.ThreadPool;
29+
import org.opensearch.wlm.ResourceType;
3030

3131
import java.util.ArrayList;
3232
import java.util.Collection;

server/src/main/java/org/opensearch/cluster/metadata/QueryGroup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.opensearch.core.xcontent.ToXContentObject;
1818
import org.opensearch.core.xcontent.XContentBuilder;
1919
import org.opensearch.core.xcontent.XContentParser;
20-
import org.opensearch.search.ResourceType;
20+
import org.opensearch.wlm.ResourceType;
2121
import org.joda.time.Instant;
2222

2323
import java.io.IOException;

server/src/main/java/org/opensearch/search/backpressure/SearchBackpressureService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.opensearch.common.settings.Setting;
1919
import org.opensearch.monitor.jvm.JvmStats;
2020
import org.opensearch.monitor.process.ProcessProbe;
21-
import org.opensearch.search.ResourceType;
2221
import org.opensearch.search.backpressure.settings.SearchBackpressureMode;
2322
import org.opensearch.search.backpressure.settings.SearchBackpressureSettings;
2423
import org.opensearch.search.backpressure.settings.SearchShardTaskSettings;
@@ -43,6 +42,7 @@
4342
import org.opensearch.tasks.TaskResourceTrackingService.TaskCompletionListener;
4443
import org.opensearch.threadpool.Scheduler;
4544
import org.opensearch.threadpool.ThreadPool;
45+
import org.opensearch.wlm.ResourceType;
4646

4747
import java.io.IOException;
4848
import java.util.ArrayList;

server/src/main/java/org/opensearch/search/backpressure/trackers/NodeDuressTrackers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
package org.opensearch.search.backpressure.trackers;
1010

1111
import org.opensearch.common.util.Streak;
12-
import org.opensearch.search.ResourceType;
12+
import org.opensearch.wlm.ResourceType;
1313

1414
import java.util.Map;
1515
import java.util.function.BooleanSupplier;

server/src/main/java/org/opensearch/wlm/QueryGroupLevelResourceUsageView.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
package org.opensearch.wlm;
1010

11-
import org.opensearch.search.ResourceType;
1211
import org.opensearch.tasks.Task;
1312

1413
import java.util.List;

server/src/main/java/org/opensearch/search/ResourceType.java renamed to server/src/main/java/org/opensearch/wlm/ResourceType.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* compatible open source license.
77
*/
88

9-
package org.opensearch.search;
9+
package org.opensearch.wlm;
1010

1111
import org.opensearch.common.annotation.PublicApi;
1212
import org.opensearch.core.common.io.stream.StreamOutput;
@@ -21,15 +21,17 @@
2121
*/
2222
@PublicApi(since = "2.x")
2323
public enum ResourceType {
24-
CPU("cpu", task -> task.getTotalResourceUtilization(ResourceStats.CPU)),
25-
MEMORY("memory", task -> task.getTotalResourceUtilization(ResourceStats.MEMORY));
24+
CPU("cpu", task -> task.getTotalResourceUtilization(ResourceStats.CPU), true),
25+
MEMORY("memory", task -> task.getTotalResourceUtilization(ResourceStats.MEMORY), true);
2626

2727
private final String name;
2828
private final Function<Task, Long> getResourceUsage;
29+
private final boolean statsEnabled;
2930

30-
ResourceType(String name, Function<Task, Long> getResourceUsage) {
31+
ResourceType(String name, Function<Task, Long> getResourceUsage, boolean statsEnabled) {
3132
this.name = name;
3233
this.getResourceUsage = getResourceUsage;
34+
this.statsEnabled = statsEnabled;
3335
}
3436

3537
/**
@@ -63,4 +65,8 @@ public String getName() {
6365
public long getResourceUsage(Task task) {
6466
return getResourceUsage.apply(task);
6567
}
68+
69+
public boolean hasStatsEnabled() {
70+
return statsEnabled;
71+
}
6672
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.wlm.stats;
10+
11+
import org.opensearch.common.metrics.CounterMetric;
12+
import org.opensearch.wlm.ResourceType;
13+
14+
import java.util.EnumMap;
15+
import java.util.Map;
16+
17+
/**
18+
* This class will keep the point in time view of the query group stats
19+
*/
20+
public class QueryGroupState {
21+
/**
22+
* completions at the query group level, this is a cumulative counter since the Opensearch start time
23+
*/
24+
final CounterMetric completions = new CounterMetric();
25+
26+
/**
27+
* rejections at the query group level, this is a cumulative counter since the OpenSearch start time
28+
*/
29+
final CounterMetric totalRejections = new CounterMetric();
30+
31+
/**
32+
* this will track the cumulative failures in a query group
33+
*/
34+
final CounterMetric failures = new CounterMetric();
35+
36+
/**
37+
* This will track total number of cancellations in the query group due to all resource type breaches
38+
*/
39+
final CounterMetric totalCancellations = new CounterMetric();
40+
41+
/**
42+
* This is used to store the resource type state both for CPU and MEMORY
43+
*/
44+
private final Map<ResourceType, ResourceTypeState> resourceState;
45+
46+
public QueryGroupState() {
47+
resourceState = new EnumMap<>(ResourceType.class);
48+
for (ResourceType resourceType : ResourceType.values()) {
49+
if (resourceType.hasStatsEnabled()) {
50+
resourceState.put(resourceType, new ResourceTypeState(resourceType));
51+
}
52+
}
53+
}
54+
55+
/**
56+
*
57+
* @return completions in the query group
58+
*/
59+
public long getCompletions() {
60+
return completions.count();
61+
}
62+
63+
/**
64+
*
65+
* @return rejections in the query group
66+
*/
67+
public long getTotalRejections() {
68+
return totalRejections.count();
69+
}
70+
71+
/**
72+
*
73+
* @return failures in the query group
74+
*/
75+
public long getFailures() {
76+
return failures.count();
77+
}
78+
79+
public long getTotalCancellations() {
80+
return totalCancellations.count();
81+
}
82+
83+
/**
84+
* getter for query group resource state
85+
* @return the query group resource state
86+
*/
87+
public Map<ResourceType, ResourceTypeState> getResourceState() {
88+
return resourceState;
89+
}
90+
91+
/**
92+
* This class holds the resource level stats for the query group
93+
*/
94+
public static class ResourceTypeState {
95+
final ResourceType resourceType;
96+
final CounterMetric cancellations = new CounterMetric();
97+
final CounterMetric rejections = new CounterMetric();
98+
99+
public ResourceTypeState(ResourceType resourceType) {
100+
this.resourceType = resourceType;
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)