-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate with CPU admission controller for cluster-manager Read API's.
The admission control is enforced at the transport layer.
- Loading branch information
Showing
8 changed files
with
273 additions
and
8 deletions.
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
...Test/java/org/opensearch/ratelimitting/admissioncontrol/AdmissionForClusterManagerIT.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,135 @@ | ||
/* | ||
* 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.action.admin.indices.alias.get.GetAliasesRequest; | ||
import org.opensearch.action.admin.indices.alias.get.GetAliasesResponse; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.unit.TimeValue; | ||
import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException; | ||
import org.opensearch.node.ResourceUsageCollectorService; | ||
import org.opensearch.node.resource.tracker.ResourceTrackerSettings; | ||
import org.opensearch.ratelimitting.admissioncontrol.enums.AdmissionControlActionType; | ||
import org.opensearch.ratelimitting.admissioncontrol.enums.AdmissionControlMode; | ||
import org.opensearch.ratelimitting.admissioncontrol.stats.AdmissionControllerStats; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
import org.junit.Before; | ||
|
||
import static org.opensearch.ratelimitting.admissioncontrol.AdmissionControlSettings.ADMISSION_CONTROL_TRANSPORT_LAYER_MODE; | ||
import static org.opensearch.ratelimitting.admissioncontrol.settings.CpuBasedAdmissionControllerSettings.CLUSTER_INFO_CPU_USAGE_LIMIT; | ||
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
public class AdmissionForClusterManagerIT extends OpenSearchIntegTestCase { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(AdmissionForClusterManagerIT.class); | ||
|
||
public static final String INDEX_NAME = "test_index"; | ||
|
||
private String clusterManagerNodeId; | ||
private ResourceUsageCollectorService cMResourceCollector; | ||
|
||
private static final Settings DISABLE_ADMISSION_CONTROL = Settings.builder() | ||
.put(ADMISSION_CONTROL_TRANSPORT_LAYER_MODE.getKey(), AdmissionControlMode.DISABLED) | ||
.build(); | ||
|
||
private static final Settings ENFORCE_ADMISSION_CONTROL = Settings.builder() | ||
.put(ResourceTrackerSettings.GLOBAL_CPU_USAGE_AC_WINDOW_DURATION_SETTING.getKey(), TimeValue.timeValueMillis(500)) | ||
.put(ADMISSION_CONTROL_TRANSPORT_LAYER_MODE.getKey(), AdmissionControlMode.ENFORCED) | ||
.put(CLUSTER_INFO_CPU_USAGE_LIMIT.getKey(), 50) | ||
.build(); | ||
|
||
@Before | ||
public void init() { | ||
String clusterManagerNode = internalCluster().startClusterManagerOnlyNode( | ||
Settings.builder().put(DISABLE_ADMISSION_CONTROL).build() | ||
); | ||
internalCluster().startDataOnlyNode(Settings.builder().put(DISABLE_ADMISSION_CONTROL).build()); | ||
|
||
ensureClusterSizeConsistency(); | ||
ensureGreen(); | ||
|
||
// Disable the automatic resource collection | ||
clusterManagerNodeId = internalCluster().clusterService(clusterManagerNode).localNode().getId(); | ||
cMResourceCollector = internalCluster().getClusterManagerNodeInstance(ResourceUsageCollectorService.class); | ||
cMResourceCollector.stop(); | ||
|
||
// Enable admission control | ||
client().admin().cluster().prepareUpdateSettings().setTransientSettings(ENFORCE_ADMISSION_CONTROL).execute().actionGet(); | ||
} | ||
|
||
public void testAdmissionControlEnforced() throws InterruptedException { | ||
cMResourceCollector.collectNodeResourceUsageStats(clusterManagerNodeId, System.currentTimeMillis(), 97, 99); | ||
|
||
// Write API on ClusterManager | ||
assertAcked(prepareCreate("test").setMapping("field", "type=text").setAliases("{\"alias1\" : {}}")); | ||
|
||
// Read API on ClusterManager | ||
GetAliasesRequest aliasesRequest = new GetAliasesRequest(); | ||
aliasesRequest.aliases("alias1"); | ||
try { | ||
dataNodeClient().admin().indices().getAliases(aliasesRequest).actionGet(); | ||
fail("expected failure"); | ||
} catch (Exception e) { | ||
assertTrue(e instanceof OpenSearchRejectedExecutionException); | ||
} | ||
|
||
client().admin().cluster().prepareUpdateSettings().setTransientSettings(DISABLE_ADMISSION_CONTROL).execute().actionGet(); | ||
|
||
GetAliasesResponse getAliasesResponse = dataNodeClient().admin().indices().getAliases(aliasesRequest).actionGet(); | ||
assertThat(getAliasesResponse.getAliases().get("test").size(), equalTo(1)); | ||
|
||
AdmissionControlService admissionControlServicePrimary = internalCluster().getClusterManagerNodeInstance( | ||
AdmissionControlService.class | ||
); | ||
AdmissionControllerStats admissionStats = admissionControlServicePrimary.stats().getAdmissionControllerStatsList().get(0); | ||
assertEquals(admissionStats.rejectionCount.get(AdmissionControlActionType.CLUSTER_INFO.getType()).longValue(), 1); | ||
assertNull(admissionStats.rejectionCount.get(AdmissionControlActionType.SEARCH.getType())); | ||
assertNull(admissionStats.rejectionCount.get(AdmissionControlActionType.INDEXING.getType())); | ||
} | ||
|
||
public void testAdmissionControlEnabledOnNoBreach() throws InterruptedException { | ||
// CPU usage is less than threshold 50% | ||
cMResourceCollector.collectNodeResourceUsageStats(clusterManagerNodeId, System.currentTimeMillis(), 97, 35); | ||
|
||
// Write API on ClusterManager | ||
assertAcked(prepareCreate("test").setMapping("field", "type=text").setAliases("{\"alias1\" : {}}").execute().actionGet()); | ||
|
||
// Read API on ClusterManager | ||
GetAliasesRequest aliasesRequest = new GetAliasesRequest(); | ||
aliasesRequest.aliases("alias1"); | ||
GetAliasesResponse getAliasesResponse = dataNodeClient().admin().indices().getAliases(aliasesRequest).actionGet(); | ||
assertThat(getAliasesResponse.getAliases().get("test").size(), equalTo(1)); | ||
} | ||
|
||
public void testAdmissionControlDisabledOnBreach() throws InterruptedException { | ||
client().admin().cluster().prepareUpdateSettings().setTransientSettings(DISABLE_ADMISSION_CONTROL).execute().actionGet(); | ||
|
||
cMResourceCollector.collectNodeResourceUsageStats(clusterManagerNodeId, System.currentTimeMillis(), 97, 97); | ||
|
||
// Write API on ClusterManager | ||
assertAcked(prepareCreate("test").setMapping("field", "type=text").setAliases("{\"alias1\" : {}}").execute().actionGet()); | ||
|
||
// Read API on ClusterManager | ||
GetAliasesRequest aliasesRequest = new GetAliasesRequest(); | ||
aliasesRequest.aliases("alias1"); | ||
GetAliasesResponse getAliasesResponse = dataNodeClient().admin().indices().getAliases(aliasesRequest).actionGet(); | ||
assertThat(getAliasesResponse.getAliases().get("test").size(), equalTo(1)); | ||
|
||
} | ||
|
||
@Override | ||
public void tearDown() throws Exception { | ||
client().admin().cluster().prepareUpdateSettings().setTransientSettings(DISABLE_ADMISSION_CONTROL).execute().actionGet(); | ||
super.tearDown(); | ||
} | ||
} |
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
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
Oops, something went wrong.