8000 [SFN] Add usage analytics for Variable Workflow and JSONata features by gregfurman · Pull Request #11963 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

[SFN] Add usage analytics for Variable Workflow and JSONata features #11963

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
merged 3 commits into from
Nov 29, 2024

Conversation

gregfurman
Copy link
Contributor

Motivation

This PR adds analytics the SFN provider to help ascertain usage of the new JSONata and Variable workflows.

Changes

  • Add a static analyser that will check for:
    • Any variable sampling or assigning of variables
    • The query language being used by the state machine definition
  • Metrics have been added that will record whether a sfn uses JSONata or variable workflows, respectively.

Testing

  • Added unit tests to ensure the static analysis is correct.

@gregfurman gregfurman self-assigned this Nov 29, 2024
@gregfurman gregfurman added aws:stepfunctions AWS Step Functions semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases semver: patch Non-breaking changes which can be included in patch releases and removed semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases labels Nov 29, 2024
@gregfurman gregfurman added this to the 4.0.3 milestone Nov 29, 2024
Comment on lines +16 to +20
# Successful invocations (also including expected error cases in line with AWS behaviour)
invocation_counter = UsageCounter("stepfunctions:invocation")

# Unexpected errors that we do not account for
error_counter = UsageCounter("stepfunctions:error")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently unused. Will be implemented in a follow-up

Comment on lines +52 to +56
def visitVariable_sample(self, ctx: ASLParser.Variable_sampleContext):
self.has_variable_sampling = True

def visitAssign_decl(self, ctx: ASLParser.Assign_declContext):
self.has_variable_sampling = True
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want to set this flag to true if there is an Assign or if any variable sampling has been used.

Copy link
Contributor
@MEPalma MEPalma left a comment

Choose a reason for hiding this comment

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

Looking good from a SFN standpoint!

self.has_variable_sampling = False

def visitQuery_language_decl(self, ctx: ASLParser.Query_language_declContext):
query_language_mode_int = ctx.children[-1].getSymbol().type
Copy link
Contributor

Choose a reason for hiding this comment

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

You can probably prune this logic if the flag is already set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@gregfurman gregfurman marked this pull request as ready for review November 29, 2024 13:06
Copy link
github-actions bot commented Nov 29, 2024

LocalStack Community integration with Pro

    2 files  ±    0      2 suites  ±0   34m 42s ⏱️ - 1h 15m 29s
1 267 tests  - 2 511  1 173 ✅  - 2 259  94 💤  - 252  0 ❌ ±0 
1 269 runs   - 2 511  1 173 ✅  - 2 259  96 💤  - 252  0 ❌ ±0 

Results for commit 3cf219b. ± Comparison against base commit a47e701.

This pull request removes 2511 tests.
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_lambda_dynamodb
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_opensearch_crud
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_search_books
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_setup
tests.aws.scenario.kinesis_firehose.test_kinesis_firehose.TestKinesisFirehoseScenario ‑ test_kinesis_firehose_s3
tests.aws.scenario.lambda_destination.test_lambda_destination_scenario.TestLambdaDestinationScenario ‑ test_destination_sns
tests.aws.scenario.lambda_destination.test_lambda_destination_scenario.TestLambdaDestinationScenario ‑ test_infra
tests.aws.scenario.loan_broker.test_loan_broker.TestLoanBrokerScenario ‑ test_prefill_dynamodb_table
tests.aws.scenario.loan_broker.test_loan_broker.TestLoanBrokerScenario ‑ test_stepfunctions_input_recipient_list[step_function_input0-SUCCEEDED]
tests.aws.scenario.loan_broker.test_loan_broker.TestLoanBrokerScenario ‑ test_stepfunctions_input_recipient_list[step_function_input1-SUCCEEDED]
…
This pull request skips 1 test.
tests.aws.services.stepfunctions.v2.evaluate_jsonata.test_base_evaluate_expressions.TestBaseEvaluateJsonata ‑ test_base_task[TIMEOUT_SECONDS]

♻️ This comment has been updated with latest results.

10000

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.

yeah data 👍

I would skip the try/catch on the metric counter unless we have a good reason from the SFN analyser side.

analyser = UsageMetricsStaticAnalyser()
analyser.analyse(definition=definition)

try:
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the try/catch here? has_jsonata is just a getter and we can expect the counters to work (we're not using try/catch anywhere else)
if we want to be as defensive, then we should rather cover the analyse step.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We didn't want the metrics collection to be the reason why SFN was failing. Will just surround the whole block in a try-catch rather

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK wrapped the whole process in a try-except

@gregfurman gregfurman merged commit 1bd7dca into master Nov 29, 2024
32 checks passed
@gregfurman gregfurman deleted the add/sfn/metrics branch November 29, 2024 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:stepfunctions AWS Step Functions 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.

3 participants
0