-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor settings management for plugin #1393
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3adf179
Separate knn settings defs from util methods
jmazanec15 02e435e
Organize KNNSettings for refactoring
jmazanec15 a7edf5a
Move SpaceTypeValidator to SpaceType class
jmazanec15 db0ece4
Move onIndexModule into plugin
jmazanec15 3e5303f
Move updating of cb out of KNNSettings
jmazanec15 500385d
Move parsers back into defs
jmazanec15 0af13a2
Move setting consumer to NativeMemoryCacheManager
jmazanec15 4b0c355
Move setting list into KNNPlugin
jmazanec15 fe02ca3
Remote setClusterService for KNNSettings
jmazanec15 b54d276
Move setting definitions to respective classes
jmazanec15 d0b22d1
Relocate getter utility methods
jmazanec15 bb5720b
Move dynamic settings to NativeCacheManager
jmazanec15 183a286
Remove the KNNSettings class
jmazanec15 866886e
Fix broken test case
jmazanec15 57d085b
Remove space type validator class
jmazanec15 4e5b546
Update changelog
jmazanec15 4354683
Address minor PR comments
jmazanec15 cb5c451
Move index_thread_qty to KNNCodecService
jmazanec15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
140 changes: 140 additions & 0 deletions
140
src/main/java/org/opensearch/knn/index/KNNCircuitBreakerUtil.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,140 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.index; | ||
|
||
import lombok.extern.log4j.Log4j2; | ||
import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; | ||
import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.unit.TimeValue; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.core.common.unit.ByteSizeValue; | ||
import org.opensearch.knn.plugin.stats.StatNames; | ||
import org.opensearch.knn.plugin.transport.KNNStatsAction; | ||
import org.opensearch.knn.plugin.transport.KNNStatsNodeResponse; | ||
import org.opensearch.knn.plugin.transport.KNNStatsRequest; | ||
import org.opensearch.knn.plugin.transport.KNNStatsResponse; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import static org.opensearch.knn.index.KNNCircuitBreaker.KNN_CIRCUIT_BREAKER_TRIGGERED; | ||
import static org.opensearch.knn.index.KNNCircuitBreaker.KNN_CIRCUIT_BREAKER_TRIGGERED_SETTING; | ||
import static org.opensearch.knn.index.KNNCircuitBreaker.KNN_CIRCUIT_BREAKER_UNSET_PERCENTAGE_SETTING; | ||
import static org.opensearch.knn.index.KNNCircuitBreaker.KNN_MEMORY_CIRCUIT_BREAKER_LIMIT_SETTING; | ||
|
||
/** | ||
* Singleton utility class to interact with the circuit breaker. | ||
*/ | ||
@Log4j2 | ||
public class KNNCircuitBreakerUtil { | ||
private static KNNCircuitBreakerUtil instance; | ||
|
||
private KNNCircuitBreakerUtil() {} | ||
|
||
private Client client; | ||
|
||
/** | ||
* Return instance of the KNNCircuitBreakerUtil, must be initialized first for proper usage | ||
* @return instance of KNNCircuitBreakerUtil | ||
*/ | ||
public static synchronized KNNCircuitBreakerUtil instance() { | ||
if (instance == null) { | ||
instance = new KNNCircuitBreakerUtil(); | ||
} | ||
return instance; | ||
} | ||
|
||
/** | ||
* | ||
* @param client client for interfacing with the cluster | ||
*/ | ||
public void initialize(final Client client) { | ||
this.client = Objects.requireNonNull(client, "client must not be null"); | ||
} | ||
|
||
/** | ||
* Get the nodes in cluster that have reached the maximum capacity | ||
* | ||
* @return list of IDs for nodes that have reached the max capacity | ||
*/ | ||
public List<String> getNodesAtMaxCapacity() throws ExecutionException, InterruptedException { | ||
KNNStatsRequest knnStatsRequest = new KNNStatsRequest(); | ||
knnStatsRequest.addStat(StatNames.CACHE_CAPACITY_REACHED.getName()); | ||
knnStatsRequest.timeout(new TimeValue(1000 * 10)); // 10 second timeout | ||
|
||
KNNStatsResponse knnStatsResponse = client.execute(KNNStatsAction.INSTANCE, knnStatsRequest).get(); | ||
List<KNNStatsNodeResponse> nodeResponses = knnStatsResponse.getNodes(); | ||
|
||
List<String> nodesAtMaxCapacity = new ArrayList<>(); | ||
for (KNNStatsNodeResponse nodeResponse : nodeResponses) { | ||
if ((Boolean) nodeResponse.getStatsMap().get(StatNames.CACHE_CAPACITY_REACHED.getName())) { | ||
nodesAtMaxCapacity.add(nodeResponse.getNode().getId()); | ||
} | ||
} | ||
|
||
return nodesAtMaxCapacity; | ||
} | ||
|
||
/** | ||
* Updates knn.circuit_breaker.triggered setting to true/false | ||
* @param flag true/false | ||
*/ | ||
public synchronized void updateCircuitBreakerSettings(boolean flag) { | ||
ClusterUpdateSettingsRequest clusterUpdateSettingsRequest = new ClusterUpdateSettingsRequest(); | ||
Settings circuitBreakerSettings = Settings.builder().put(KNN_CIRCUIT_BREAKER_TRIGGERED, flag).build(); | ||
clusterUpdateSettingsRequest.persistentSettings(circuitBreakerSettings); | ||
client.admin().cluster().updateSettings(clusterUpdateSettingsRequest, new ActionListener<>() { | ||
@Override | ||
public void onResponse(ClusterUpdateSettingsResponse clusterUpdateSettingsResponse) { | ||
log.debug( | ||
"Cluster setting {}, acknowledged: {} ", | ||
clusterUpdateSettingsRequest.persistentSettings(), | ||
clusterUpdateSettingsResponse.isAcknowledged() | ||
); | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
log.info( | ||
"Exception while updating circuit breaker setting {} to {}", | ||
clusterUpdateSettingsRequest.persistentSettings(), | ||
e.getMessage() | ||
); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Get if circuit breaker is triggered or not | ||
* | ||
* @return If circuit breaker is enabled for the cluster | ||
*/ | ||
public boolean isCircuitBreakerTriggered() { | ||
return KNNClusterUtil.instance().getClusterSetting(KNN_CIRCUIT_BREAKER_TRIGGERED_SETTING); | ||
} | ||
|
||
/** | ||
* Get value of limit for circuit breaker | ||
* | ||
* @return Value of circuit breaker limit as ByteSizeValue | ||
*/ | ||
public ByteSizeValue getCircuitBreakerLimit() { | ||
return KNNClusterUtil.instance().getClusterSetting(KNN_MEMORY_CIRCUIT_BREAKER_LIMIT_SETTING); | ||
} | ||
|
||
/** | ||
* Get value of circuit breaker unset percentage setting | ||
* | ||
* @return Value as double of unset circuit breaker percentage | ||
*/ | ||
public double getCircuitBreakerUnsetPercentage() { | ||
return KNNClusterUtil.instance().getClusterSetting(KNN_CIRCUIT_BREAKER_UNSET_PERCENTAGE_SETTING); | ||
} | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since initialize is outside object creation, can you add non-null check for client?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure