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

feat(events): add filter rules for prefixEqualsIgnoreCase, suffixEqualsIgnoreCase, wildcard, and anythingBut* matches #32063

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

jaw111
Copy link

@jaw111 jaw111 commented Nov 8, 2024

Issue # (if applicable)

Closes #28462.

Reason for this change

Add support for:

  • Prefix matching while ignoring case
  • Suffix matching while ignoring case
  • Wildcard matching
  • Anything-but matching on suffixes
  • Anything-but matching using wildcards
  • Anything-but matching while ignoring case

Extend anything-but matching on prefixes to support a list of prefix values.

Description of changes

Added functions on Match class:

  • prefixEqualsIgnoreCase()
  • suffixEqualsIgnoreCase()
  • wildcard()
  • anythingButSuffix()
  • anythingButWildcard()
  • anythingButEqualsIgnoreCase()

Modified anythingButPrefix() to support rest parameters.

Description of how you validated changes

Added unit and integration tests for new and changed functions.

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 November 8, 2024 08:35
@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Nov 8, 2024
@jaw111
Copy link
Author

jaw111 commented Nov 8, 2024

The build fails, which seems to be due to failing tests for @aws-cdk/aws-scheduler-targets-alpha:test.

It's not clear from the contributing guidelines what/how to fix.

@badmintoncryer
Copy link
Contributor

@jaw111 Thank you for your contribution!

It appears that aws-events integ test has failed, which may indicate that this modification introduces a breaking change.

@aws-cdk-testing/framework-integ: Failed: /codebuild/output/src3594926594/src/github.com/aws/aws-cdk/packages/@aws-cdk-testing/framework-integ/test/aws-events/test/integ.rule.js
@aws-cdk-testing/framework-integ: Error: Some tests failed!

Could you please clarify the reason for failure?

@badmintoncryer
Copy link
Contributor

Oh, it seems the integration test you updated this time has failed. Could you please update the snapshot for integ.rule.ts?

@jaw111
Copy link
Author

jaw111 commented Nov 9, 2024

I think I am missing something, the contributing guide says to run integration tests on the .js file, whilst I modified the .ts file.

The changes I made to the .ts file are not reflected into the .js file, and the .js files appear to be ignored by Git.

How are those created/updated?

* add functions anythingButSuffix, anythingButWildcard, and anythingButEqualsIgnoreCase
* change anythingButPrefix to support multiple values
* implement unit tests
* implement integration tests
* update snapshots
throw new Error('anythingBut matchers must be non-empty lists');
}

return this.fromObjects([{ 'anything-but': { prefix: values } }]);
Copy link
Author

Choose a reason for hiding this comment

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

This will always output an array also when only a single value is supplied.

To avoid changes to existing rules created with this pattern, I can add an exception to handle such cases.

@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 Nov 9, 2024
@@ -41,6 +41,36 @@ new Rule(stack, 'MyRule', {
},
});

new Rule(stack, 'MyWildcardRule', {
Copy link
Author

Choose a reason for hiding this comment

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

I split this out to a separate rule, otherwise MyRule gets too complex and updating the resource fails.

@badmintoncryer
Copy link
Contributor

It seems to be working well, but let me share the procedure just in case.

  1. modify integ.rule.ts
  2. execute yarn tsc at aws-cdk/packages/@aws-cdk-testing/framework-integ
  3. execute yarn integ path/to/integ.rule.js --update-on-failed

@@ -109,8 +116,45 @@ export class Match implements IResolvable {
/**
* Matches any string that doesn't start with the given prefix.
*/
public static anythingButPrefix(prefix: string): string[] {
return this.fromObjects([{ 'anything-but': { prefix: prefix } }]);
public static anythingButPrefix(...values: string[]): string[] {
Copy link
Contributor

@badmintoncryer badmintoncryer Nov 9, 2024

Choose a reason for hiding this comment

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

Changing an existing argument from a single string to string[] is a breaking change.
If you implement this, you would need to use feature flags, which would increase the complexity of the PR.
Please either avoid breaking changes as much as possible or modify the PR to use feature flags.

Example PRs:

Copy link
Author

Choose a reason for hiding this comment

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

Is it a breaking change? If the function is called with a single value like anythingButPrefix('foo') then it still works as before, so it is backwards compatible.

Otherwise I can make it something like this:

public static anythingButPrefix(prefix: string, ...values: string[]): string[] {
  values.unshift(prefix);

  // rest of code
}

Copy link
Author

Choose a reason for hiding this comment

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

Another option would be to use function overloading:

public static anythingButPrefix(prefix: string): string[];
public static anythingButPrefix(...values: string[]): string[] {
  return this.anythingButConjunction('prefix', values);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm really sorry for my misunderstandings.. This is not a breaking change and you don't need to update any more.

Copy link
Author

Choose a reason for hiding this comment

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

No problem, thanks for taking the time to review.

What are the next step? Should I merge/rebase the latest changes from the main branch?

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.19%. Comparing base (740db43) to head (da62a0e).
Report is 54 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #32063   +/-   ##
=======================================
  Coverage   77.19%   77.19%           
=======================================
  Files         105      105           
  Lines        7164     7164           
  Branches     1311     1311           
=======================================
  Hits         5530     5530           
  Misses       1454     1454           
  Partials      180      180           
Flag Coverage Δ
suite.unit 77.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 77.19% <ø> (ø)
---- 🚨 Try these New Features:

Copy link
Contributor

@badmintoncryer badmintoncryer left a comment

Choose a reason for hiding this comment

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

Thank you very much for your assistance!

In this PR, I believe not only the wildcard but also matches like equals-ignore-case have been newly added. Could you please make the following adjustments accordingly?

  • Modify the PR title and description
  • Add usage examples for all newly added public static methods in the README

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Nov 13, 2024
@jaw111 jaw111 changed the title feat(events): add filter rule for wildcard match feat(events): add filter rules for prefixEqualsIgnoreCase, suffixEqualsIgnoreCase, wildcard, and anythingBut* matches Nov 13, 2024
Copy link
Contributor

@badmintoncryer badmintoncryer left a comment

Choose a reason for hiding this comment

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

Thanks!

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@jaw111
Copy link
Author

jaw111 commented Nov 25, 2024

@badmintoncryer @mrgrain what are the next steps, is anything still needed from me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-events): EventPattern support for wildcard filters
4 participants