Skip to content

Commit

Permalink
updated changelog
Browse files Browse the repository at this point in the history
Signed-off-by: Rajiv Kumar Vaidyanathan <[email protected]>
  • Loading branch information
rajiv-kv committed Mar 21, 2024
1 parent e3b7570 commit d9e42b5
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Introduce a new setting `index.check_pending_flush.enabled` to expose the ability to disable the check for pending flushes by write threads ([#12710](https://github.com/opensearch-project/OpenSearch/pull/12710))
- Built-in secure transports support ([#12435](https://github.com/opensearch-project/OpenSearch/pull/12435))
- Lightweight Transport action to verify local term before fetching cluster-state from remote ([#12252](https://github.com/opensearch-project/OpenSearch/pull/12252/))
- Integrate with admission controller for cluster-manager Read API. ([#12496](https://github.com/opensearch-project/OpenSearch/pull/12496))

### Dependencies
- Bump `peter-evans/find-comment` from 2 to 3 ([#12288](https://github.com/opensearch-project/OpenSearch/pull/12288))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.opensearch.node.IoUsageStats;
import org.opensearch.node.ResourceUsageCollectorService;
import org.opensearch.node.resource.tracker.ResourceTrackerSettings;
import org.opensearch.ratelimitting.admissioncontrol.controllers.CpuBasedAdmissionController;
import org.opensearch.ratelimitting.admissioncontrol.enums.AdmissionControlActionType;
import org.opensearch.ratelimitting.admissioncontrol.enums.AdmissionControlMode;
import org.opensearch.ratelimitting.admissioncontrol.stats.AdmissionControllerStats;
Expand All @@ -30,6 +31,8 @@
import org.opensearch.test.rest.FakeRestRequest;
import org.junit.Before;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;

Expand All @@ -50,7 +53,7 @@ public class AdmissionForClusterManagerIT extends OpenSearchIntegTestCase {
private ResourceUsageCollectorService cMResourceCollector;

private static final Settings DISABLE_ADMISSION_CONTROL = Settings.builder()
.put(ADMISSION_CONTROL_TRANSPORT_LAYER_MODE.getKey(), AdmissionControlMode.DISABLED)
.put(ADMISSION_CONTROL_TRANSPORT_LAYER_MODE.getKey(), AdmissionControlMode.DISABLED.getMode())
.build();

private static final Settings ENFORCE_ADMISSION_CONTROL = Settings.builder()
Expand Down Expand Up @@ -92,16 +95,21 @@ public void testAdmissionControlEnforced() throws Exception {
fail("expected failure");
} catch (Exception e) {
assertTrue(e instanceof OpenSearchRejectedExecutionException);
assertTrue(e.getMessage().contains("CPU usage admission controller rejected the request"));
assertTrue(e.getMessage().contains("[indices:admin/aliases/get]"));
assertTrue(e.getMessage().contains("action-type [CLUSTER_ADMIN]"));
}

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
AdmissionControlService admissionControlServiceCM = internalCluster().getClusterManagerNodeInstance(AdmissionControlService.class);

AdmissionControllerStats admissionStats = getAdmissionControlStats(admissionControlServiceCM).get(
CpuBasedAdmissionController.CPU_BASED_ADMISSION_CONTROLLER
);
AdmissionControllerStats admissionStats = admissionControlServicePrimary.stats().getAdmissionControllerStatsList().get(0);

assertEquals(admissionStats.rejectionCount.get(AdmissionControlActionType.CLUSTER_ADMIN.getType()).longValue(), 1);
assertNull(admissionStats.rejectionCount.get(AdmissionControlActionType.SEARCH.getType()));
assertNull(admissionStats.rejectionCount.get(AdmissionControlActionType.INDEXING.getType()));
Expand All @@ -121,8 +129,18 @@ public void testAdmissionControlEnabledOnNoBreach() throws InterruptedException
assertThat(getAliasesResponse.getAliases().get("test").size(), equalTo(1));
}

public void testAdmissionControlMonitorOnBreach() throws InterruptedException {
admissionControlDisabledOnBreach(
Settings.builder().put(ADMISSION_CONTROL_TRANSPORT_LAYER_MODE.getKey(), AdmissionControlMode.MONITOR.getMode()).build()
);
}

public void testAdmissionControlDisabledOnBreach() throws InterruptedException {
client().admin().cluster().prepareUpdateSettings().setTransientSettings(DISABLE_ADMISSION_CONTROL).execute().actionGet();
admissionControlDisabledOnBreach(DISABLE_ADMISSION_CONTROL);
}

public void admissionControlDisabledOnBreach(Settings admission) throws InterruptedException {
client().admin().cluster().prepareUpdateSettings().setTransientSettings(admission).execute().actionGet();

cMResourceCollector.collectNodeResourceUsageStats(clusterManagerNodeId, System.currentTimeMillis(), 97, 97, new IoUsageStats(98));

Expand Down Expand Up @@ -169,4 +187,12 @@ public void tearDown() throws Exception {
client().admin().cluster().prepareUpdateSettings().setTransientSettings(DISABLE_ADMISSION_CONTROL).execute().actionGet();
super.tearDown();
}

Map<String, AdmissionControllerStats> getAdmissionControlStats(AdmissionControlService admissionControlService) {
Map<String, AdmissionControllerStats> acStats = new HashMap<>();
for (AdmissionControllerStats admissionControllerStats : admissionControlService.stats().getAdmissionControllerStatsList()) {
acStats.put(admissionControllerStats.getAdmissionControllerName(), admissionControllerStats);
}
return acStats;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -709,21 +709,17 @@ public void apply(Settings value, Settings current, Settings previous) {
IndicesService.CLUSTER_REMOTE_TRANSLOG_BUFFER_INTERVAL_SETTING,
IndicesService.CLUSTER_REMOTE_INDEX_RESTRICT_ASYNC_DURABILITY_SETTING,
IndicesService.CLUSTER_INDEX_RESTRICT_REPLICATION_TYPE_SETTING,
IndicesService.CLUSTER_REMOTE_STORE_PATH_PREFIX_TYPE_SETTING,

// Admission Control Settings
AdmissionControlSettings.ADMISSION_CONTROL_TRANSPORT_LAYER_MODE,
CpuBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE,
CpuBasedAdmissionControllerSettings.INDEXING_CPU_USAGE_LIMIT,
CpuBasedAdmissionControllerSettings.SEARCH_CPU_USAGE_LIMIT,
CpuBasedAdmissionControllerSettings.CLUSTER_INFO_CPU_USAGE_LIMIT,
CpuBasedAdmissionControllerSettings.CLUSTER_ADMIN_CPU_USAGE_LIMIT,

IoBasedAdmissionControllerSettings.IO_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE,
IoBasedAdmissionControllerSettings.SEARCH_IO_USAGE_LIMIT,
IoBasedAdmissionControllerSettings.INDEXING_IO_USAGE_LIMIT,
IndicesService.CLUSTER_INDEX_RESTRICT_REPLICATION_TYPE_SETTING,
IndicesService.CLUSTER_REMOTE_STORE_PATH_PREFIX_TYPE_SETTING,
IndicesService.CLUSTER_INDEX_RESTRICT_REPLICATION_TYPE_SETTING,

// Concurrent segment search settings
SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ private void applyForTransportLayer(String actionName, AdmissionControlActionTyp
throw new OpenSearchRejectedExecutionException(
String.format(
Locale.ROOT,
"Io usage admission controller rejected the request for action [%s] as IO limit reached",
"IO usage admission controller rejected the request for action [%s] as IO limit reached for action-type [%s]",
actionName,
admissionControlActionType.name()
)
);
Expand Down Expand Up @@ -113,6 +114,8 @@ private long getIoRejectionThreshold(AdmissionControlActionType admissionControl
return this.settings.getSearchIOUsageLimit();
case INDEXING:
return this.settings.getIndexingIOUsageLimit();
case CLUSTER_ADMIN:
return this.settings.getClusterAdminIOUsageLimit();
default:
throw new IllegalArgumentException(
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ public String getType() {

public static AdmissionControlActionType fromName(String name) {
name = name.toLowerCase(Locale.ROOT);

for (AdmissionControlActionType type : AdmissionControlActionType.values()) {
if (type.getType().equals(name)) {
return type;
}
switch (name) {
case "indexing":
return INDEXING;
case "search":
return SEARCH;
case "cluster_admin":
return CLUSTER_ADMIN;

Check warning on line 43 in server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/enums/AdmissionControlActionType.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/enums/AdmissionControlActionType.java#L43

Added line #L43 was not covered by tests
default:
throw new IllegalArgumentException("Not Supported TransportAction Type: " + name);
}
throw new IllegalArgumentException("Not Supported TransportAction Type: " + name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ public class IoBasedAdmissionControllerSettings {
*/
public static class Defaults {
public static final long IO_USAGE_LIMIT = 95;
public static final long CLUSTER_ADMIN_IO_USAGE_LIMIT = 100;

}

private AdmissionControlMode transportLayerMode;
private Long searchIOUsageLimit;
private Long indexingIOUsageLimit;
private Long clusterAdminIOUsageLimit;

/**
* Feature level setting to operate in shadow-mode or in enforced-mode. If enforced field is set
Expand Down Expand Up @@ -63,11 +66,22 @@ public static class Defaults {
Setting.Property.NodeScope
);

/**
* This setting used to set the limits for cluster admin requests by default it will use default cluster_admin IO usage limit
*/
public static final Setting<Long> CLUSTER_ADMIN_IO_USAGE_LIMIT = Setting.longSetting(
"admission_control.cluster_admin.io_usage.limit",
Defaults.CLUSTER_ADMIN_IO_USAGE_LIMIT,
Setting.Property.Final,
Setting.Property.NodeScope
);

public IoBasedAdmissionControllerSettings(ClusterSettings clusterSettings, Settings settings) {
this.transportLayerMode = IO_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE.get(settings);
clusterSettings.addSettingsUpdateConsumer(IO_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE, this::setTransportLayerMode);
this.searchIOUsageLimit = SEARCH_IO_USAGE_LIMIT.get(settings);
this.indexingIOUsageLimit = INDEXING_IO_USAGE_LIMIT.get(settings);
this.clusterAdminIOUsageLimit = CLUSTER_ADMIN_IO_USAGE_LIMIT.get(settings);
clusterSettings.addSettingsUpdateConsumer(INDEXING_IO_USAGE_LIMIT, this::setIndexingIOUsageLimit);
clusterSettings.addSettingsUpdateConsumer(SEARCH_IO_USAGE_LIMIT, this::setSearchIOUsageLimit);
}
Expand Down Expand Up @@ -95,4 +109,8 @@ public Long getIndexingIOUsageLimit() {
public Long getSearchIOUsageLimit() {
return searchIOUsageLimit;
}

public Long getClusterAdminIOUsageLimit() {
return clusterAdminIOUsageLimit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public void testDefaultSettings() {
assertEquals(ioBasedAdmissionControllerSettings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.DISABLED);
assertEquals(ioBasedAdmissionControllerSettings.getIndexingIOUsageLimit().longValue(), percent);
assertEquals(ioBasedAdmissionControllerSettings.getSearchIOUsageLimit().longValue(), percent);
assertEquals(
ioBasedAdmissionControllerSettings.getClusterAdminIOUsageLimit().longValue(),
IoBasedAdmissionControllerSettings.Defaults.CLUSTER_ADMIN_IO_USAGE_LIMIT
);
}

public void testGetConfiguredSettings() {
Expand Down Expand Up @@ -134,6 +138,10 @@ public void testUpdateAfterGetConfiguredSettings() {
assertEquals(ioBasedAdmissionControllerSettings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.ENFORCED);
assertEquals(ioBasedAdmissionControllerSettings.getSearchIOUsageLimit().longValue(), searchPercent);
assertEquals(ioBasedAdmissionControllerSettings.getIndexingIOUsageLimit().longValue(), percent);
assertEquals(
ioBasedAdmissionControllerSettings.getClusterAdminIOUsageLimit().longValue(),
IoBasedAdmissionControllerSettings.Defaults.CLUSTER_ADMIN_IO_USAGE_LIMIT
);

Settings updatedSettings = Settings.builder()
.put(
Expand All @@ -146,6 +154,10 @@ public void testUpdateAfterGetConfiguredSettings() {
assertEquals(ioBasedAdmissionControllerSettings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.MONITOR);
assertEquals(ioBasedAdmissionControllerSettings.getSearchIOUsageLimit().longValue(), searchPercent);
assertEquals(ioBasedAdmissionControllerSettings.getIndexingIOUsageLimit().longValue(), indexingPercent);
assertEquals(
ioBasedAdmissionControllerSettings.getClusterAdminIOUsageLimit().longValue(),
IoBasedAdmissionControllerSettings.Defaults.CLUSTER_ADMIN_IO_USAGE_LIMIT
);

searchPercent = 70;
updatedSettings = Settings.builder()
Expand All @@ -156,5 +168,9 @@ public void testUpdateAfterGetConfiguredSettings() {
clusterService.getClusterSettings().applySettings(updatedSettings);
assertEquals(ioBasedAdmissionControllerSettings.getSearchIOUsageLimit().longValue(), searchPercent);
assertEquals(ioBasedAdmissionControllerSettings.getIndexingIOUsageLimit().longValue(), indexingPercent);
assertEquals(
ioBasedAdmissionControllerSettings.getClusterAdminIOUsageLimit().longValue(),
IoBasedAdmissionControllerSettings.Defaults.CLUSTER_ADMIN_IO_USAGE_LIMIT
);
}
}

0 comments on commit d9e42b5

Please sign in to comment.