-
Notifications
You must be signed in to change notification settings - Fork 202
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
Support otel_logs codec in S3 source (#5028) #5030
Merged
dlvenable
merged 6 commits into
opensearch-project:main
from
danhli:otel-logs-s3-source
Oct 11, 2024
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f78f11c
Support otlp_json_logs codec in S3 source (#5028)
danhli a67c31a
Add copyright info (#5028)
danhli e3c5b91
Update class loader (#5028)
danhli ac291d6
Change the codec's name to opentelemetry_logs (#5028)
danhli ae110fd
Change the codec's name to otel_logs (#5028)
danhli dfeeb97
Add documentation and otel_logs format option enum (#5028)
danhli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...common/src/main/java/org/opensearch/dataprepper/plugins/otel/codec/OTLPJsonLogsCodec.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,22 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.otel.codec; | ||
|
||
import org.opensearch.dataprepper.model.annotations.DataPrepperPlugin; | ||
import org.opensearch.dataprepper.model.codec.InputCodec; | ||
import org.opensearch.dataprepper.model.event.Event; | ||
import org.opensearch.dataprepper.model.record.Record; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.function.Consumer; | ||
|
||
@DataPrepperPlugin(name = "opentelemetry_logs", pluginType = InputCodec.class) | ||
public class OTLPJsonLogsCodec extends OTLPJsonLogsDecoder implements InputCodec { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you rename this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed it to |
||
public void parse(InputStream inputStream, Consumer<Record<Event>> eventConsumer) throws IOException { | ||
parse(inputStream, null, eventConsumer); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...mmon/src/main/java/org/opensearch/dataprepper/plugins/otel/codec/OTLPJsonLogsDecoder.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,41 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.dataprepper.plugins.otel.codec; | ||
|
||
import io.opentelemetry.proto.collector.logs.v1.ExportLogsServiceRequest; | ||
import org.opensearch.dataprepper.model.codec.ByteDecoder; | ||
import org.opensearch.dataprepper.model.record.Record; | ||
|
||
import com.google.protobuf.util.JsonFormat; | ||
|
||
import org.opensearch.dataprepper.model.event.Event; | ||
import org.opensearch.dataprepper.model.log.OpenTelemetryLog; | ||
|
||
import java.util.List; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.util.function.Consumer; | ||
import java.time.Instant; | ||
|
||
|
||
public class OTLPJsonLogsDecoder implements ByteDecoder { | ||
private final OTelProtoCodec.OTelProtoDecoder otelProtoDecoder; | ||
public OTLPJsonLogsDecoder() { | ||
otelProtoDecoder = new OTelProtoCodec.OTelProtoDecoder(); | ||
} | ||
public void parse(InputStream inputStream, Instant timeReceivedMs, Consumer<Record<Event>> eventConsumer) throws IOException { | ||
Reader reader = new InputStreamReader(inputStream); | ||
ExportLogsServiceRequest.Builder builder = ExportLogsServiceRequest.newBuilder(); | ||
JsonFormat.parser().merge(reader, builder); | ||
ExportLogsServiceRequest request = builder.build(); | ||
List<OpenTelemetryLog> logs = otelProtoDecoder.parseExportLogsServiceRequest(request, timeReceivedMs); | ||
for (OpenTelemetryLog log: logs) { | ||
eventConsumer.accept(new Record<>(log)); | ||
} | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...on/src/test/java/org/opensearch/dataprepper/plugins/otel/codec/OTLPJsonLogsCodecTest.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,47 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.otel.codec; | ||
|
||
import java.io.InputStream; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
import org.opensearch.dataprepper.model.log.OpenTelemetryLog; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class OTLPJsonLogsCodecTest { | ||
private static final String TEST_REQUEST_LOGS_FILE = "test-request-multiple-logs.json"; | ||
|
||
public OTLPJsonLogsCodec createObjectUnderTest() { | ||
return new OTLPJsonLogsCodec(); | ||
} | ||
|
||
private void validateLog(OpenTelemetryLog logRecord) { | ||
assertThat(logRecord.getServiceName(), is("service")); | ||
assertThat(logRecord.getTime(), is("2020-05-24T14:00:00Z")); | ||
assertThat(logRecord.getObservedTime(), is("2020-05-24T14:00:02Z")); | ||
assertThat(logRecord.getBody(), is("Log value")); | ||
assertThat(logRecord.getDroppedAttributesCount(), is(3)); | ||
assertThat(logRecord.getSchemaUrl(), is("schemaurl")); | ||
assertThat(logRecord.getSeverityNumber(), is(5)); | ||
assertThat(logRecord.getSeverityText(), is("Severity value")); | ||
assertThat(logRecord.getTraceId(), is("ba1a1c23b4093b63")); | ||
assertThat(logRecord.getSpanId(), is("2cc83ac90ebc469c")); | ||
Map<String, Object> mergedAttributes = logRecord.getAttributes(); | ||
assertThat(mergedAttributes.keySet().size(), is(2)); | ||
assertThat(mergedAttributes.get("log.attributes.statement@params"), is("us-east-1")); | ||
assertThat(mergedAttributes.get("resource.attributes.service@name"), is("service")); | ||
} | ||
|
||
@Test | ||
public void testParse() throws Exception { | ||
InputStream inputStream = OTLPJsonLogsCodecTest.class.getClassLoader().getResourceAsStream(TEST_REQUEST_LOGS_FILE); | ||
createObjectUnderTest().parse(inputStream, (record) -> { | ||
validateLog((OpenTelemetryLog)record.getData()); | ||
}); | ||
|
||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
.../src/test/java/org/opensearch/dataprepper/plugins/otel/codec/OTLPJsonLogsDecoderTest.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,48 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.otel.codec; | ||
|
||
import java.io.InputStream; | ||
import java.time.Instant; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
import org.opensearch.dataprepper.model.log.OpenTelemetryLog; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class OTLPJsonLogsDecoderTest { | ||
private static final String TEST_REQUEST_LOGS_FILE = "test-request-multiple-logs.json"; | ||
|
||
public OTLPJsonLogsDecoder createObjectUnderTest() { | ||
return new OTLPJsonLogsDecoder(); | ||
} | ||
|
||
private void validateLog(OpenTelemetryLog logRecord) { | ||
assertThat(logRecord.getServiceName(), is("service")); | ||
assertThat(logRecord.getTime(), is("2020-05-24T14:00:00Z")); | ||
assertThat(logRecord.getObservedTime(), is("2020-05-24T14:00:02Z")); | ||
assertThat(logRecord.getBody(), is("Log value")); | ||
assertThat(logRecord.getDroppedAttributesCount(), is(3)); | ||
assertThat(logRecord.getSchemaUrl(), is("schemaurl")); | ||
assertThat(logRecord.getSeverityNumber(), is(5)); | ||
assertThat(logRecord.getSeverityText(), is("Severity value")); | ||
assertThat(logRecord.getTraceId(), is("ba1a1c23b4093b63")); | ||
assertThat(logRecord.getSpanId(), is("2cc83ac90ebc469c")); | ||
Map<String, Object> mergedAttributes = logRecord.getAttributes(); | ||
assertThat(mergedAttributes.keySet().size(), is(2)); | ||
assertThat(mergedAttributes.get("log.attributes.statement@params"), is("us-east-1")); | ||
assertThat(mergedAttributes.get("resource.attributes.service@name"), is("service")); | ||
} | ||
|
||
@Test | ||
public void testParse() throws Exception { | ||
InputStream inputStream = OTLPJsonLogsDecoderTest.class.getClassLoader().getResourceAsStream(TEST_REQUEST_LOGS_FILE); | ||
createObjectUnderTest().parse(inputStream, Instant.now(), (record) -> { | ||
validateLog((OpenTelemetryLog)record.getData()); | ||
}); | ||
|
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be
otel_json_logs
orotel_logs_json
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to
otel_logs
.