Skip to content

Commit ee57210

Browse files
kkondakajeffreyAaron
authored andcommitted
Modify cloudwatch sink to use FixedThreadPool (opensearch-project#5770)
* Modify cloudwatch sink to use FixedThreadPool Signed-off-by: Krishna Kondaka <krishkdk@amazon.com> * Addressed comments Signed-off-by: Krishna Kondaka <krishkdk@amazon.com> --------- Signed-off-by: Krishna Kondaka <krishkdk@amazon.com> Signed-off-by: Jeffrey Aaron Jeyasingh <jeffreyaaron06@gmail.com>
1 parent 32f9c36 commit ee57210

4 files changed

Lines changed: 27 additions & 1 deletion

File tree

data-prepper-plugins/cloudwatch-logs/src/main/java/org/opensearch/dataprepper/plugins/sink/cloudwatch_logs/CloudWatchLogsSink.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public CloudWatchLogsSink(final PluginSetting pluginSetting,
7474
dlqPushHandler = new DlqPushHandler(pluginFactory, pluginSetting, pluginMetrics, cloudWatchLogsSinkConfig.getDlq(), region, role, "cloudWatchLogs");
7575
}
7676

77-
Executor executor = Executors.newCachedThreadPool();
77+
Executor executor = Executors.newFixedThreadPool(cloudWatchLogsSinkConfig.getWorkers());
7878

7979
CloudWatchLogsDispatcher cloudWatchLogsDispatcher = CloudWatchLogsDispatcher.builder()
8080
.cloudWatchLogsClient(cloudWatchLogsClient)

data-prepper-plugins/cloudwatch-logs/src/main/java/org/opensearch/dataprepper/plugins/sink/cloudwatch_logs/config/CloudWatchLogsSinkConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
public class CloudWatchLogsSinkConfig {
1919
public static final int DEFAULT_RETRY_COUNT = 5;
20+
public static final int DEFAULT_NUM_WORKERS = 10;
2021

2122
@JsonProperty("aws")
2223
@Valid
@@ -43,6 +44,11 @@ public class CloudWatchLogsSinkConfig {
4344
@Max(15)
4445
private int maxRetries = DEFAULT_RETRY_COUNT;
4546

47+
@JsonProperty(value = "workers", defaultValue = "10")
48+
@Min(1)
49+
@Max(50)
50+
private int workers = DEFAULT_NUM_WORKERS;
51+
4652
public AwsConfig getAwsConfig() {
4753
return awsConfig;
4854
}
@@ -67,4 +73,8 @@ public int getMaxRetries() {
6773
return maxRetries;
6874
}
6975

76+
public int getWorkers() {
77+
return workers;
78+
}
79+
7080
}

data-prepper-plugins/cloudwatch-logs/src/test/java/org/opensearch/dataprepper/plugins/sink/cloudwatch_logs/CloudWatchLogsSinkTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ void setUp() {
6767
when(mockCloudWatchLogsSinkConfig.getThresholdConfig()).thenReturn(thresholdConfig);
6868
when(mockCloudWatchLogsSinkConfig.getLogGroup()).thenReturn(TEST_LOG_GROUP);
6969
when(mockCloudWatchLogsSinkConfig.getLogStream()).thenReturn(TEST_LOG_STREAM);
70+
when(mockCloudWatchLogsSinkConfig.getMaxRetries()).thenReturn(3);
71+
when(mockCloudWatchLogsSinkConfig.getWorkers()).thenReturn(10);
7072

7173
when(mockPluginSetting.getName()).thenReturn(TEST_PLUGIN_NAME);
7274
when(mockPluginSetting.getPipelineName()).thenReturn(TEST_PIPELINE_NAME);

data-prepper-plugins/cloudwatch-logs/src/test/java/org/opensearch/dataprepper/plugins/sink/cloudwatch_logs/config/CloudWatchLogsSinkConfigTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import static org.hamcrest.Matchers.equalTo;
1414
import static org.hamcrest.Matchers.notNullValue;
1515

16+
import java.util.Random;
17+
1618
class CloudWatchLogsSinkConfigTest {
1719
private CloudWatchLogsSinkConfig cloudWatchLogsSinkConfig;
1820
private AwsConfig awsConfig;
@@ -42,11 +44,23 @@ void GIVEN_new_sink_config_WHEN_get_log_group_called_SHOULD_return_null() {
4244
assertThat(new CloudWatchLogsSinkConfig().getLogGroup(), equalTo(null));
4345
}
4446

47+
@Test
48+
void GIVEN_new_sink_config_WHEN_get_num_threads_called_SHOULD_return_default_value() {
49+
assertThat(new CloudWatchLogsSinkConfig().getWorkers(), equalTo(CloudWatchLogsSinkConfig.DEFAULT_NUM_WORKERS));
50+
}
51+
4552
@Test
4653
void GIVEN_new_sink_config_WHEN_get_log_stream_called_SHOULD_return_null() {
4754
assertThat(new CloudWatchLogsSinkConfig().getLogStream(), equalTo(null));
4855
}
4956

57+
@Test
58+
void GIVEN_num_threads_configured_SHOULD_return_the_configured_value() throws NoSuchFieldException, IllegalAccessException {
59+
int testValue = (new Random()).nextInt();
60+
ReflectivelySetField.setField(cloudWatchLogsSinkConfig.getClass(), cloudWatchLogsSinkConfig, "workers", testValue);
61+
assertThat(cloudWatchLogsSinkConfig.getWorkers(), equalTo(testValue));
62+
}
63+
5064
@Test
5165
void GIVEN_empty_sink_config_WHEN_deserialized_from_json_SHOULD_return_valid_log_group_and_log_stream() throws NoSuchFieldException, IllegalAccessException {
5266
ReflectivelySetField.setField(cloudWatchLogsSinkConfig.getClass(), cloudWatchLogsSinkConfig, "logGroup", LOG_GROUP);

0 commit comments

Comments
 (0)