Return HTTP 400 with informative message for client-side protobuf val…#6989
Return HTTP 400 with informative message for client-side protobuf val…#6989indrajababu wants to merge 3 commits into
Conversation
…idation errors Signed-off-by: Indraja Babu <indbabu@amazon.com>
dlvenable
left a comment
There was a problem hiding this comment.
Thank you @indrajababu for this contribution to Data Prepper!
| badRequestsCounter.increment(); | ||
| return Status.INVALID_ARGUMENT.withDescription(InvalidRequestExceptions.INVALID_PROTOBUF_MESSAGE).withCause(cause); | ||
| } | ||
| if (InvalidRequestExceptions.isUndecodableCompressedFrame(cause)) { |
There was a problem hiding this comment.
You have two conditions that you change here. Are there more that should be 400? Is there a helper within Armeria that can say "this can be a 400?"
| + "libraries producing this telemetry and correct the source emitting the malformed data."; | ||
|
|
||
| public static final String COMPRESSED_FRAME_MESSAGE = | ||
| "Unable to decode the compressed request frame. This is a client-side data issue, not a server error. " |
There was a problem hiding this comment.
This is a client-side data issue, not a server error.
This might not be completely accurate. It is an indicator of a mismatch.
Maybe say:
This is a problem with the client-side request or a misconfiguration of the pipeline source.
| final String grpcMessage = response.headers().get("grpc-message"); | ||
| final String detail = grpcMessage != null ? grpcMessage : response.contentUtf8(); | ||
| assertThat("Client should receive an informative, client-side-oriented message", | ||
| detail, containsString("client-side data issue")); |
There was a problem hiding this comment.
This is a good approach to testing. But, I'd look more for this string instead: contain valid UTF-8
| } | ||
|
|
||
| @Test | ||
| void unframedRequests_protobufWithInvalidUtf8_returns400WithInformativeMessage() { |
There was a problem hiding this comment.
Can you also have a test for invalid compression?
…ch/dataprepper/InvalidRequestExceptions.java Co-authored-by: David Venable <dev@venable.io> Signed-off-by: Indraja Babu <156961807+indrajababu@users.noreply.github.com>
…ch/dataprepper/InvalidRequestExceptions.java Co-authored-by: David Venable <dev@venable.io> Signed-off-by: Indraja Babu <156961807+indrajababu@users.noreply.github.com>
Description
When a client sends a protobuf request containing invalid UTF-8 in string fields
(e.g., InstrumentationScope name/version), the pipeline currently returns HTTP 500
with a generic error. This change returns HTTP 400 with a client-actionable message
explaining the issue.
Changes
apply()in GrpcRequestExceptionHandler to interceptInvalidProtocolBufferException before Armeria's default short-circuit
Testing
Issues Resolved
Resolves #6991
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.