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

Do not write empty lists of DlqObject to the DLQ #4403

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
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 @@ -84,6 +84,10 @@ public class S3DlqWriter implements DlqWriter {

@Override
public void write(final List<DlqObject> dlqObjects, final String pipelineName, final String pluginId) throws IOException {
if(dlqObjects.isEmpty()) {
return;
}

try {
doWrite(dlqObjects, pipelineName, pluginId);
dlqS3RequestSuccessCounter.increment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import software.amazon.awssdk.services.s3.model.PutObjectResponse;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.UUID;
Expand All @@ -48,6 +49,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static org.opensearch.dataprepper.plugins.dlq.s3.S3DlqWriter.S3_DLQ_RECORDS_FAILED;
Expand Down Expand Up @@ -163,6 +165,24 @@ public void testWrite(final String keyPathPrefix, final String expectedKeyPrefix
verify(dlqS3RecordsSuccessCounter).increment(dlqObjects.size());
}

@Test
void write_with_empty_list_does_not_write_to_S3() throws Exception {
when(config.getKeyPathPrefix()).thenReturn(keyPathPrefix);
when(config.getS3Client()).thenReturn(s3Client);
when(config.getBucket()).thenReturn(bucket);
s3DlqWriter = new S3DlqWriter(config, objectMapper, pluginMetrics);

dlqObjects = Collections.emptyList();

s3DlqWriter.write(dlqObjects, pipelineName, pluginId);

verifyNoInteractions(s3Client);
verifyNoInteractions(dlqS3RequestSuccessCounter);
verifyNoInteractions(dlqS3RecordsSuccessCounter);
verifyNoInteractions(dlqS3RequestFailedCounter);
verifyNoInteractions(dlqS3RecordsFailedCounter);
}

private static Stream<Arguments> validKeyPathPrefixes() {
final String randomKeyPathPrefix = UUID.randomUUID().toString();

Expand Down
Loading