Skip to content

Commit 006bdf2

Browse files
Starting refactor
1 parent 8dca924 commit 006bdf2

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ static TransportVersion def(int id) {
365365
public static final TransportVersion ESQL_LOOKUP_JOIN_ON_MANY_FIELDS = def(9_139_0_00);
366366
public static final TransportVersion SIMULATE_INGEST_EFFECTIVE_MAPPING = def(9_140_0_00);
367367
public static final TransportVersion RESOLVE_INDEX_MODE_ADDED = def(9_141_0_00);
368+
public static final TransportVersion INFERENCE_DISABLE_EIS_DISABLE_RATE_LIMITING_ADDED = def(9_142_0_00);
368369

369370
/*
370371
* STOP! READ THIS FIRST! No, really,

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/http/sender/RequestExecutorService.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,20 @@ private void cleanup() {
252252

253253
private void handleTasks() {
254254
try {
255-
if (shutdown.get()) {
256-
logger.debug("Shutdown requested while handling tasks, cleaning up");
257-
cleanup();
258-
return;
259-
}
255+
TimeValue timeToWait;
260256

261-
var timeToWait = settings.getTaskPollFrequency();
262-
for (var endpoint : rateLimitGroupings.values()) {
263-
timeToWait = TimeValue.min(endpoint.executeEnqueuedTask(), timeToWait);
264-
}
257+
do {
258+
if (shutdown.get()) {
259+
logger.debug("Shutdown requested while handling tasks, cleaning up");
260+
cleanup();
261+
return;
262+
}
263+
264+
timeToWait = settings.getTaskPollFrequency();
265+
for (var endpoint : rateLimitGroupings.values()) {
266+
timeToWait = TimeValue.min(endpoint.executeEnqueuedTask(), timeToWait);
267+
}
268+
} while (timeToWait.compareTo(TimeValue.ZERO) <= 0);
265269

266270
scheduleNextHandleTasks(timeToWait);
267271
} catch (Exception e) {

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/http/sender/RequestExecutorServiceSettings.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class RequestExecutorServiceSettings {
4040
static final Setting<TimeValue> TASK_POLL_FREQUENCY_SETTING = Setting.timeSetting(
4141
"xpack.inference.http.request_executor.task_poll_frequency",
4242
DEFAULT_TASK_POLL_FREQUENCY_TIME,
43+
TimeValue.timeValueNanos(1),
4344
Setting.Property.NodeScope,
4445
Setting.Property.Dynamic
4546
);
@@ -51,6 +52,7 @@ public class RequestExecutorServiceSettings {
5152
static final Setting<TimeValue> RATE_LIMIT_GROUP_CLEANUP_INTERVAL_SETTING = Setting.timeSetting(
5253
"xpack.inference.http.request_executor.rate_limit_group_cleanup_interval",
5354
DEFAULT_RATE_LIMIT_GROUP_CLEANUP_INTERVAL,
55+
TimeValue.timeValueNanos(1),
5456
Setting.Property.NodeScope,
5557
Setting.Property.Dynamic
5658
);
@@ -63,6 +65,7 @@ public class RequestExecutorServiceSettings {
6365
static final Setting<TimeValue> RATE_LIMIT_GROUP_STALE_DURATION_SETTING = Setting.timeSetting(
6466
"xpack.inference.http.request_executor.rate_limit_group_stale_duration",
6567
DEFAULT_RATE_LIMIT_GROUP_STALE_DURATION,
68+
TimeValue.timeValueNanos(1),
6669
Setting.Property.NodeScope,
6770
Setting.Property.Dynamic
6871
);

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/settings/RateLimitSettings.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public static RateLimitSettings of(
5353
return requestsPerMinute == null ? defaultValue : new RateLimitSettings(requestsPerMinute);
5454
}
5555

56+
// public static RateLimitSettings disabledRateLimiting() {
57+
//
58+
// }
59+
5660
public static Map<String, SettingsConfiguration> toSettingsConfigurationWithDescription(
5761
String description,
5862
EnumSet<TaskType> supportedTaskTypes
@@ -84,6 +88,8 @@ public RateLimitSettings(long requestsPerMinute) {
8488
}
8589

8690
/**
91+
* This should only be used for testing.
92+
*
8793
* Defines the settings in requests per the time unit provided
8894
* @param requestsPerTimeUnit number of requests
8995
* @param timeUnit _
@@ -98,6 +104,12 @@ public RateLimitSettings(long requestsPerTimeUnit, TimeUnit timeUnit) {
98104
this.timeUnit = Objects.requireNonNull(timeUnit);
99105
}
100106

107+
private RateLimitSettings(long requestsPerTimeUnit, TimeUnit timeUnit, boolean disableRateLimiting) {
108+
this.requestsPerTimeUnit = 0;
109+
this.timeUnit = Objects.requireNonNull(timeUnit);
110+
111+
}
112+
101113
public RateLimitSettings(StreamInput in) throws IOException {
102114
requestsPerTimeUnit = in.readVLong();
103115
timeUnit = TimeUnit.MINUTES;

0 commit comments

Comments
 (0)