-
Notifications
You must be signed in to change notification settings - Fork 218
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
Fix to better handle lambda responses when they are empty or null or not a valid json #5211
Fix to better handle lambda responses when they are empty or null or not a valid json #5211
Conversation
…not a valid json Signed-off-by: Santhosh Gandhe <1909520+san81@users.noreply.github.com>
Signed-off-by: Santhosh Gandhe <1909520+san81@users.noreply.github.com>
Signed-off-by: Santhosh Gandhe <1909520+san81@users.noreply.github.com>
Signed-off-by: Santhosh Gandhe <1909520+san81@users.noreply.github.com>
@@ -72,6 +73,7 @@ public class LambdaProcessor extends AbstractProcessor<Record<Event>, Record<Eve | |||
private final Counter numberOfRecordsFailedCounter; | |||
private final Counter numberOfRequestsSuccessCounter; | |||
private final Counter numberOfRequestsFailedCounter; | |||
private final Counter lambdaResponseRecordsCounter; |
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.
Should we use a DistributionSummary
here? This will let us both count and understand the sizes per request.
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.
@dlvenable let's do this in the follow up PR
"Lambda response payload is null or empty, dropping the original events"); | ||
return responseStrategy.handleEvents(parsedEvents, originalRecords); | ||
// Considering "null" payload as empty response from lambda and not parsing it. | ||
if (!("null".equals(payload.asUtf8String()))) { |
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.
Can you explain the "null"
string situation?
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.
Like then Lambda response is a plain one word "null" then we are considering it as empty response and not trying to parse it. It is basically like no response from lambda so we are going to drop all the records in the case of AggregateMode but fail in the case of StrictMode
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.
Is this a Lambda response or a response from the Lambda function?
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.
This is lambda response.
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.
Let's make this a constant with a useful name.
e.g.
private static final NO_RETURN_RESPONSE = "null"
assertThrows(RuntimeException.class, () -> localLambdaProcessor.convertLambdaResponseToEvent(buffer, invokeResponse), | ||
"For Strict mode request and response size from lambda should match"); | ||
|
||
if (null != expectedException) { |
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.
It's better not to have conditionals in tests. This can be flaky and hard to understand.
Can we split this into two tests with two different ArgumentsSources methods/providers?
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.
Oh in this case, it is basically like, is there an exception to assert or no. The check is only based on the arguments but not based on the logic. I think we do have such pattern else where.
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.
I think it is a pattern best avoided.
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.
But, we can keep for now.
Signed-off-by: Santhosh Gandhe <1909520+san81@users.noreply.github.com>
Signed-off-by: Santhosh Gandhe <1909520+san81@users.noreply.github.com>
Signed-off-by: Srikanth Govindarajan <srigovs@amazon.com>
lambdaRegion = System.getProperty("tests.lambda.processor.region"); | ||
functionName = System.getProperty("tests.lambda.processor.functionName"); | ||
role = System.getProperty("tests.lambda.processor.sts_role_arn"); | ||
// lambdaRegion = System.getProperty("tests.lambda.processor.region"); |
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.
I think you meant to revert this comment. This will not work in our CI.
"Lambda response payload is null or empty, dropping the original events"); | ||
return responseStrategy.handleEvents(parsedEvents, originalRecords); | ||
// Considering "null" payload as empty response from lambda and not parsing it. | ||
if (!("null".equals(payload.asUtf8String()))) { |
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.
Is this a Lambda response or a response from the Lambda function?
Signed-off-by: Santhosh Gandhe <1909520+san81@users.noreply.github.com>
Signed-off-by: Srikanth Govindarajan <srigovs@amazon.com>
Signed-off-by: Santhosh Gandhe <1909520+san81@users.noreply.github.com>
Signed-off-by: Srikanth Govindarajan <srigovs@amazon.com>
Signed-off-by: Srikanth Govindarajan <srigovs@amazon.com>
arguments("lambda-processor-success-config.yaml", thirdSample, "random string",thirdSample, true), | ||
arguments("lambda-processor-success-config.yaml", fourthSample, SdkBytes.fromByteArray("[]".getBytes()), fourthSample, true), | ||
arguments("lambda-processor-success-config.yaml", fifthSample, SdkBytes.fromByteArray(fifthSampleJsonString.getBytes()), fifthSample, false)/*, | ||
arguments("lambda-processor-success-config.yaml", getSampleEventRecords(1), SdkBytes.fromByteArray("[{\"key\":\"val\"}, {\"key\":\"val\"}]".getBytes()),Collections.emptyList()), |
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.
Please remove commented out code
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.
Removed
assertThrows(RuntimeException.class, () -> localLambdaProcessor.convertLambdaResponseToEvent(buffer, invokeResponse), | ||
"For Strict mode request and response size from lambda should match"); | ||
|
||
if (null != expectedException) { |
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.
I think it is a pattern best avoided.
...a/src/test/java/org/opensearch/dataprepper/plugins/lambda/processor/LambdaProcessorTest.java
Outdated
Show resolved
Hide resolved
@@ -73,6 +97,8 @@ | |||
import static org.opensearch.dataprepper.plugins.lambda.utils.LambdaTestSetupUtil.getSampleEventRecords; | |||
import static org.opensearch.dataprepper.plugins.lambda.utils.LambdaTestSetupUtil.getSampleRecord; | |||
|
|||
======= |
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.
Merge conflicts
"Lambda response payload is null or empty, dropping the original events"); | ||
return responseStrategy.handleEvents(parsedEvents, originalRecords); | ||
// Considering "null" payload as empty response from lambda and not parsing it. | ||
if (!("null".equals(payload.asUtf8String()))) { |
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.
Let's make this a constant with a useful name.
e.g.
private static final NO_RETURN_RESPONSE = "null"
throw new RuntimeException( | ||
"Response Processing Mode is configured as Strict mode but behavior is aggregate mode. Event count mismatch."); | ||
throw new StrictResponseModeNotRespectedException( | ||
"Response Processing Mode is configured as Strict mode but behavior is aggregate mode. " + |
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.
"The aws_lambda processor is configured with response_events_match set to true. The Lambda function responded with a different number of events. Either set response_events_match to false or investigate your Lambda function to ensure that it returns the same number of events and provided as input. parsedEvents size = . Original events size = "
Signed-off-by: Srikanth Govindarajan <srigovs@amazon.com>
Description
In the cases where the Lambda response is not a proper Json, we are better handling the logic now as described below
Issues Resolved
Resolves #[Issue number to be closed when this PR is merged]
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.