Skip to content

Commit 01184de

Browse files
authored
Add Settings related to Workload Management feature (opensearch-project#15028)
* add QeryGroup Service tests Signed-off-by: Ruirui Zhang <mariazrr@amazon.com> * add PR to changelog Signed-off-by: Ruirui Zhang <mariazrr@amazon.com> * change the test directory Signed-off-by: Ruirui Zhang <mariazrr@amazon.com> * modify comments to be more specific Signed-off-by: Ruirui Zhang <mariazrr@amazon.com> * add test coverage Signed-off-by: Ruirui Zhang <mariazrr@amazon.com> * remove QUERY_GROUP_RUN_INTERVAL_SETTING as we'll define it in QueryGroupService Signed-off-by: Ruirui Zhang <mariazrr@amazon.com> * address comments Signed-off-by: Ruirui Zhang <mariazrr@amazon.com>
1 parent ce64fac commit 01184de

File tree

4 files changed

+506
-1
lines changed

4 files changed

+506
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1818
- Add `rangeQuery` and `regexpQuery` for `constant_keyword` field type ([#14711](https://github.com/opensearch-project/OpenSearch/pull/14711))
1919
- Add took time to request nodes stats ([#15054](https://github.com/opensearch-project/OpenSearch/pull/15054))
2020
- [Workload Management] Add Get QueryGroup API Logic ([14709](https://github.com/opensearch-project/OpenSearch/pull/14709))
21+
- [Workload Management] Add Settings for Workload Management feature ([#15028](https://github.com/opensearch-project/OpenSearch/pull/15028))
2122
- [Workload Management] QueryGroup resource tracking framework changes ([#13897](https://github.com/opensearch-project/OpenSearch/pull/13897))
2223
- Support filtering on a large list encoded by bitmap ([#14774](https://github.com/opensearch-project/OpenSearch/pull/14774))
2324
- Add slice execution listeners to SearchOperationListener interface ([#15153](https://github.com/opensearch-project/OpenSearch/pull/15153))

server/src/main/java/org/opensearch/common/settings/ClusterSettings.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
import org.opensearch.transport.SniffConnectionStrategy;
174174
import org.opensearch.transport.TransportSettings;
175175
import org.opensearch.watcher.ResourceWatcherService;
176+
import org.opensearch.wlm.WorkloadManagementSettings;
176177

177178
import java.util.Arrays;
178179
import java.util.Collections;
@@ -766,7 +767,13 @@ public void apply(Settings value, Settings current, Settings previous) {
766767
// Composite index settings
767768
CompositeIndexSettings.STAR_TREE_INDEX_ENABLED_SETTING,
768769

769-
SystemTemplatesService.SETTING_APPLICATION_BASED_CONFIGURATION_TEMPLATES_ENABLED
770+
SystemTemplatesService.SETTING_APPLICATION_BASED_CONFIGURATION_TEMPLATES_ENABLED,
771+
772+
// WorkloadManagement settings
773+
WorkloadManagementSettings.NODE_LEVEL_CPU_REJECTION_THRESHOLD,
774+
WorkloadManagementSettings.NODE_LEVEL_CPU_CANCELLATION_THRESHOLD,
775+
WorkloadManagementSettings.NODE_LEVEL_MEMORY_REJECTION_THRESHOLD,
776+
WorkloadManagementSettings.NODE_LEVEL_MEMORY_CANCELLATION_THRESHOLD
770777
)
771778
)
772779
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
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;
10+
11+
import org.opensearch.common.settings.ClusterSettings;
12+
import org.opensearch.common.settings.Setting;
13+
import org.opensearch.common.settings.Settings;
14+
15+
/**
16+
* Main class to declare Workload Management related settings
17+
*/
18+
public class WorkloadManagementSettings {
19+
private static final Double DEFAULT_NODE_LEVEL_MEMORY_REJECTION_THRESHOLD = 0.8;
20+
private static final Double DEFAULT_NODE_LEVEL_MEMORY_CANCELLATION_THRESHOLD = 0.9;
21+
private static final Double DEFAULT_NODE_LEVEL_CPU_REJECTION_THRESHOLD = 0.8;
22+
private static final Double DEFAULT_NODE_LEVEL_CPU_CANCELLATION_THRESHOLD = 0.9;
23+
public static final double NODE_LEVEL_MEMORY_CANCELLATION_THRESHOLD_MAX_VALUE = 0.95;
24+
public static final double NODE_LEVEL_MEMORY_REJECTION_THRESHOLD_MAX_VALUE = 0.9;
25+
public static final double NODE_LEVEL_CPU_CANCELLATION_THRESHOLD_MAX_VALUE = 0.95;
26+
public static final double NODE_LEVEL_CPU_REJECTION_THRESHOLD_MAX_VALUE = 0.9;
27+
28+
private Double nodeLevelMemoryCancellationThreshold;
29+
private Double nodeLevelMemoryRejectionThreshold;
30+
private Double nodeLevelCpuCancellationThreshold;
31+
private Double nodeLevelCpuRejectionThreshold;
32+
33+
/**
34+
* Setting name for node level memory based rejection threshold for QueryGroup service
35+
*/
36+
public static final String NODE_MEMORY_REJECTION_THRESHOLD_SETTING_NAME = "wlm.query_group.node.memory_rejection_threshold";
37+
/**
38+
* Setting to control the memory based rejection threshold
39+
*/
40+
public static final Setting<Double> NODE_LEVEL_MEMORY_REJECTION_THRESHOLD = Setting.doubleSetting(
41+
NODE_MEMORY_REJECTION_THRESHOLD_SETTING_NAME,
42+
DEFAULT_NODE_LEVEL_MEMORY_REJECTION_THRESHOLD,
43+
Setting.Property.Dynamic,
44+
Setting.Property.NodeScope
45+
);
46+
/**
47+
* Setting name for node level cpu based rejection threshold for QueryGroup service
48+
*/
49+
public static final String NODE_CPU_REJECTION_THRESHOLD_SETTING_NAME = "wlm.query_group.node.cpu_rejection_threshold";
50+
/**
51+
* Setting to control the cpu based rejection threshold
52+
*/
53+
public static final Setting<Double> NODE_LEVEL_CPU_REJECTION_THRESHOLD = Setting.doubleSetting(
54+
NODE_CPU_REJECTION_THRESHOLD_SETTING_NAME,
55+
DEFAULT_NODE_LEVEL_CPU_REJECTION_THRESHOLD,
56+
Setting.Property.Dynamic,
57+
Setting.Property.NodeScope
58+
);
59+
/**
60+
* Setting name for node level memory based cancellation threshold for QueryGroup service
61+
*/
62+
public static final String NODE_MEMORY_CANCELLATION_THRESHOLD_SETTING_NAME = "wlm.query_group.node.memory_cancellation_threshold";
63+
/**
64+
* Setting to control the memory based cancellation threshold
65+
*/
66+
public static final Setting<Double> NODE_LEVEL_MEMORY_CANCELLATION_THRESHOLD = Setting.doubleSetting(
67+
NODE_MEMORY_CANCELLATION_THRESHOLD_SETTING_NAME,
68+
DEFAULT_NODE_LEVEL_MEMORY_CANCELLATION_THRESHOLD,
69+
Setting.Property.Dynamic,
70+
Setting.Property.NodeScope
71+
);
72+
/**
73+
* Setting name for node level cpu based cancellation threshold for QueryGroup service
74+
*/
75+
public static final String NODE_CPU_CANCELLATION_THRESHOLD_SETTING_NAME = "wlm.query_group.node.cpu_cancellation_threshold";
76+
/**
77+
* Setting to control the cpu based cancellation threshold
78+
*/
79+
public static final Setting<Double> NODE_LEVEL_CPU_CANCELLATION_THRESHOLD = Setting.doubleSetting(
80+
NODE_CPU_CANCELLATION_THRESHOLD_SETTING_NAME,
81+
DEFAULT_NODE_LEVEL_CPU_CANCELLATION_THRESHOLD,
82+
Setting.Property.Dynamic,
83+
Setting.Property.NodeScope
84+
);
85+
86+
/**
87+
* QueryGroup service settings constructor
88+
* @param settings - QueryGroup service settings
89+
* @param clusterSettings - QueryGroup cluster settings
90+
*/
91+
public WorkloadManagementSettings(Settings settings, ClusterSettings clusterSettings) {
92+
nodeLevelMemoryCancellationThreshold = NODE_LEVEL_MEMORY_CANCELLATION_THRESHOLD.get(settings);
93+
nodeLevelMemoryRejectionThreshold = NODE_LEVEL_MEMORY_REJECTION_THRESHOLD.get(settings);
94+
nodeLevelCpuCancellationThreshold = NODE_LEVEL_CPU_CANCELLATION_THRESHOLD.get(settings);
95+
nodeLevelCpuRejectionThreshold = NODE_LEVEL_CPU_REJECTION_THRESHOLD.get(settings);
96+
97+
ensureRejectionThresholdIsLessThanCancellation(
98+
nodeLevelMemoryRejectionThreshold,
99+
nodeLevelMemoryCancellationThreshold,
100+
NODE_MEMORY_REJECTION_THRESHOLD_SETTING_NAME,
101+
NODE_MEMORY_CANCELLATION_THRESHOLD_SETTING_NAME
102+
);
103+
ensureRejectionThresholdIsLessThanCancellation(
104+
nodeLevelCpuRejectionThreshold,
105+
nodeLevelCpuCancellationThreshold,
106+
NODE_CPU_REJECTION_THRESHOLD_SETTING_NAME,
107+
NODE_CPU_CANCELLATION_THRESHOLD_SETTING_NAME
108+
);
109+
110+
clusterSettings.addSettingsUpdateConsumer(NODE_LEVEL_MEMORY_CANCELLATION_THRESHOLD, this::setNodeLevelMemoryCancellationThreshold);
111+
clusterSettings.addSettingsUpdateConsumer(NODE_LEVEL_MEMORY_REJECTION_THRESHOLD, this::setNodeLevelMemoryRejectionThreshold);
112+
clusterSettings.addSettingsUpdateConsumer(NODE_LEVEL_CPU_CANCELLATION_THRESHOLD, this::setNodeLevelCpuCancellationThreshold);
113+
clusterSettings.addSettingsUpdateConsumer(NODE_LEVEL_CPU_REJECTION_THRESHOLD, this::setNodeLevelCpuRejectionThreshold);
114+
}
115+
116+
/**
117+
* Method to get the node level memory based cancellation threshold
118+
* @return current node level memory based cancellation threshold
119+
*/
120+
public Double getNodeLevelMemoryCancellationThreshold() {
121+
return nodeLevelMemoryCancellationThreshold;
122+
}
123+
124+
/**
125+
* Method to set the node level memory based cancellation threshold
126+
* @param nodeLevelMemoryCancellationThreshold sets the new node level memory based cancellation threshold
127+
* @throws IllegalArgumentException if the value is &gt; 0.95 and cancellation &lt; rejection threshold
128+
*/
129+
public void setNodeLevelMemoryCancellationThreshold(Double nodeLevelMemoryCancellationThreshold) {
130+
if (Double.compare(nodeLevelMemoryCancellationThreshold, NODE_LEVEL_MEMORY_CANCELLATION_THRESHOLD_MAX_VALUE) > 0) {
131+
throw new IllegalArgumentException(
132+
NODE_MEMORY_CANCELLATION_THRESHOLD_SETTING_NAME + " value cannot be greater than 0.95 as it can result in a node drop"
133+
);
134+
}
135+
136+
ensureRejectionThresholdIsLessThanCancellation(
137+
nodeLevelMemoryRejectionThreshold,
138+
nodeLevelMemoryCancellationThreshold,
139+
NODE_MEMORY_REJECTION_THRESHOLD_SETTING_NAME,
140+
NODE_MEMORY_CANCELLATION_THRESHOLD_SETTING_NAME
141+
);
142+
143+
this.nodeLevelMemoryCancellationThreshold = nodeLevelMemoryCancellationThreshold;
144+
}
145+
146+
/**
147+
* Method to get the node level cpu based cancellation threshold
148+
* @return current node level cpu based cancellation threshold
149+
*/
150+
public Double getNodeLevelCpuCancellationThreshold() {
151+
return nodeLevelCpuCancellationThreshold;
152+
}
153+
154+
/**
155+
* Method to set the node level cpu based cancellation threshold
156+
* @param nodeLevelCpuCancellationThreshold sets the new node level cpu based cancellation threshold
157+
* @throws IllegalArgumentException if the value is &gt; 0.95 and cancellation &lt; rejection threshold
158+
*/
159+
public void setNodeLevelCpuCancellationThreshold(Double nodeLevelCpuCancellationThreshold) {
160+
if (Double.compare(nodeLevelCpuCancellationThreshold, NODE_LEVEL_CPU_CANCELLATION_THRESHOLD_MAX_VALUE) > 0) {
161+
throw new IllegalArgumentException(
162+
NODE_CPU_CANCELLATION_THRESHOLD_SETTING_NAME + " value cannot be greater than 0.95 as it can result in a node drop"
163+
);
164+
}
165+
166+
ensureRejectionThresholdIsLessThanCancellation(
167+
nodeLevelCpuRejectionThreshold,
168+
nodeLevelCpuCancellationThreshold,
169+
NODE_CPU_REJECTION_THRESHOLD_SETTING_NAME,
170+
NODE_CPU_CANCELLATION_THRESHOLD_SETTING_NAME
171+
);
172+
173+
this.nodeLevelCpuCancellationThreshold = nodeLevelCpuCancellationThreshold;
174+
}
175+
176+
/**
177+
* Method to get the memory based node level rejection threshold
178+
* @return the current memory based node level rejection threshold
179+
*/
180+
public Double getNodeLevelMemoryRejectionThreshold() {
181+
return nodeLevelMemoryRejectionThreshold;
182+
}
183+
184+
/**
185+
* Method to set the node level memory based rejection threshold
186+
* @param nodeLevelMemoryRejectionThreshold sets the new memory based rejection threshold
187+
* @throws IllegalArgumentException if rejection &gt; 0.90 and rejection &lt; cancellation threshold
188+
*/
189+
public void setNodeLevelMemoryRejectionThreshold(Double nodeLevelMemoryRejectionThreshold) {
190+
if (Double.compare(nodeLevelMemoryRejectionThreshold, NODE_LEVEL_MEMORY_REJECTION_THRESHOLD_MAX_VALUE) > 0) {
191+
throw new IllegalArgumentException(
192+
NODE_MEMORY_REJECTION_THRESHOLD_SETTING_NAME + " value cannot be greater than 0.90 as it can result in a node drop"
193+
);
194+
}
195+
196+
ensureRejectionThresholdIsLessThanCancellation(
197+
nodeLevelMemoryRejectionThreshold,
198+
nodeLevelMemoryCancellationThreshold,
199+
NODE_MEMORY_REJECTION_THRESHOLD_SETTING_NAME,
200+
NODE_MEMORY_CANCELLATION_THRESHOLD_SETTING_NAME
201+
);
202+
203+
this.nodeLevelMemoryRejectionThreshold = nodeLevelMemoryRejectionThreshold;
204+
}
205+
206+
/**
207+
* Method to get the cpu based node level rejection threshold
208+
* @return the current cpu based node level rejection threshold
209+
*/
210+
public Double getNodeLevelCpuRejectionThreshold() {
211+
return nodeLevelCpuRejectionThreshold;
212+
}
213+
214+
/**
215+
* Method to set the node level cpu based rejection threshold
216+
* @param nodeLevelCpuRejectionThreshold sets the new cpu based rejection threshold
217+
* @throws IllegalArgumentException if rejection &gt; 0.90 and rejection &lt; cancellation threshold
218+
*/
219+
public void setNodeLevelCpuRejectionThreshold(Double nodeLevelCpuRejectionThreshold) {
220+
if (Double.compare(nodeLevelCpuRejectionThreshold, NODE_LEVEL_CPU_REJECTION_THRESHOLD_MAX_VALUE) > 0) {
221+
throw new IllegalArgumentException(
222+
NODE_CPU_REJECTION_THRESHOLD_SETTING_NAME + " value cannot be greater than 0.90 as it can result in a node drop"
223+
);
224+
}
225+
226+
ensureRejectionThresholdIsLessThanCancellation(
227+
nodeLevelCpuRejectionThreshold,
228+
nodeLevelCpuCancellationThreshold,
229+
NODE_CPU_REJECTION_THRESHOLD_SETTING_NAME,
230+
NODE_CPU_CANCELLATION_THRESHOLD_SETTING_NAME
231+
);
232+
233+
this.nodeLevelCpuRejectionThreshold = nodeLevelCpuRejectionThreshold;
234+
}
235+
236+
/**
237+
* Method to validate that the cancellation threshold is greater than or equal to rejection threshold
238+
* @param nodeLevelRejectionThreshold rejection threshold to be compared
239+
* @param nodeLevelCancellationThreshold cancellation threshold to be compared
240+
* @param rejectionThresholdSettingName name of the rejection threshold setting
241+
* @param cancellationThresholdSettingName name of the cancellation threshold setting
242+
* @throws IllegalArgumentException if cancellation threshold is less than rejection threshold
243+
*/
244+
private void ensureRejectionThresholdIsLessThanCancellation(
245+
Double nodeLevelRejectionThreshold,
246+
Double nodeLevelCancellationThreshold,
247+
String rejectionThresholdSettingName,
248+
String cancellationThresholdSettingName
249+
) {
250+
if (Double.compare(nodeLevelCancellationThreshold, nodeLevelRejectionThreshold) < 0) {
251+
throw new IllegalArgumentException(
252+
cancellationThresholdSettingName + " value should not be less than " + rejectionThresholdSettingName
253+
);
254+
}
255+
}
256+
}

0 commit comments

Comments
 (0)