Skip to content

Commit

Permalink
Added modifiable back_off_timer, added threshold test for back_off_ti…
Browse files Browse the repository at this point in the history
…mer and params to AwsConfig

Signed-off-by: Marcos Gonzalez Mayedo <alemayed@amazon.com>
  • Loading branch information
Marcos Gonzalez Mayedo committed Jun 27, 2023
1 parent 5515bcb commit de9a58d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import jakarta.validation.constraints.Size;
import software.amazon.awssdk.regions.Region;

import java.util.Map;

/**
* AwsConfig is based on the S3-Sink AwsAuthenticationOptions
* where the configuration allows the sink to fetch Aws credentials
* and resources.
*/
public class AwsConfig {
private int DEFAULT_CONNECTION_ATTEMPTS = 5;

@JsonProperty("region")
@Size(min = 1, message = "Region cannot be empty string")
private String awsRegion;
Expand All @@ -18,8 +22,17 @@ public class AwsConfig {
@Size(min = 20, max = 2048, message = "awsStsRoleArn length should be between 1 and 2048 characters")
private String awsStsRoleArn;

@JsonProperty("path_to_credentials")
private String pathToCredentials;
@JsonProperty("sts_header_overrides")
@Size(max = 5, message = "sts_header_overrides supports a maximum of 5 headers to override")
private Map<String, String> awsStsHeaderOverrides;

@JsonProperty("sts_external_id")
@Size(min = 2, max = 1224, message = "awsStsExternalId length should be between 2 and 1224 characters")
private String awsStsExternalId;

public int getDEFAULT_CONNECTION_ATTEMPTS() {
return DEFAULT_CONNECTION_ATTEMPTS;
}

public Region getAwsRegion() {
return awsRegion != null ? Region.of(awsRegion) : null;
Expand All @@ -29,7 +42,11 @@ public String getAwsStsRoleArn() {
return awsStsRoleArn;
}

public String getPathToCredentials() {
return pathToCredentials;
public String getAwsStsExternalId() {
return awsStsExternalId;
}

public Map<String, String> getAwsStsHeaderOverrides() {
return awsStsHeaderOverrides;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
public class CwlSinkConfig {
public static final String DEFAULT_BUFFER_TYPE = "in_memory";

//Class was utilized from the
@JsonProperty("aws")
@NotNull
@Valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* restrictions.
*/
public class ThresholdConfig {
public static final int DEFAULT_BATCH_SIZE = 10;
public static final int DEFAULT_BATCH_SIZE = 100;
public static final int DEFAULT_EVENT_SIZE = 50;
public static final int DEFAULT_SIZE_OF_REQUEST = 25000;
public static final int DEFAULT_SIZE_OF_REQUEST = 524288;
public static final int DEFAULT_RETRY_COUNT = 5;
public static final int DEFAULT_LOG_SEND_INTERVAL_TIME = 60;
public static final int DEFAULT_BACKOFF_TIME = 5000;
Expand All @@ -21,7 +21,7 @@ public class ThresholdConfig {
private int batchSize = DEFAULT_BATCH_SIZE;

@JsonProperty("max_event_size")
@Size(min = 1, max = 256, message = "max_event_size amount should be between 1 to 256 bytes")
@Size(min = 1, max = 256, message = "max_event_size amount should be between 1 to 256 kilobytes")
private int maxEventSize = DEFAULT_EVENT_SIZE;

@JsonProperty("max_request_size")
Expand All @@ -36,6 +36,8 @@ public class ThresholdConfig {
@Size(min = 5, max = 300, message = "log_send_interval amount should be between 5 and 300 seconds")
private int logSendInterval = DEFAULT_LOG_SEND_INTERVAL_TIME;

@JsonProperty("back_off_time")
@Size(min = 0, max = 10000, message = "back_off_time amount should be between 0 and 10000 milliseconds")
private int backOffTime = DEFAULT_BACKOFF_TIME;

public int getBatchSize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@
import static org.hamcrest.Matchers.equalTo;

public class CwlSinkConfigTest {
public static final String LOG_GROUP = "testGroup";
public static final String LOG_STREAM = "testStream";
public static final String BUFFER_TYPE = "in_memory";
public static final int BATCH_SIZE = 10;
public static final int MAX_RETRIES = 10;
//Auth Config:
public static final String REGION = "us-east-1";

@Test
void check_null_auth_config_test() {
assertThat(new CwlSinkConfig().getAwsConfig(), equalTo(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,25 @@ void check_valid_request_size(final int max_batch_request_size) {

@ParameterizedTest
@ValueSource(ints = {1, 10, 15})
void check_valid_retry_count(final int retryCount) {
final Map<String, Integer> jsonMap = Map.of("retry_count", retryCount);
void check_valid_retry_count(final int retry_count) {
final Map<String, Integer> jsonMap = Map.of("retry_count", retry_count);
final ThresholdConfig thresholdConfigTest = objectMapper.convertValue(jsonMap, ThresholdConfig.class);
assertThat(thresholdConfigTest.getRetryCount(), equalTo(retryCount));
assertThat(thresholdConfigTest.getRetryCount(), equalTo(retry_count));
}

@ParameterizedTest
@ValueSource(ints = {5, 10, 300})
void check_valid_log_send_interval(final int logSendInterval) {
final Map<String, Integer> jsonMap = Map.of("log_send_interval", logSendInterval);
void check_valid_log_send_interval(final int log_send_interval) {
final Map<String, Integer> jsonMap = Map.of("log_send_interval", log_send_interval);
final ThresholdConfig thresholdConfigTest = objectMapper.convertValue(jsonMap, ThresholdConfig.class);
assertThat(thresholdConfigTest.getLogSendInterval(), equalTo(logSendInterval));
assertThat(thresholdConfigTest.getLogSendInterval(), equalTo(log_send_interval));
}

@ParameterizedTest
@ValueSource(ints = {0, 100, 5000})
void check_valid_back_off_time(final int back_off_time) {
final Map<String, Integer> jsonMap = Map.of("back_off_time", back_off_time);
final ThresholdConfig thresholdConfigTest = objectMapper.convertValue(jsonMap, ThresholdConfig.class);
assertThat(thresholdConfigTest.getBackOffTime(), equalTo(back_off_time));
}
}

0 comments on commit de9a58d

Please sign in to comment.