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

[SFN] Base Support for States.DataLimitExceeded #10511

Merged
merged 4 commits into from Mar 26, 2024

Conversation

MEPalma
Copy link
Contributor

@MEPalma MEPalma commented Mar 21, 2024

Motivation

Currently the States error States.DataLimitExceeded is not supported by the StepFunctions v2 interpreter. This PR adds grammar support for such States error name, and base support for raising States.DataLimitExceeded exceptions whenever the size of a state or task response is above the quota.
Addresses: #10489

Changes

  • Added grammar support for States.DataLimitExceeded error name parsing
  • Added quota exceptions in service tasks, legacy lambda tasks, generic state size
  • Added snapshot test for each quota guards introduced
  • Resolved related issue for lambda payload handling, for which when this is a utf-8 body stream, it is incorrectly parsed as a json string

@MEPalma MEPalma added the semver: patch Non-breaking changes which can be included in patch releases label Mar 21, 2024
@MEPalma MEPalma added this to the 3.3 milestone Mar 21, 2024
@MEPalma MEPalma requested a review from joe4dev March 21, 2024 16:55
@MEPalma MEPalma self-assigned this Mar 21, 2024
Copy link

github-actions bot commented Mar 21, 2024

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 28m 51s ⏱️ -41s
2 727 tests +6  2 472 ✅ +6  255 💤 ±0  0 ❌ ±0 
2 729 runs  +6  2 472 ✅ +6  257 💤 ±0  0 ❌ ±0 

Results for commit 0b0c846. ± Comparison against base commit 241f5a1.

♻️ This comment has been updated with latest results.

Copy link
Member

@joe4dev joe4dev left a comment

Choose a reason for hiding this comment

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

Thanks for jumping on that issue so quickly @MEPalma 👏

Nothing blocking, just a couple of improvement suggestions 👍



def is_within_size_quota(value: Union[str, json]) -> bool:
item_str = value if isinstance(value, str) else to_json_str(value)
Copy link
Member

Choose a reason for hiding this comment

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

StepFunctions is tricky with all these conditional castings 😅

"End": true
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: missing newline?

"Next": "ProcessResult",
"Catch": [
{
// Note: DataLimitExceeded is a terminal error that can't be caught by the States.ALL error type.
Copy link
Member

Choose a reason for hiding this comment

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

Putting json5 to good use with a useful comment 😃

create_lambda_function(
func_name=function_name,
handler_file=EHT.LAMBDA_FUNC_LARGE_OUTPUT_STRING,
runtime="python3.9",
Copy link
Member

Choose a reason for hiding this comment

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

Can we use the typed Runtime.python3_12 here instead?

It would be great to adopt the latest Lambda runtimes for new tests because the al2023 image size is massively smaller, saving us pull time.

Copy link
Member

Choose a reason for hiding this comment

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

same for the other new test cases

FYI: Bojan is currently updating the Lambda runtimes for existing tests, so no need to update them to prevent conflicts

create_state_machine,
sfn_snapshot,
):
four_bytes_utf8_char = "𐍈"
Copy link
Member

Choose a reason for hiding this comment

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

🤣

"$..tracingConfiguration",
]
)
class TestStatesErrors:
Copy link
Member

Choose a reason for hiding this comment

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

Thorough coverage of error scenarios 👏

💡 A short high-level overview of the key test cases (e.g., as class docstring) could improve clarity. That would clarify the two cases service_task_lambda and task_lambda.

Copy link
Member

Choose a reason for hiding this comment

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

More of a thought input, rather than actionable:
🧠 Given the inherent complexity of StepFunctions, it's impossible to test all possible scenarios. I wonder whether you have some intuition for a testing strategy to provide good enough coverage while keeping an eye on the test execution time?

def exec_lambda_function(env: Environment, parameters: dict, region: str, account: str) -> None:
lambda_client = boto_client_for(region=region, account=account, service="lambda")

invocation_resp: InvocationResponse = lambda_client.invoke(**parameters)

func_error: Optional[str] = invocation_resp.get("FunctionError")
payload_json = json.load(invocation_resp["Payload"])
Copy link
Member

Choose a reason for hiding this comment

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

ups, did I break something with this refactoring?
That's a cumbersome decoding step, do we have a regression test to catch that?

Copy link
Member

Choose a reason for hiding this comment

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

maybe a clarifying comment on why this extra step is needed could help. Is this payload extraction handling the decoding error necessary in other places of LocalStack as well 🤔 ?

Copy link
Contributor Author

@MEPalma MEPalma Mar 25, 2024

Choose a reason for hiding this comment

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

Thank you! I have added some in-code comments to explain the goal of the _from_payload function. The lambda tests added by this pr will control the case in which the output of the lambda is a to be handled by SFN as a string and not a json string. I will also add a test for string payloads in lambda suite in the services package test_invoke_string_payload.

@joe4dev
Copy link
Member

joe4dev commented Mar 26, 2024

LS style: We usually write something like Addresses #10489 instead of Closes: #10489 such that the ticket does not get closed automatically. It is a bit nicer to ask the issue reporter for feedback on whether our PR actually fixes the issue. We also have better control over when to notify the customer to ensure the pro image is out (which is not yet the case when merging a community PR).
Once you respond to the customer, you can apply the label "response required" and our stale bot will automatically close the issue if we do not receive a timely response. See GitHub Triaging Process (internal Notion) for more details.

@MEPalma MEPalma merged commit 881321d into master Mar 26, 2024
31 checks passed
@MEPalma MEPalma deleted the MEP-sfn-extend_states_errors branch March 26, 2024 17:55
@MEPalma
Copy link
Contributor Author

MEPalma commented Mar 26, 2024

Thank you @joe4dev for these kind guidelines! I have updated the issue as you suggested: #10489

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants