Skip to content
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(stepfunctions): item batcher doesn't properly render json paths #29152

Closed
wants to merge 2 commits into from

Conversation

noseworthy
Copy link

@noseworthy noseworthy commented Feb 17, 2024

Reason for this change

The ItemBatcher property of DistributedMap supports json path fields, but the new DistributedMap construct doesn't call
FieldUtils.renderObject when rendering the ItemBatcher.

Description of changes

Make sure to call FieldUtils.renderObject() when rendering this property.

Description of how you validated changes

  • Added a unit test to ensure that the proper cloudformation step function definition is generated. This ensures that the definition includes adding '.$' to the end of keys that contain json path values.
  • Added an integration test that creates a distributed map based step function that uses the item batcher and includes both a constant value and json path field value in the batch input. After successful execution of the state machine, a lambda checks the that the input to the state machine includes both the constant value and the resolved json path value.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team February 17, 2024 21:17
@github-actions github-actions bot added p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Feb 17, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@noseworthy noseworthy force-pushed the fix-item-batcher-render branch from e96a4cd to 85d4433 Compare February 18, 2024 20:21
@aws-cdk-automation aws-cdk-automation dismissed their stale review February 18, 2024 20:22

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Feb 18, 2024
Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍
Can you please update the title to describe the bug (not the solution)?

@aws-cdk-automation aws-cdk-automation added pr/needs-maintainer-review This PR needs a review from a Core Team Member and removed pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Mar 30, 2024
@noseworthy noseworthy changed the title fix(stepfunctions): support json path fields for item batcher fix(stepfunctions): item batcher doesn't properly render json paths Mar 30, 2024
@noseworthy
Copy link
Author

Looks good to me 👍 Can you please update the title to describe the bug (not the solution)?

Done! Thanks for the review!

@noseworthy noseworthy force-pushed the fix-item-batcher-render branch from e951272 to 03ec32f Compare March 31, 2024 16:29
@noseworthy
Copy link
Author

Rebased on main and amended the commit message.

@godwingrs22 godwingrs22 self-requested a review April 17, 2024 17:46
@godwingrs22 godwingrs22 self-assigned this Apr 17, 2024
@godwingrs22
Copy link
Member

@noseworthy Thank you for this contribution. But I would like to get more context on the issue we are trying to solve.

  • Could you provide more detail on the issue please?
  • Do we have any open issue ticket that can be linked to this PR?

@@ -631,6 +634,9 @@ describe('Distributed Map State', () => {
ToleratedFailurePercentagePath: '$.toleratedFailurePercentage',
ToleratedFailureCountPath: '$.toleratedFailureCount',
ItemBatcher: {
BatchInput: {
'TestBatchInput.$': '$.testBatchInput',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you provide detail on why we need to expect '.$' to the key?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to this, a brief comment here explaining why we need the .$ and what it signifies (likely with a link to the relevant docs) would be very helpful

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do! It might be a little while for a proper response. I'm away for the next week, but will try to get to it when I get back.

The long and short of it is that stepfunctions will parse keys that end in .$ as json paths and will look up the value from previous states using the value of this key rather than just passing the value to the next state.

This is done in almost all other state configuration so that values can be dynamically included from previous states, but this functionality was missed here requiring the user to manually specify '.$'. This is confusing and it isn't clear that the json paths aren't automatically rendered by the cdk construct parsing.

See documentation here: https://docs.aws.amazon.com/step-functions/latest/dg/connect-parameters.html#connect-parameters-path

And here: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_stepfunctions.JsonPath.html

@@ -71,7 +73,7 @@ export class ItemBatcher {
...(this.props.maxItemsPerBatchPath && { MaxItemsPerBatchPath: this.props.maxItemsPerBatchPath }),
...(this.props.maxInputBytesPerBatch && { MaxInputBytesPerBatch: this.props.maxInputBytesPerBatch }),
...(this.props.maxInputBytesPerBatchPath && { MaxInputBytesPerBatchPath: this.props.maxInputBytesPerBatchPath }),
...(this.props.batchInput && { BatchInput: this.props.batchInput }),
...(this.props.batchInput && { BatchInput: FieldUtils.renderObject(this.props.batchInput) }),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to update the PR description with detail specifically for batchInput property in the itemBatcher class. To me from the description its not clear specifcally to which property we are modifying.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to understand more on why do we need to render only this specifc batchInput property since the existing behavious itself will be able to pass Json payload to the batchInput property?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to the question above and also to provide some more details in the description.

@noseworthy noseworthy force-pushed the fix-item-batcher-render branch 2 times, most recently from 1b75865 to 5954dd8 Compare June 13, 2024 17:26
@noseworthy noseworthy force-pushed the fix-item-batcher-render branch from 5954dd8 to 2b99080 Compare July 4, 2024 13:14
The ItemBatcher property of DistributedMap supports json path fields,
but the new DistributedMap construct doesn't call
FieldUtils.renderObject when rendering the ItemBatcher.

Make sure to call `FieldUtils.renderObject()` when rendering this
property.

Added an integration test to ensure that the json path field resolves to
the actual value from the state in the input by checking the output from
the results writer in S3.
@noseworthy noseworthy force-pushed the fix-item-batcher-render branch from 2b99080 to 27fff5d Compare September 3, 2024 13:21
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: ec2c608
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@paulhcsun paulhcsun self-assigned this Oct 28, 2024
Copy link
Contributor

@paulhcsun paulhcsun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @noseworthy, just wondering if you're still available to work on this. Theres just the one pending question + an integ test snapshot that needs to be updated. Thanks!

@@ -71,7 +73,7 @@ export class ItemBatcher {
...(this.props.maxItemsPerBatchPath && { MaxItemsPerBatchPath: this.props.maxItemsPerBatchPath }),
...(this.props.maxInputBytesPerBatch && { MaxInputBytesPerBatch: this.props.maxInputBytesPerBatch }),
...(this.props.maxInputBytesPerBatchPath && { MaxInputBytesPerBatchPath: this.props.maxInputBytesPerBatchPath }),
...(this.props.batchInput && { BatchInput: this.props.batchInput }),
...(this.props.batchInput && { BatchInput: FieldUtils.renderObject(this.props.batchInput) }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to the question above and also to provide some more details in the description.

@noseworthy
Copy link
Author

Sorry @paulhcsun, I've been swamped and haven't been able to get back to this yet.

@paulhcsun
Copy link
Contributor

No worries @noseworthy, just wanted to confirm this PR was not abandoned. Though with our automation this will be closed after 3 weeks due to the Changes Requested status.

@gracelu0 gracelu0 removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 5, 2024
@aws-cdk-automation
Copy link
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@aws-cdk-automation
Copy link
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@aws-cdk-automation aws-cdk-automation added the closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. label Dec 14, 2024
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants