Skip to content

Commit ccfa598

Browse files
committed
make retry time window configurable in ml processor config
Signed-off-by: Xun Zhang <xunzh@amazon.com>
1 parent ca06a48 commit ccfa598

6 files changed

Lines changed: 239 additions & 10 deletions

File tree

data-prepper-plugins/ml-inference-processor/src/main/java/org/opensearch/dataprepper/plugins/ml_inference/processor/MLProcessorConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.opensearch.dataprepper.plugins.ml_inference.processor.configuration.AwsAuthenticationOptions;
2222
import org.opensearch.dataprepper.plugins.ml_inference.processor.configuration.ServiceName;
2323

24+
import java.time.Duration;
2425
import java.util.Collections;
2526
import java.util.List;
2627
import java.util.Map;
@@ -31,6 +32,7 @@
3132
"It supports both synchronous and asynchronous invocations based on your use case.")
3233
public class MLProcessorConfig {
3334
private static final int DEFAULT_MAX_BATCH_SIZE = 100;
35+
public static final Duration DEFAULT_RETRY_WINDOW = Duration.ofMinutes(10);
3436

3537
@JsonProperty("aws")
3638
@NotNull
@@ -82,6 +84,11 @@ public class MLProcessorConfig {
8284
@JsonProperty("max_batch_size")
8385
private int maxBatchSize = DEFAULT_MAX_BATCH_SIZE;
8486

87+
@JsonPropertyDescription("The time duration for which the ml_inference processor retains events for retry attempts."
88+
+ "Supports ISO_8601 notation Strings (\"PT20.345S\", \"PT15M\", etc.) as well as simple notation Strings for seconds (\"60s\") and milliseconds (\"1500ms\")")
89+
@JsonProperty("retry_time_window")
90+
private Duration retryTimeWindow = DEFAULT_RETRY_WINDOW;
91+
8592
@JsonProperty("dlq")
8693
private PluginModel dlq;
8794

data-prepper-plugins/ml-inference-processor/src/main/java/org/opensearch/dataprepper/plugins/ml_inference/processor/common/AbstractBatchJobCreator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public abstract class AbstractBatchJobCreator implements MLBatchJobCreator {
3131
public static final String NUMBER_OF_RECORDS_FAILED_IN_BATCH_JOB = "recordsFailedInBatchJobCreation";
3232
public static final String NUMBER_OF_RECORDS_SUCCEEDED_IN_BATCH_JOB = "recordsSucceededInBatchJobCreation";
3333
protected static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
34-
protected static final long MAX_RETRY_WINDOW_MS = 600_000; // 10 minutes
3534
protected static final int TOO_MANY_REQUESTS = 429;
3635
protected final MLProcessorConfig mlProcessorConfig;
3736
protected final AwsCredentialsSupplier awsCredentialsSupplier;
@@ -42,6 +41,7 @@ public abstract class AbstractBatchJobCreator implements MLBatchJobCreator {
4241
protected final List<String> tagsOnFailure;
4342
protected final MlCommonRequester mlCommonRequester;
4443
protected DlqPushHandler dlqPushHandler = null;
44+
protected final long maxRetryTimeWindow;
4545
private static final Aws4Signer signer;
4646
static {
4747
signer = Aws4Signer.create();
@@ -61,6 +61,7 @@ public AbstractBatchJobCreator(MLProcessorConfig mlProcessorConfig,
6161
this.tagsOnFailure = mlProcessorConfig.getTagsOnFailure();
6262
this.mlCommonRequester = new MlCommonRequester(signer, mlProcessorConfig, awsCredentialsSupplier);
6363
this.dlqPushHandler = dlqPushHandler;
64+
this.maxRetryTimeWindow = mlProcessorConfig.getRetryTimeWindow().toMillis();
6465
}
6566

6667
// Add common logic here that both subclasses can share
@@ -133,7 +134,7 @@ class RetryRecord {
133134
}
134135

135136
boolean isExpired() {
136-
return System.currentTimeMillis() - createdTime > MAX_RETRY_WINDOW_MS;
137+
return System.currentTimeMillis() - createdTime > maxRetryTimeWindow;
137138
}
138139

139140
void incrementRetryCount() {

data-prepper-plugins/ml-inference-processor/src/main/java/org/opensearch/dataprepper/plugins/ml_inference/processor/common/BedrockBatchJobCreator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private void handleExpiredRecords(List<RetryRecord> expiredRecords, List<Record<
268268
String errorMessage = String.format(
269269
"Record expired after %d retries over %d minutes",
270270
expiredRecord.getRetryCount(),
271-
MAX_RETRY_WINDOW_MS / 60000
271+
maxRetryTimeWindow / 60000
272272
);
273273

274274
LOG.error(NOISY, "Record expired from throttle queue: {}", errorMessage);

data-prepper-plugins/ml-inference-processor/src/main/java/org/opensearch/dataprepper/plugins/ml_inference/processor/common/SageMakerBatchJobCreator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class SageMakerBatchJobCreator extends AbstractBatchJobCreator {
5151
// Added batch processing fields
5252
@Getter
5353
private final ConcurrentLinkedQueue<Record<Event>> batch_records = new ConcurrentLinkedQueue<>();
54+
@Getter
5455
private final ConcurrentLinkedQueue<Record<Event>> processedBatchRecords = new ConcurrentLinkedQueue<>();
5556
@Getter
5657
private final ConcurrentLinkedQueue<RetryRecord> retryQueue = new ConcurrentLinkedQueue<>();
@@ -287,7 +288,7 @@ private void processRetryQueue() {
287288
expiredRecords.add(retryRecord.getRecord());
288289
LOG.debug("Record expired after {} attempts over {} ms",
289290
retryRecord.getRetryCount(),
290-
MAX_RETRY_WINDOW_MS);
291+
maxRetryTimeWindow);
291292
return true;
292293
}
293294
return false;
@@ -312,10 +313,10 @@ private void processRetryQueue() {
312313

313314
private void handleExpiredRecords(List<Record<Event>> expiredRecords) {
314315
LOG.warn("{} records expired from retry queue after {} ms timeout",
315-
expiredRecords.size(), MAX_RETRY_WINDOW_MS);
316+
expiredRecords.size(), maxRetryTimeWindow);
316317
handleFailure(expiredRecords, processedBatchRecords,
317318
new MLBatchJobException(HttpURLConnection.HTTP_BAD_REQUEST,
318-
"Records expired after " + MAX_RETRY_WINDOW_MS/(60*1000) + " minute retry window"),
319+
"Records expired after " + maxRetryTimeWindow/(60*1000) + " minute retry window"),
319320
HttpURLConnection.HTTP_BAD_REQUEST);
320321
}
321322

data-prepper-plugins/ml-inference-processor/src/test/java/org/opensearch/dataprepper/plugins/ml_inference/processor/common/BedrockBatchJobCreatorTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import static org.mockito.Mockito.times;
3737
import static org.mockito.Mockito.verify;
3838
import static org.mockito.Mockito.when;
39+
import static org.opensearch.dataprepper.plugins.ml_inference.processor.MLProcessorConfig.DEFAULT_RETRY_WINDOW;
3940
import static org.opensearch.dataprepper.plugins.ml_inference.processor.common.AbstractBatchJobCreator.NUMBER_OF_FAILED_BATCH_JOBS_CREATION;
4041
import static org.opensearch.dataprepper.plugins.ml_inference.processor.common.AbstractBatchJobCreator.NUMBER_OF_RECORDS_FAILED_IN_BATCH_JOB;
4142
import static org.opensearch.dataprepper.plugins.ml_inference.processor.common.AbstractBatchJobCreator.NUMBER_OF_RECORDS_SUCCEEDED_IN_BATCH_JOB;
@@ -66,6 +67,7 @@ public class BedrockBatchJobCreatorTest {
6667
void setUp() {
6768
MockitoAnnotations.openMocks(this);
6869
when(mlProcessorConfig.getOutputPath()).thenReturn("s3://offlinebatch/output");
70+
when(mlProcessorConfig.getRetryTimeWindow()).thenReturn(DEFAULT_RETRY_WINDOW);
6971
counter = new Counter() {
7072
@Override
7173
public void increment(double v) {}

0 commit comments

Comments
 (0)