-
Notifications
You must be signed in to change notification settings - Fork 332
Otel logs source http service #6250
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
Merged
KarstenSchnitter
merged 23 commits into
opensearch-project:main
from
sternadsoftware:otel-logs-source-http-service
Feb 20, 2026
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
646b02b
[WIP]
TomasLongo c52d4c9
[WIP]
TomasLongo ec77c3b
[WIP]
TomasLongo 5f863a4
[WIP] Integrate http service and make sure it works properly
TomasLongo 7747436
Integrate grpc and http service into a single server
TomasLongo eef7d52
Refactoring. Cleanup tests
TomasLongo 61016a1
Extract tests that assert grpc requests
TomasLongo 6812a24
Clean up
TomasLongo 3f21bce
Revert introduction of CertificatProvider interface
TomasLongo 8be400a
Cleanup
TomasLongo 2efce64
Fix return value of http service
TomasLongo be398bf
Re-introduce unframed request for the grpc service
TomasLongo 53e7126
Incorporate review suggestions
TomasLongo 64382fa
Add E2E test
TomasLongo bdac9f2
Add E2E test for gRPC
TomasLongo ac428aa
Remove unused imports
TomasLongo 0b23b4d
Add test for unframed requests
TomasLongo 4207c71
Add e2e test for unframed requests
TomasLongo 7269fe9
Add e2e test for protobuf requests
TomasLongo e1a839d
Fix media type for protobuf payload
TomasLongo 5ad01cc
Update license headers
TomasLongo 302c619
Adhere to config when it comes to chose a codec
TomasLongo 8285d1f
Inject OtelProtoCodec into ArmeriaHttpService
TomasLongo 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
This file contains hidden or 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 hidden or 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
26 changes: 0 additions & 26 deletions
26
...rc/main/java/org/opensearch/dataprepper/plugins/source/otellogs/ConvertConfiguration.java
This file was deleted.
Oops, something went wrong.
221 changes: 193 additions & 28 deletions
221
...urce/src/main/java/org/opensearch/dataprepper/plugins/source/otellogs/OTelLogsSource.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
120 changes: 120 additions & 0 deletions
120
...main/java/org/opensearch/dataprepper/plugins/source/otellogs/http/ArmeriaHttpService.java
This file contains hidden or 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,120 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| * | ||
| */ | ||
|
|
||
| package org.opensearch.dataprepper.plugins.source.otellogs.http; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.opensearch.dataprepper.exceptions.BadRequestException; | ||
| import org.opensearch.dataprepper.exceptions.BufferWriteException; | ||
| import org.opensearch.dataprepper.logging.DataPrepperMarkers; | ||
| import org.opensearch.dataprepper.metrics.PluginMetrics; | ||
| import org.opensearch.dataprepper.model.buffer.Buffer; | ||
| import org.opensearch.dataprepper.model.log.OpenTelemetryLog; | ||
| import org.opensearch.dataprepper.model.record.Record; | ||
| import org.opensearch.dataprepper.plugins.otel.codec.OTelProtoCodec; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import com.linecorp.armeria.server.ServiceRequestContext; | ||
| import com.linecorp.armeria.server.annotation.ConsumesJson; | ||
| import com.linecorp.armeria.server.annotation.ConsumesProtobuf; | ||
| import com.linecorp.armeria.server.annotation.Post; | ||
|
|
||
| import io.micrometer.core.instrument.Counter; | ||
| import io.micrometer.core.instrument.DistributionSummary; | ||
| import io.micrometer.core.instrument.Timer; | ||
| import io.opentelemetry.proto.collector.logs.v1.ExportLogsServiceRequest; | ||
| import io.opentelemetry.proto.collector.logs.v1.ExportLogsServiceResponse; | ||
|
|
||
| public class ArmeriaHttpService { | ||
| private static final Logger LOG = LoggerFactory.getLogger(ArmeriaHttpService.class); | ||
|
|
||
| public static final String REQUESTS_RECEIVED = "requestsReceived"; | ||
| public static final String SUCCESS_REQUESTS = "successRequests"; | ||
| public static final String PAYLOAD_SIZE = "payloadSize"; | ||
| public static final String REQUEST_PROCESS_DURATION = "requestProcessDuration"; | ||
|
|
||
| private final OTelProtoCodec.OTelProtoDecoder oTelProtoDecoder; | ||
| private final Buffer<Record<Object>> buffer; | ||
|
|
||
| private final int bufferWriteTimeoutInMillis; | ||
|
|
||
| private final Counter requestsReceivedCounter; | ||
| private final Counter successRequestsCounter; | ||
| private final DistributionSummary payloadSizeSummary; | ||
| private final Timer requestProcessDuration; | ||
|
|
||
| public ArmeriaHttpService( | ||
| Buffer<Record<Object>> buffer, | ||
| final PluginMetrics pluginMetrics, | ||
| final int bufferWriteTimeoutInMillis, | ||
| final OTelProtoCodec.OTelProtoDecoder oTelProtoDecoder | ||
| ) { | ||
| this.buffer = buffer; | ||
| this.oTelProtoDecoder = oTelProtoDecoder; | ||
| this.bufferWriteTimeoutInMillis = bufferWriteTimeoutInMillis; | ||
|
|
||
| requestsReceivedCounter = pluginMetrics.counter(REQUESTS_RECEIVED); | ||
| successRequestsCounter = pluginMetrics.counter(SUCCESS_REQUESTS); | ||
| payloadSizeSummary = pluginMetrics.summary(PAYLOAD_SIZE); | ||
| requestProcessDuration = pluginMetrics.timer(REQUEST_PROCESS_DURATION); | ||
| } | ||
|
|
||
| // no path provided. Will be set by config. | ||
| @Post("") | ||
| @ConsumesJson | ||
| @ConsumesProtobuf | ||
| public ExportLogsServiceResponse exportLog(ExportLogsServiceRequest request) { | ||
| requestsReceivedCounter.increment(); | ||
| payloadSizeSummary.record(request.getSerializedSize()); | ||
|
|
||
| requestProcessDuration.record(() -> processRequest(request)); | ||
|
|
||
| return ExportLogsServiceResponse.newBuilder().build(); | ||
| } | ||
|
|
||
| private void processRequest(final ExportLogsServiceRequest request) { | ||
| final List<OpenTelemetryLog> logs; | ||
|
|
||
| try { | ||
| logs = oTelProtoDecoder.parseExportLogsServiceRequest(request, Instant.now()); | ||
| } catch (Exception e) { | ||
| LOG.warn(DataPrepperMarkers.SENSITIVE, "Failed to parse the request with error {}. Request body: {}", e, request); | ||
| throw new BadRequestException(e.getMessage(), e); | ||
| } | ||
|
|
||
| try { | ||
| if (buffer.isByteBuffer()) { | ||
| buffer.writeBytes(request.toByteArray(), null, bufferWriteTimeoutInMillis); | ||
| } else { | ||
| final List<Record<Object>> records = logs.stream().map(log -> new Record<Object>(log)).collect(Collectors.toList()); | ||
| buffer.writeAll(records, bufferWriteTimeoutInMillis); | ||
| } | ||
| } catch (Exception e) { | ||
| if (ServiceRequestContext.current().isTimedOut()) { | ||
| LOG.warn("Exception writing to buffer but request already timed out.", e); | ||
| return; | ||
| } | ||
|
|
||
| LOG.error("Failed to write the request of size {} due to:", request.toString().length(), e); | ||
| throw new BufferWriteException(e.getMessage(), e); | ||
| } | ||
|
|
||
| if (ServiceRequestContext.current().isTimedOut()) { | ||
| LOG.warn("Buffer write completed successfully but request already timed out."); | ||
| return; | ||
| } | ||
|
|
||
| successRequestsCounter.increment(); | ||
| } | ||
| } | ||
158 changes: 158 additions & 0 deletions
158
...in/java/org/opensearch/dataprepper/plugins/source/otellogs/http/HttpExceptionHandler.java
This file contains hidden or 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,158 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| * | ||
| */ | ||
|
|
||
| package org.opensearch.dataprepper.plugins.source.otellogs.http; | ||
|
TomasLongo marked this conversation as resolved.
|
||
|
|
||
|
|
||
| import java.time.Duration; | ||
| import java.util.concurrent.TimeoutException; | ||
|
|
||
| import org.opensearch.dataprepper.RetryInfoCalculator; | ||
| import org.opensearch.dataprepper.exceptions.BadRequestException; | ||
| import org.opensearch.dataprepper.exceptions.BufferWriteException; | ||
| import org.opensearch.dataprepper.exceptions.RequestCancelledException; | ||
| import org.opensearch.dataprepper.metrics.PluginMetrics; | ||
| import org.opensearch.dataprepper.model.buffer.SizeOverflowException; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import com.google.protobuf.Any; | ||
| import com.google.protobuf.InvalidProtocolBufferException; | ||
| import com.google.protobuf.util.JsonFormat; | ||
| import com.google.rpc.RetryInfo; | ||
| import com.linecorp.armeria.common.ContentTooLargeException; | ||
| import com.linecorp.armeria.common.HttpRequest; | ||
| import com.linecorp.armeria.common.HttpResponse; | ||
| import com.linecorp.armeria.common.HttpStatus; | ||
| import com.linecorp.armeria.common.MediaType; | ||
| import com.linecorp.armeria.server.HttpStatusException; | ||
| import com.linecorp.armeria.server.RequestTimeoutException; | ||
| import com.linecorp.armeria.server.ServiceRequestContext; | ||
| import com.linecorp.armeria.server.annotation.ExceptionHandlerFunction; | ||
|
|
||
| import io.grpc.Status; | ||
| import io.grpc.StatusRuntimeException; | ||
| import io.micrometer.core.instrument.Counter; | ||
|
|
||
| public class HttpExceptionHandler implements ExceptionHandlerFunction { | ||
| private static final Logger LOG = LoggerFactory.getLogger(HttpExceptionHandler.class); | ||
|
|
||
| static final String ARMERIA_REQUEST_TIMEOUT_MESSAGE = "Timeout waiting for request to be served. This is usually due to the buffer being full."; | ||
| public static final String REQUEST_TIMEOUTS = "requestTimeouts"; | ||
| public static final String BAD_REQUESTS = "badRequests"; | ||
| public static final String REQUESTS_TOO_LARGE = "requestsTooLarge"; | ||
| public static final String INTERNAL_SERVER_ERROR = "internalServerError"; | ||
|
|
||
| private final Counter requestTimeoutsCounter; | ||
| private final Counter badRequestsCounter; | ||
| private final Counter requestsTooLargeCounter; | ||
| private final Counter internalServerErrorCounter; | ||
| private final RetryInfoCalculator retryInfoCalculator; | ||
|
|
||
| public HttpExceptionHandler(final PluginMetrics pluginMetrics, Duration retryInfoMinDelay, Duration retryInfoMaxDelay) { | ||
| requestTimeoutsCounter = pluginMetrics.counter(REQUEST_TIMEOUTS); | ||
| badRequestsCounter = pluginMetrics.counter(BAD_REQUESTS); | ||
| requestsTooLargeCounter = pluginMetrics.counter(REQUESTS_TOO_LARGE); | ||
| internalServerErrorCounter = pluginMetrics.counter(INTERNAL_SERVER_ERROR); | ||
| this.retryInfoCalculator = new RetryInfoCalculator(retryInfoMinDelay, retryInfoMaxDelay); | ||
| } | ||
|
|
||
| @Override | ||
| public HttpResponse handleException(final ServiceRequestContext ctx, | ||
| final HttpRequest req, | ||
| final Throwable e) { | ||
| final Throwable exceptionCause; | ||
| if (e instanceof BufferWriteException) { | ||
| exceptionCause = e.getCause(); | ||
| } else if (e instanceof HttpStatusException) { | ||
| exceptionCause = e.getCause(); | ||
| } else { | ||
| exceptionCause = e; | ||
| } | ||
|
|
||
| StatusHolder statusHolder = createStatus(exceptionCause); | ||
|
|
||
| try { | ||
| JsonFormat.TypeRegistry typeRegistry = JsonFormat.TypeRegistry.newBuilder() | ||
| .add(RetryInfo.getDescriptor()) | ||
| .build(); | ||
|
|
||
| JsonFormat.Printer printer = JsonFormat.printer().usingTypeRegistry(typeRegistry); | ||
| return HttpResponse.of(statusHolder.getHttpStatus(), MediaType.JSON, printer.print(statusHolder.getStatus())); | ||
| } catch (InvalidProtocolBufferException ipbe) { | ||
| throw new RuntimeException(ipbe); | ||
| } | ||
| } | ||
|
|
||
| private StatusHolder createStatus(Throwable e) { | ||
| if (e instanceof RequestTimeoutException || e instanceof TimeoutException) { | ||
| requestTimeoutsCounter.increment(); | ||
| return new StatusHolder(createStatus(e, Status.Code.RESOURCE_EXHAUSTED), createHttpStatusFromProtoBufStatus(Status.Code.RESOURCE_EXHAUSTED)); | ||
| } else if (e instanceof SizeOverflowException || e instanceof ContentTooLargeException) { | ||
| requestsTooLargeCounter.increment(); | ||
| return new StatusHolder(createStatus(e, Status.Code.RESOURCE_EXHAUSTED), createHttpStatusFromProtoBufStatus(Status.Code.RESOURCE_EXHAUSTED)); | ||
| } else if (e instanceof BadRequestException) { | ||
| badRequestsCounter.increment(); | ||
| return new StatusHolder(createStatus(e, Status.Code.INVALID_ARGUMENT), createHttpStatusFromProtoBufStatus(Status.Code.INVALID_ARGUMENT)); | ||
| } else if ((e instanceof StatusRuntimeException) && (e.getMessage().contains("Invalid protobuf byte sequence") || e.getMessage().contains("Can't decode compressed frame"))) { | ||
| badRequestsCounter.increment(); | ||
| return new StatusHolder(createStatus(e, Status.Code.INVALID_ARGUMENT), createHttpStatusFromProtoBufStatus(Status.Code.INVALID_ARGUMENT)); | ||
| } else if (e instanceof RequestCancelledException) { | ||
| requestTimeoutsCounter.increment(); | ||
| return new StatusHolder(createStatus(e, Status.Code.CANCELLED), createHttpStatusFromProtoBufStatus(Status.Code.CANCELLED)); | ||
| } else { | ||
| LOG.error("Unexpected exception handling http request", e); | ||
| internalServerErrorCounter.increment(); | ||
| return new StatusHolder(createStatus(e, Status.Code.INTERNAL), createHttpStatusFromProtoBufStatus(Status.Code.INTERNAL)); | ||
| } | ||
| } | ||
|
|
||
| private HttpStatus createHttpStatusFromProtoBufStatus(Status.Code status) { | ||
| if (status == Status.Code.RESOURCE_EXHAUSTED) { | ||
| return HttpStatus.INSUFFICIENT_STORAGE; | ||
| } else if (status == Status.Code.INVALID_ARGUMENT) { | ||
| return HttpStatus.BAD_REQUEST; | ||
| } else { | ||
| return HttpStatus.INTERNAL_SERVER_ERROR; | ||
| } | ||
| } | ||
|
|
||
| private com.google.rpc.Status createStatus(final Throwable e, final Status.Code code) { | ||
| com.google.rpc.Status.Builder builder = com.google.rpc.Status.newBuilder().setCode(code.value()); | ||
| if (e instanceof RequestTimeoutException) { | ||
| builder.setMessage(ARMERIA_REQUEST_TIMEOUT_MESSAGE); | ||
| } else { | ||
| builder.setMessage(e.getMessage() == null ? code.name() :e.getMessage()); | ||
| } | ||
| if (code == Status.Code.RESOURCE_EXHAUSTED) { | ||
| builder.addDetails(Any.pack(retryInfoCalculator.createRetryInfo())); | ||
| } | ||
| return builder.build(); | ||
| } | ||
|
|
||
| private static class StatusHolder { | ||
| private final HttpStatus httpStatus; | ||
| private final com.google.rpc.Status status; | ||
|
|
||
| public StatusHolder(com.google.rpc.Status status, HttpStatus httpStatus) { | ||
| this.httpStatus = httpStatus; | ||
| this.status = status; | ||
| } | ||
|
|
||
| public HttpStatus getHttpStatus() { | ||
| return httpStatus; | ||
| } | ||
|
|
||
| public com.google.rpc.Status getStatus() { | ||
| return status; | ||
| } | ||
| } | ||
|
|
||
| } | ||
5 changes: 5 additions & 0 deletions
5
...test/java/org/opensearch/dataprepper/plugins/source/otellogs/OTelLogsGrpcServiceTest.java
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.