Skip to content

Commit 8f3a5ea

Browse files
committed
fixed the PR comments and added Settings test
1 parent 68968cf commit 8f3a5ea

File tree

9 files changed

+66
-43
lines changed

9 files changed

+66
-43
lines changed

server/src/internalClusterTest/java/org/opensearch/ratelimitting/admissioncontrol/AdmissionForClusterManagerIT.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.junit.Before;
2525

2626
import static org.opensearch.ratelimitting.admissioncontrol.AdmissionControlSettings.ADMISSION_CONTROL_TRANSPORT_LAYER_MODE;
27-
import static org.opensearch.ratelimitting.admissioncontrol.settings.CpuBasedAdmissionControllerSettings.CLUSTER_INFO_CPU_USAGE_LIMIT;
27+
import static org.opensearch.ratelimitting.admissioncontrol.settings.CpuBasedAdmissionControllerSettings.CLUSTER_ADMIN_CPU_USAGE_LIMIT;
2828
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
2929
import static org.hamcrest.Matchers.equalTo;
3030

@@ -45,7 +45,7 @@ public class AdmissionForClusterManagerIT extends OpenSearchIntegTestCase {
4545
private static final Settings ENFORCE_ADMISSION_CONTROL = Settings.builder()
4646
.put(ResourceTrackerSettings.GLOBAL_CPU_USAGE_AC_WINDOW_DURATION_SETTING.getKey(), TimeValue.timeValueMillis(500))
4747
.put(ADMISSION_CONTROL_TRANSPORT_LAYER_MODE.getKey(), AdmissionControlMode.ENFORCED)
48-
.put(CLUSTER_INFO_CPU_USAGE_LIMIT.getKey(), 50)
48+
.put(CLUSTER_ADMIN_CPU_USAGE_LIMIT.getKey(), 50)
4949
.build();
5050

5151
@Before
@@ -92,7 +92,7 @@ public void testAdmissionControlEnforced() throws InterruptedException {
9292
AdmissionControlService.class
9393
);
9494
AdmissionControllerStats admissionStats = admissionControlServicePrimary.stats().getAdmissionControllerStatsList().get(0);
95-
assertEquals(admissionStats.rejectionCount.get(AdmissionControlActionType.CLUSTER_INFO.getType()).longValue(), 1);
95+
assertEquals(admissionStats.rejectionCount.get(AdmissionControlActionType.CLUSTER_ADMIN.getType()).longValue(), 1);
9696
assertNull(admissionStats.rejectionCount.get(AdmissionControlActionType.SEARCH.getType()));
9797
assertNull(admissionStats.rejectionCount.get(AdmissionControlActionType.INDEXING.getType()));
9898
}

server/src/main/java/org/opensearch/action/support/HandledTransportAction.java

+10-20
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,16 @@ protected HandledTransportAction(
109109
) {
110110
super(actionName, actionFilters, transportService.getTaskManager());
111111

112-
if (admissionControlActionType != null) {
113-
transportService.registerRequestHandler(
114-
actionName,
115-
executor,
116-
false,
117-
canTripCircuitBreaker,
118-
admissionControlActionType,
119-
requestReader,
120-
new TransportHandler()
121-
);
122-
} else {
123-
transportService.registerRequestHandler(
124-
actionName,
125-
executor,
126-
false,
127-
canTripCircuitBreaker,
128-
requestReader,
129-
new TransportHandler()
130-
);
131-
}
112+
transportService.registerRequestHandler(
113+
actionName,
114+
executor,
115+
false,
116+
canTripCircuitBreaker,
117+
admissionControlActionType,
118+
requestReader,
119+
new TransportHandler()
120+
);
121+
132122
}
133123

134124
/**

server/src/main/java/org/opensearch/action/support/clustermanager/TransportClusterManagerNodeReadAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected TransportClusterManagerNodeReadAction(
6363
this(
6464
actionName,
6565
true,
66-
AdmissionControlActionType.CLUSTER_INFO,
66+
AdmissionControlActionType.CLUSTER_ADMIN,
6767
transportService,
6868
clusterService,
6969
threadPool,

server/src/main/java/org/opensearch/common/settings/ClusterSettings.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,13 @@ public void apply(Settings value, Settings current, Settings previous) {
701701
RemoteStoreNodeService.MIGRATION_DIRECTION_SETTING,
702702
IndicesService.CLUSTER_REMOTE_TRANSLOG_BUFFER_INTERVAL_SETTING,
703703
IndicesService.CLUSTER_REMOTE_INDEX_RESTRICT_ASYNC_DURABILITY_SETTING,
704+
705+
// Admission Control Settings
704706
AdmissionControlSettings.ADMISSION_CONTROL_TRANSPORT_LAYER_MODE,
705707
CpuBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE,
706708
CpuBasedAdmissionControllerSettings.INDEXING_CPU_USAGE_LIMIT,
707709
CpuBasedAdmissionControllerSettings.SEARCH_CPU_USAGE_LIMIT,
708-
CpuBasedAdmissionControllerSettings.CLUSTER_INFO_CPU_USAGE_LIMIT,
710+
CpuBasedAdmissionControllerSettings.CLUSTER_ADMIN_CPU_USAGE_LIMIT,
709711
IndicesService.CLUSTER_INDEX_RESTRICT_REPLICATION_TYPE_SETTING,
710712

711713
// Concurrent segment search settings

server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/controllers/CpuBasedAdmissionController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ private long getCpuRejectionThreshold(AdmissionControlActionType admissionContro
113113
return this.settings.getSearchCPULimit();
114114
case INDEXING:
115115
return this.settings.getIndexingCPULimit();
116-
case CLUSTER_INFO:
117-
return this.settings.getClusterInfoCPULimit();
116+
case CLUSTER_ADMIN:
117+
return this.settings.getClusterAdminCPULimit();
118118
default:
119119
throw new IllegalArgumentException(
120120
String.format(

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

+7-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
public enum AdmissionControlActionType {
1717
INDEXING("indexing"),
1818
SEARCH("search"),
19-
CLUSTER_INFO("cluster_info");
19+
CLUSTER_ADMIN("cluster_admin");
2020

2121
private final String type;
2222

@@ -34,15 +34,12 @@ public String getType() {
3434

3535
public static AdmissionControlActionType fromName(String name) {
3636
name = name.toLowerCase(Locale.ROOT);
37-
switch (name) {
38-
case "indexing":
39-
return INDEXING;
40-
case "search":
41-
return SEARCH;
42-
case "cluster_info":
43-
return CLUSTER_INFO;
44-
default:
45-
throw new IllegalArgumentException("Not Supported TransportAction Type: " + name);
37+
38+
for (AdmissionControlActionType type : AdmissionControlActionType.values()) {
39+
if (type.name().equals(name)) {
40+
return type;
41+
}
4642
}
43+
throw new IllegalArgumentException("Not Supported TransportAction Type: " + name);
4744
}
4845
}

server/src/main/java/org/opensearch/ratelimitting/admissioncontrol/settings/CpuBasedAdmissionControllerSettings.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static class Defaults {
6464
Setting.Property.NodeScope
6565
);
6666

67-
public static final Setting<Long> CLUSTER_INFO_CPU_USAGE_LIMIT = Setting.longSetting(
67+
public static final Setting<Long> CLUSTER_ADMIN_CPU_USAGE_LIMIT = Setting.longSetting(
6868
"admission_control.cluster.admin.cpu_usage.limit",
6969
Defaults.CPU_USAGE_LIMIT,
7070
Setting.Property.Dynamic,
@@ -77,10 +77,10 @@ public CpuBasedAdmissionControllerSettings(ClusterSettings clusterSettings, Sett
7777
clusterSettings.addSettingsUpdateConsumer(CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE, this::setTransportLayerMode);
7878
this.searchCPULimit = SEARCH_CPU_USAGE_LIMIT.get(settings);
7979
this.indexingCPULimit = INDEXING_CPU_USAGE_LIMIT.get(settings);
80-
this.clusterInfoCPULimit = CLUSTER_INFO_CPU_USAGE_LIMIT.get(settings);
80+
this.clusterInfoCPULimit = CLUSTER_ADMIN_CPU_USAGE_LIMIT.get(settings);
8181
clusterSettings.addSettingsUpdateConsumer(INDEXING_CPU_USAGE_LIMIT, this::setIndexingCPULimit);
8282
clusterSettings.addSettingsUpdateConsumer(SEARCH_CPU_USAGE_LIMIT, this::setSearchCPULimit);
83-
clusterSettings.addSettingsUpdateConsumer(CLUSTER_INFO_CPU_USAGE_LIMIT, this::setClusterInfoCPULimit);
83+
clusterSettings.addSettingsUpdateConsumer(CLUSTER_ADMIN_CPU_USAGE_LIMIT, this::setClusterInfoCPULimit);
8484

8585
}
8686

@@ -100,7 +100,7 @@ public Long getIndexingCPULimit() {
100100
return indexingCPULimit;
101101
}
102102

103-
public Long getClusterInfoCPULimit() {
103+
public Long getClusterAdminCPULimit() {
104104
return clusterInfoCPULimit;
105105
}
106106

server/src/main/java/org/opensearch/transport/TransportService.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,11 @@ public <Request extends TransportRequest> void registerRequestHandler(
12141214
TransportRequestHandler<Request> handler
12151215
) {
12161216
validateActionName(action);
1217-
handler = interceptor.interceptHandler(action, executor, forceExecution, handler, admissionControlActionType);
1217+
if (admissionControlActionType != null) {
1218+
handler = interceptor.interceptHandler(action, executor, forceExecution, handler, admissionControlActionType);
1219+
} else {
1220+
handler = interceptor.interceptHandler(action, executor, forceExecution, handler);
1221+
}
12181222
RequestHandlerRegistry<Request> reg = new RequestHandlerRegistry<>(
12191223
action,
12201224
requestReader,

server/src/test/java/org/opensearch/ratelimitting/admissioncontrol/settings/CPUBasedAdmissionControlSettingsTests.java

+31-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public void testSettingsExists() {
4949
Arrays.asList(
5050
CpuBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE,
5151
CpuBasedAdmissionControllerSettings.SEARCH_CPU_USAGE_LIMIT,
52-
CpuBasedAdmissionControllerSettings.INDEXING_CPU_USAGE_LIMIT
52+
CpuBasedAdmissionControllerSettings.INDEXING_CPU_USAGE_LIMIT,
53+
CpuBasedAdmissionControllerSettings.CLUSTER_ADMIN_CPU_USAGE_LIMIT
5354
)
5455
)
5556
);
@@ -149,4 +150,33 @@ public void testUpdateAfterGetConfiguredSettings() {
149150
assertEquals(cpuBasedAdmissionControllerSettings.getSearchCPULimit().longValue(), searchPercent);
150151
assertEquals(cpuBasedAdmissionControllerSettings.getIndexingCPULimit().longValue(), indexingPercent);
151152
}
153+
154+
public void testConfiguredSettingsForAdmin() {
155+
Settings settings = Settings.builder()
156+
.put(
157+
CpuBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE.getKey(),
158+
AdmissionControlMode.ENFORCED.getMode()
159+
)
160+
.put(CpuBasedAdmissionControllerSettings.CLUSTER_ADMIN_CPU_USAGE_LIMIT.getKey(), 50)
161+
.build();
162+
163+
CpuBasedAdmissionControllerSettings cpuBasedAdmissionControllerSettings = new CpuBasedAdmissionControllerSettings(
164+
clusterService.getClusterSettings(),
165+
settings
166+
);
167+
assertEquals(cpuBasedAdmissionControllerSettings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.ENFORCED);
168+
assertEquals(cpuBasedAdmissionControllerSettings.getClusterAdminCPULimit().longValue(), 50);
169+
170+
Settings updatedSettings = Settings.builder()
171+
.put(
172+
CpuBasedAdmissionControllerSettings.CPU_BASED_ADMISSION_CONTROLLER_TRANSPORT_LAYER_MODE.getKey(),
173+
AdmissionControlMode.MONITOR.getMode()
174+
)
175+
.put(CpuBasedAdmissionControllerSettings.CLUSTER_ADMIN_CPU_USAGE_LIMIT.getKey(), 90)
176+
.build();
177+
clusterService.getClusterSettings().applySettings(updatedSettings);
178+
assertEquals(cpuBasedAdmissionControllerSettings.getTransportLayerAdmissionControllerMode(), AdmissionControlMode.MONITOR);
179+
assertEquals(cpuBasedAdmissionControllerSettings.getClusterAdminCPULimit().longValue(), 90);
180+
181+
}
152182
}

0 commit comments

Comments
 (0)