-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: json support for bq sink (#173)
* feat: json support for bq sink * feat: add/update depot configs in sinkFactoryUtils * chore: version bump and removing json related configs * feat: add json schema type * fix: fix typo and handle json messages on log dlq writer (#180) * fix: fix typo and handle json messages on log dlq writer * test: add logDlqwriter unit test * chore: version bump Co-authored-by: kevin.bheda <[email protected]> Co-authored-by: mayur.gubrele <[email protected]> Co-authored-by: lavkesh <[email protected]> Co-authored-by: jesrypandawa <[email protected]>
- Loading branch information
1 parent
d2a9a25
commit abdb7da
Showing
15 changed files
with
224 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 0 additions & 61 deletions
61
src/main/java/io/odpf/firehose/config/BigQuerySinkConfig.java
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
src/main/java/io/odpf/firehose/config/converter/InputSchemaTypeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.odpf.firehose.config.converter; | ||
|
||
import io.odpf.firehose.config.enums.InputSchemaType; | ||
import org.aeonbits.owner.Converter; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
public class InputSchemaTypeConverter implements Converter<InputSchemaType> { | ||
@Override | ||
public InputSchemaType convert(Method method, String input) { | ||
return InputSchemaType.valueOf(input.trim().toUpperCase()); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/io/odpf/firehose/config/enums/InputSchemaType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.odpf.firehose.config.enums; | ||
|
||
public enum InputSchemaType { | ||
PROTOBUF, | ||
JSON | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/test/java/io/odpf/firehose/config/converter/InputSchemaTypeConverterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.odpf.firehose.config.converter; | ||
|
||
import io.odpf.firehose.config.enums.InputSchemaType; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class InputSchemaTypeConverterTest { | ||
|
||
@Test | ||
public void shouldConvertSchemaType() { | ||
InputSchemaTypeConverter converter = new InputSchemaTypeConverter(); | ||
InputSchemaType schemaType = converter.convert(null, "PROTOBUF"); | ||
Assert.assertEquals(InputSchemaType.PROTOBUF, schemaType); | ||
schemaType = converter.convert(null, "JSON"); | ||
Assert.assertEquals(InputSchemaType.JSON, schemaType); | ||
} | ||
|
||
@Test | ||
public void shouldConvertSchemaTypeWithLowerCase() { | ||
InputSchemaTypeConverter converter = new InputSchemaTypeConverter(); | ||
InputSchemaType schemaType = converter.convert(null, " json "); | ||
Assert.assertEquals(InputSchemaType.JSON, schemaType); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/test/java/io/odpf/firehose/sink/dlq/LogDlqWriterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package io.odpf.firehose.sink.dlq; | ||
|
||
import io.odpf.depot.error.ErrorInfo; | ||
import io.odpf.depot.error.ErrorType; | ||
import io.odpf.firehose.message.Message; | ||
import io.odpf.firehose.metrics.FirehoseInstrumentation; | ||
import io.odpf.firehose.sink.dlq.log.LogDlqWriter; | ||
import org.apache.commons.lang3.exception.ExceptionUtils; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class LogDlqWriterTest { | ||
|
||
@Mock | ||
private FirehoseInstrumentation firehoseInstrumentation; | ||
|
||
private LogDlqWriter logDlqWriter; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
logDlqWriter = new LogDlqWriter(firehoseInstrumentation); | ||
} | ||
|
||
@Test | ||
public void shouldWriteMessagesToLog() throws IOException { | ||
long timestamp = Instant.parse("2020-01-01T00:00:00Z").toEpochMilli(); | ||
Message message = new Message("123".getBytes(), "abc".getBytes(), "booking", 1, 1, null, timestamp, timestamp, new ErrorInfo(new IOException("test"), ErrorType.DESERIALIZATION_ERROR)); | ||
|
||
String key = new String(message.getLogKey()); | ||
String value = new String(message.getLogMessage()); | ||
ErrorInfo errorInfo = message.getErrorInfo(); | ||
String error = ExceptionUtils.getStackTrace(errorInfo.getException()); | ||
|
||
List<Message> messages = Collections.singletonList(message); | ||
Assert.assertEquals(0, logDlqWriter.write(messages).size()); | ||
|
||
Mockito.verify(firehoseInstrumentation, Mockito.times(1)).logInfo("key: {}\nvalue: {}\nerror: {}", key, value, error); | ||
} | ||
|
||
@Test | ||
public void shouldWriteMessagesToLogWhenKeyIsNull() throws IOException { | ||
long timestamp = Instant.parse("2020-01-01T00:00:00Z").toEpochMilli(); | ||
Message message = new Message(null, "abc".getBytes(), "booking", 1, 1, null, timestamp, timestamp, new ErrorInfo(new IOException("test"), ErrorType.DESERIALIZATION_ERROR)); | ||
|
||
String value = new String(message.getLogMessage()); | ||
ErrorInfo errorInfo = message.getErrorInfo(); | ||
String error = ExceptionUtils.getStackTrace(errorInfo.getException()); | ||
|
||
List<Message> messages = Collections.singletonList(message); | ||
Assert.assertEquals(0, logDlqWriter.write(messages).size()); | ||
|
||
Mockito.verify(firehoseInstrumentation, Mockito.times(1)).logInfo("key: {}\nvalue: {}\nerror: {}", "", value, error); | ||
} | ||
|
||
@Test | ||
public void shouldWriteMessagesToLogWhenValueIsNull() throws IOException { | ||
long timestamp = Instant.parse("2020-01-01T00:00:00Z").toEpochMilli(); | ||
Message message = new Message("123".getBytes(), null, "booking", 1, 1, null, timestamp, timestamp, new ErrorInfo(new IOException("test"), ErrorType.DESERIALIZATION_ERROR)); | ||
|
||
String key = new String(message.getLogKey()); | ||
ErrorInfo errorInfo = message.getErrorInfo(); | ||
String error = ExceptionUtils.getStackTrace(errorInfo.getException()); | ||
|
||
List<Message> messages = Collections.singletonList(message); | ||
Assert.assertEquals(0, logDlqWriter.write(messages).size()); | ||
|
||
Mockito.verify(firehoseInstrumentation, Mockito.times(1)).logInfo("key: {}\nvalue: {}\nerror: {}", key, "", error); | ||
} | ||
|
||
@Test | ||
public void shouldWriteMessagesToLogWhenErrorInfoIsNull() throws IOException { | ||
long timestamp = Instant.parse("2020-01-01T00:00:00Z").toEpochMilli(); | ||
Message message = new Message("123".getBytes(), "abc".getBytes(), "booking", 1, 1, null, timestamp, timestamp, null); | ||
|
||
String key = new String(message.getLogKey()); | ||
String value = new String(message.getLogMessage()); | ||
|
||
List<Message> messages = Collections.singletonList(message); | ||
Assert.assertEquals(0, logDlqWriter.write(messages).size()); | ||
|
||
Mockito.verify(firehoseInstrumentation, Mockito.times(1)).logInfo("key: {}\nvalue: {}\nerror: {}", key, value, ""); | ||
} | ||
|
||
@Test | ||
public void shouldWriteMessagesToLogWhenErrorInfoExceptionIsNull() throws IOException { | ||
long timestamp = Instant.parse("2020-01-01T00:00:00Z").toEpochMilli(); | ||
Message message = new Message("123".getBytes(), "abc".getBytes(), "booking", 1, 1, null, timestamp, timestamp, new ErrorInfo(null, ErrorType.DESERIALIZATION_ERROR)); | ||
|
||
String key = new String(message.getLogKey()); | ||
String value = new String(message.getLogMessage()); | ||
|
||
List<Message> messages = Collections.singletonList(message); | ||
Assert.assertEquals(0, logDlqWriter.write(messages).size()); | ||
|
||
Mockito.verify(firehoseInstrumentation, Mockito.times(1)).logInfo("key: {}\nvalue: {}\nerror: {}", key, value, ""); | ||
} | ||
} |
Oops, something went wrong.