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 27 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
@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 78.50%. Comparing base (bf77e51) to head (f0a3940).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #32063   +/-   ##
=======================================
  Coverage   78.50%   78.50%           
=======================================
  Files         106      106           
  Lines        7201     7201           
  Branches     1321     1321           
=======================================
  Hits         5653     5653           
  Misses       1361     1361           
  Partials      187      187           
Flag Coverage Δ
suite.unit 78.50% <ø> (ø)

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

Components Coverage Δ
packages/aws-cdk 78.50% <ø> (ø)

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!

@jaw111
Copy link
Author

jaw111 commented Nov 25, 2024

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

@badmintoncryer
Copy link
Contributor

@jaw111 Could you please merge the main branch? Since this PR has passed community review, the `needs-maintainer-review' label will be attached and the maintainer would review this.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 28, 2024
Copy link
Contributor

@gracelu0 gracelu0 left a comment

Choose a reason for hiding this comment

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

A few minor comments, otherwise LGTM! Once addressed I'll approve.

@mergify mergify bot dismissed gracelu0’s stale review November 30, 2024 12:42

Pull request has been modified.

Copy link
Contributor

@gracelu0 gracelu0 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 for contributing!

Copy link
Contributor

mergify bot commented Dec 2, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

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

mergify bot commented Dec 2, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Copy link
Contributor

mergify bot commented Dec 4, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Copy link
Contributor

mergify bot commented Dec 4, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

Copy link
Contributor

mergify bot commented Dec 4, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

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
5 participants