Skip to content

Commit

Permalink
add validity checks for settings
Browse files Browse the repository at this point in the history
Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com>
  • Loading branch information
kaushalmahi12 committed Apr 2, 2024
1 parent f94504d commit 239e5ec
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,23 @@ public class QuerySandboxServiceSettings {
Setting.Property.Dynamic,
Setting.Property.NodeScope
);
public static final String QUERY_SANDBOX_SERVICE_RUN_INTERVAL_MILLIS_SETTING_NAME = "query_sandbox.service.run_interval_millis";
private static final Setting<Long> QSB_RUN_INTERVAL_SETTING = Setting.longSetting(
"query_sandbox.service.run_interval_millis",
QUERY_SANDBOX_SERVICE_RUN_INTERVAL_MILLIS_SETTING_NAME,
DEFAULT_RUN_INTERVAL_MILLIS,
1,
Setting.Property.NodeScope
);

public static final String QUERY_SANDBOX_NODE_REJECTION_THRESHOLD_SETTING_NAME = "query_sandbox.node.rejection_threshold";
public static final Setting<Double> NODE_LEVEL_REJECTION_THRESHOLD = Setting.doubleSetting(
"query_sandbox.node.rejection_threshold",
QUERY_SANDBOX_NODE_REJECTION_THRESHOLD_SETTING_NAME,
DEFAULT_NODE_LEVEL_REJECTION_QUERY_SANDBOX_THRESHOLD,
Setting.Property.NodeScope
);
public static final String QUERY_SANDBOX_NODE_CANCELLATION_THRESHOLD_SETTING_NAME = "query_sandbox.node.cancellation_threshold";
public static final Setting<Double> NODE_LEVEL_CANCELLATION_THRESHOLD = Setting.doubleSetting(
"query_sandbox.node.cancellation_threshold",
QUERY_SANDBOX_NODE_CANCELLATION_THRESHOLD_SETTING_NAME,
DEFAULT_NODE_LEVEL_CANCELLATION_QUERY_SANDBOX_THRESHOLD,
Setting.Property.NodeScope
);
Expand All @@ -68,7 +71,6 @@ public TimeValue getRunIntervalMillis() {
return runIntervalMillis;
}


public void setMaxSandboxCount(int newMaxSandboxCount) {
if (newMaxSandboxCount < 0) {
throw new IllegalArgumentException("node.sandbox.max_count can't be negative");
Expand All @@ -77,6 +79,11 @@ public void setMaxSandboxCount(int newMaxSandboxCount) {
}

public void setRunIntervalMillis(TimeValue runIntervalMillis) {
if (runIntervalMillis.getMillis() < 100 && runIntervalMillis.getMillis() < 0) {
throw new IllegalArgumentException(
QUERY_SANDBOX_SERVICE_RUN_INTERVAL_MILLIS_SETTING_NAME + " can't be negative and should be greater than 100ms"
);
}
this.runIntervalMillis = runIntervalMillis;
}

Expand All @@ -85,6 +92,15 @@ public Double getNodeLevelJvmCancellationThreshold() {
}

public void setNodeLevelJvmCancellationThreshold(Double nodeLevelJvmCancellationThreshold) {
if (nodeLevelJvmCancellationThreshold > 0.95) {
throw new IllegalArgumentException(
QUERY_SANDBOX_NODE_CANCELLATION_THRESHOLD_SETTING_NAME
+ " value should not be greater than 0.95 as it pose a threat of node drop"
);
}

ensureRejectionThresholdIsLessThanCancellation(nodeLevelJvmRejectionThreshold, nodeLevelJvmCancellationThreshold);

this.nodeLevelJvmCancellationThreshold = nodeLevelJvmCancellationThreshold;
}

Expand All @@ -93,9 +109,30 @@ public Double getNodeLevelJvmRejectionThreshold() {
}

public void setNodeLevelJvmRejectionThreshold(Double nodeLevelJvmRejectionThreshold) {
if (nodeLevelJvmRejectionThreshold > 0.90) {
throw new IllegalArgumentException(
QUERY_SANDBOX_NODE_REJECTION_THRESHOLD_SETTING_NAME + " value not be greater than 0.90 as it pose a threat of node drop"
);
}

ensureRejectionThresholdIsLessThanCancellation(nodeLevelJvmRejectionThreshold, nodeLevelJvmCancellationThreshold);

this.nodeLevelJvmRejectionThreshold = nodeLevelJvmRejectionThreshold;
}

private void ensureRejectionThresholdIsLessThanCancellation(
Double nodeLevelJvmRejectionThreshold,
Double nodeLevelJvmCancellationThreshold
) {
if (nodeLevelJvmCancellationThreshold < nodeLevelJvmRejectionThreshold) {
throw new IllegalArgumentException(
QUERY_SANDBOX_NODE_CANCELLATION_THRESHOLD_SETTING_NAME
+ " value should not be less than "
+ QUERY_SANDBOX_NODE_REJECTION_THRESHOLD_SETTING_NAME
);
}
}

public int getMaxSandboxCount() {
return maxSandboxCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

package org.opensearch.search.sandbox;

import org.opensearch.action.ActionRequest;
import org.opensearch.action.search.SearchRequest;

/**
* This class is used to classify co-ordinator search reqyests into sandboxes
Expand All @@ -17,10 +17,10 @@ public class RequestSandboxClassifier {

/**
*
* @param request is a coordinator request task
* @return List of matching sandboxes based on user firing the request
* @param request is a coordinator search request
* @return matching sandboxId based on request attributes
*/
public String resolveSandboxFor(final ActionRequest request) {
public String resolveSandboxFor(final SearchRequest request) {
return "dummy";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
package org.opensearch.search.sandbox;public class SandboxStatsHolder {
/*
* 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.search.sandbox;

/**
* Main class to hold sandbox level stats
*/
public class SandboxStatsHolder {
// TODO: We will fill in this class when raising the stats PR
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.LongSupplier;
import java.util.stream.Collectors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.Map;

/**
* Main interface for calculation the score of a sandbox and request match
* Main interface for calculating the score of a sandbox and request match
*/
public interface SandboxMatchScorer {
public double score(Map<String, String> requestAttributes, Map<String, String> sandboxAttributes) throws IllegalArgumentException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
package org.opensearch.search.sandbox.matcher;

/**
* This interface is mainly for calculating the match score of two strings
* This interface id for calculating the match score of two strings, It can be generalised into different approaches
*
*/
public interface StringMatchScorer {
public double score(String input, String target) throws IllegalArgumentException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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.
*/

/**
* This package encapsulates query sandboxing related interfaces and classes
*/
package org.opensearch.search.sandbox;

0 comments on commit 239e5ec

Please sign in to comment.