|
| 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 > 0.95 and cancellation < 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 > 0.95 and cancellation < 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 > 0.90 and rejection < 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 > 0.90 and rejection < 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