Skip to content

Commit

Permalink
Use Duration for delays in RetryInfoConfig for OTelLogsSource
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasLongo committed Sep 23, 2024
1 parent 473db0e commit 6ef9b7e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,14 @@ public void stop() {
}

private GrpcExceptionHandlerFunction createGrpExceptionHandler() {
RetryInfoConfig retryInfo = oTelLogsSourceConfig.getRetryInfo() != null ? oTelLogsSourceConfig.getRetryInfo() : new RetryInfoConfig(100, 2000);
Duration defaultMinDelay = Duration.ofMillis(100);
Duration defaultMaxDelay = Duration.ofMillis(2000);

return new GrpcRequestExceptionHandler(pluginMetrics, Duration.ofMillis(retryInfo.getMinDelay()), Duration.ofMillis(retryInfo.getMaxDelay()));
RetryInfoConfig retryInfo = oTelLogsSourceConfig.getRetryInfo() != null
? oTelLogsSourceConfig.getRetryInfo()
: new RetryInfoConfig(defaultMinDelay, defaultMaxDelay);

return new GrpcRequestExceptionHandler(pluginMetrics, retryInfo.getMinDelay(), retryInfo.getMaxDelay());
}

private List<ServerInterceptor> getAuthenticationInterceptor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
package org.opensearch.dataprepper.plugins.source.otellogs;

import java.time.Duration;

import com.fasterxml.jackson.annotation.JsonProperty;

public class RetryInfoConfig {

@JsonProperty("min_delay")
private Integer minDelay;
private Duration minDelay;

@JsonProperty("max_delay")
private Integer maxDelay;
private Duration maxDelay;

// Jackson needs this constructor
public RetryInfoConfig() {}

public RetryInfoConfig(int minDelay, int maxDelay) {
public RetryInfoConfig(Duration minDelay, Duration maxDelay) {
this.minDelay = minDelay;
this.maxDelay = maxDelay;
}

public int getMinDelay() {
public Duration getMinDelay() {
return minDelay;
}

public void setMinDelay(Integer minDelay) {
public void setMinDelay(Duration minDelay) {
this.minDelay = minDelay;
}

public int getMaxDelay() {
public Duration getMaxDelay() {
return maxDelay;
}

public void setMaxDelay(Integer maxDelay) {
public void setMaxDelay(Duration maxDelay) {
this.maxDelay = maxDelay;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.opensearch.dataprepper.model.configuration.PluginSetting;
import org.opensearch.dataprepper.plugins.codec.CompressionOption;

import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
Expand Down Expand Up @@ -322,7 +323,7 @@ private PluginSetting completePluginSettingForOtelLogsSource(final int requestTi
settings.put(SSL_KEY_FILE, sslKeyFile);
settings.put(THREAD_COUNT, threadCount);
settings.put(MAX_CONNECTION_COUNT, maxConnectionCount);
settings.put(OTelLogsSourceConfig.RETRY_INFO, new RetryInfoConfig(50, 100));
settings.put(OTelLogsSourceConfig.RETRY_INFO, new RetryInfoConfig(Duration.ofMillis(50), Duration.ofMillis(100)));
return new PluginSetting(PLUGIN_NAME, settings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
class OtelLogsSourceRetryInfoTest {
private static final String GRPC_ENDPOINT = "gproto+http://127.0.0.1:21892/";
private static final String TEST_PIPELINE_NAME = "test_pipeline";
private static final RetryInfoConfig TEST_RETRY_INFO = new RetryInfoConfig(100, 2000);
private static final RetryInfoConfig TEST_RETRY_INFO = new RetryInfoConfig(Duration.ofMillis(100), Duration.ofMillis(2000));

@Mock
private PluginFactory pluginFactory;
Expand Down

0 comments on commit 6ef9b7e

Please sign in to comment.