-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Added changes for AdmissionControl Interceptor and AdmissionControlService for RateLimiting #9286
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
Merged
Bukhtawar
merged 6 commits into
opensearch-project:main
from
ajaymovva:feature/admission-controller
Oct 21, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6547a4e
Admission Controller Module Transport Interceptor Initial Commit
eb53cd8
Added AdmissionController Interceptor in Core and implemented CPU Bas…
3a8e16a
Addressing Comments
bdf365b
Addressing Comments
7848e7f
Addressing Comments
fa39f9a
Addressing Comments
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
104 changes: 104 additions & 0 deletions
104
.../src/main/java/org/opensearch/ratelimitting/admissioncontrol/AdmissionControlService.java
This file contains hidden or 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,104 @@ | ||
| /* | ||
| * 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.ratelimitting.admissioncontrol; | ||
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.opensearch.common.settings.ClusterSettings; | ||
| import org.opensearch.common.settings.Settings; | ||
| import org.opensearch.ratelimitting.admissioncontrol.controllers.AdmissionController; | ||
| import org.opensearch.ratelimitting.admissioncontrol.controllers.CPUBasedAdmissionController; | ||
| import org.opensearch.threadpool.ThreadPool; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.ConcurrentMap; | ||
|
|
||
| import static org.opensearch.ratelimitting.admissioncontrol.settings.CPUBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER; | ||
|
|
||
| /** | ||
| * Admission control Service that bootstraps and manages all the Admission Controllers in OpenSearch. | ||
| */ | ||
| public class AdmissionControlService { | ||
| private final ThreadPool threadPool; | ||
| public final AdmissionControlSettings admissionControlSettings; | ||
| private final ConcurrentMap<String, AdmissionController> ADMISSION_CONTROLLERS; | ||
| private static final Logger logger = LogManager.getLogger(AdmissionControlService.class); | ||
| private final ClusterSettings clusterSettings; | ||
| private final Settings settings; | ||
|
|
||
| /** | ||
| * | ||
| * @param settings Immutable settings instance | ||
| * @param clusterSettings ClusterSettings Instance | ||
| * @param threadPool ThreadPool Instance | ||
| */ | ||
| public AdmissionControlService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool) { | ||
| this.threadPool = threadPool; | ||
| this.admissionControlSettings = new AdmissionControlSettings(clusterSettings, settings); | ||
| this.ADMISSION_CONTROLLERS = new ConcurrentHashMap<>(); | ||
| this.clusterSettings = clusterSettings; | ||
| this.settings = settings; | ||
| this.initialise(); | ||
| } | ||
|
|
||
| /** | ||
| * Initialise and Register all the admissionControllers | ||
| */ | ||
| private void initialise() { | ||
| // Initialise different type of admission controllers | ||
| registerAdmissionController(CPU_BASED_ADMISSION_CONTROLLER); | ||
| } | ||
|
|
||
| /** | ||
| * Handler to trigger registered admissionController | ||
| */ | ||
| public void applyTransportAdmissionControl(String action) { | ||
| this.ADMISSION_CONTROLLERS.forEach((name, admissionController) -> { admissionController.apply(action); }); | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @param admissionControllerName admissionControllerName to register into the service. | ||
| */ | ||
| public void registerAdmissionController(String admissionControllerName) { | ||
| AdmissionController admissionController = this.controllerFactory(admissionControllerName); | ||
| this.ADMISSION_CONTROLLERS.put(admissionControllerName, admissionController); | ||
| } | ||
|
|
||
| /** | ||
| * @return AdmissionController Instance | ||
| */ | ||
| private AdmissionController controllerFactory(String admissionControllerName) { | ||
ajaymovva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| switch (admissionControllerName) { | ||
| case CPU_BASED_ADMISSION_CONTROLLER: | ||
| return new CPUBasedAdmissionController(admissionControllerName, this.settings, this.clusterSettings); | ||
| default: | ||
| throw new IllegalArgumentException("Not Supported AdmissionController : " + admissionControllerName); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @return list of the registered admissionControllers | ||
| */ | ||
| public List<AdmissionController> getAdmissionControllers() { | ||
| return new ArrayList<>(this.ADMISSION_CONTROLLERS.values()); | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @param controllerName name of the admissionController | ||
| * @return instance of the AdmissionController Instance | ||
| */ | ||
| public AdmissionController getAdmissionController(String controllerName) { | ||
| return this.ADMISSION_CONTROLLERS.getOrDefault(controllerName, null); | ||
| } | ||
| } | ||
83 changes: 83 additions & 0 deletions
83
...src/main/java/org/opensearch/ratelimitting/admissioncontrol/AdmissionControlSettings.java
This file contains hidden or 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,83 @@ | ||
| /* | ||
| * 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.ratelimitting.admissioncontrol; | ||
|
|
||
| import org.opensearch.common.settings.ClusterSettings; | ||
| import org.opensearch.common.settings.Setting; | ||
| import org.opensearch.common.settings.Settings; | ||
| import org.opensearch.ratelimitting.admissioncontrol.enums.AdmissionControlMode; | ||
|
|
||
| /** | ||
| * Settings related to admission control. | ||
| * @opensearch.internal | ||
| */ | ||
| public final class AdmissionControlSettings { | ||
ajaymovva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Default parameters for the AdmissionControlSettings | ||
| */ | ||
| public static class Defaults { | ||
| public static final String MODE = "disabled"; | ||
| } | ||
|
|
||
| /** | ||
| * Feature level setting to operate in shadow-mode or in enforced-mode. If enforced field is set | ||
| * rejection will be performed, otherwise only rejection metrics will be populated. | ||
| */ | ||
| public static final Setting<AdmissionControlMode> ADMISSION_CONTROL_TRANSPORT_LAYER_MODE = new Setting<>( | ||
| "admission_control.transport.mode", | ||
| Defaults.MODE, | ||
| AdmissionControlMode::fromName, | ||
| Setting.Property.Dynamic, | ||
| Setting.Property.NodeScope | ||
| ); | ||
|
|
||
| private volatile AdmissionControlMode transportLayeradmissionControlMode; | ||
|
|
||
| /** | ||
| * @param clusterSettings clusterSettings Instance | ||
| * @param settings settings instance | ||
| */ | ||
| public AdmissionControlSettings(ClusterSettings clusterSettings, Settings settings) { | ||
| this.transportLayeradmissionControlMode = ADMISSION_CONTROL_TRANSPORT_LAYER_MODE.get(settings); | ||
| clusterSettings.addSettingsUpdateConsumer(ADMISSION_CONTROL_TRANSPORT_LAYER_MODE, this::setAdmissionControlTransportLayerMode); | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @param admissionControlMode update the mode of admission control feature | ||
| */ | ||
| private void setAdmissionControlTransportLayerMode(AdmissionControlMode admissionControlMode) { | ||
| this.transportLayeradmissionControlMode = admissionControlMode; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @return return the default mode of the admissionControl | ||
| */ | ||
| public AdmissionControlMode getAdmissionControlTransportLayerMode() { | ||
| return this.transportLayeradmissionControlMode; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @return true based on the admission control feature is enforced else false | ||
| */ | ||
| public Boolean isTransportLayerAdmissionControlEnforced() { | ||
| return this.transportLayeradmissionControlMode == AdmissionControlMode.ENFORCED; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @return true based on the admission control feature is enabled else false | ||
| */ | ||
| public Boolean isTransportLayerAdmissionControlEnabled() { | ||
| return this.transportLayeradmissionControlMode != AdmissionControlMode.DISABLED; | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.