Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch KCL known exceptions to reduce noisy log statements #5102

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

package org.opensearch.dataprepper.plugins.kinesis.source;

import com.amazonaws.SdkClientException;
import lombok.Setter;
import org.opensearch.dataprepper.metrics.PluginMetrics;
import org.opensearch.dataprepper.model.acknowledgements.AcknowledgementSetManager;
Expand All @@ -35,6 +36,8 @@
import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
import software.amazon.kinesis.common.ConfigsBuilder;
import software.amazon.kinesis.coordinator.Scheduler;
import software.amazon.kinesis.exceptions.KinesisClientLibDependencyException;
import software.amazon.kinesis.exceptions.ThrottlingException;
import software.amazon.kinesis.processor.ShardRecordProcessorFactory;
import software.amazon.kinesis.retrieval.polling.PollingConfig;

Expand Down Expand Up @@ -134,20 +137,21 @@ public void shutDown() {
}

public Scheduler getScheduler(final Buffer<Record<Event>> buffer) {

int numRetries = 0;
while (scheduler == null && numRetries++ < kinesisSourceConfig.getMaxInitializationAttempts()) {
int maxAttempts = kinesisSourceConfig.getMaxInitializationAttempts();
while (scheduler == null && maxAttempts-- > 0 ) {
try {
scheduler = createScheduler(buffer);
} catch (SdkClientException | KinesisClientLibDependencyException | ThrottlingException ex) {
LOG.error(NOISY, "Caught exception when initializing KCL Scheduler due to {}. Number of remaining retries: {}", ex.getMessage(), maxAttempts);
} catch (Exception ex) {
LOG.error(NOISY, "Caught exception when initializing KCL Scheduler. Will retry", ex);
LOG.error(NOISY, "Caught exception when initializing KCL Scheduler. Number of remaining retries: {}", maxAttempts, ex);
}

if (scheduler == null) {
try {
Thread.sleep(kinesisSourceConfig.getInitializationBackoffTime().toMillis());
} catch (InterruptedException e){
LOG.debug("Interrupted exception!");
LOG.debug("Interrupted exception.");
}
}
}
Expand Down
Loading