Skip to content

Conversation

@otaviomacedo
Copy link
Contributor

@otaviomacedo otaviomacedo commented Jul 25, 2022

The current API restricts event pattern matchers to arrays of strings, which do not cover all the functionality available for EventBridge patterns.

Add a new matcher API that gets translated to the low-level JSON pattern matchers, to be consumed by EventBridge. This high-level API also adds:

  • Better ergonomics: users don’t have to remember where to use curly or square brackets; 'OR' and 'AND' conditions (where applicable) are clearly indicated.
  • Aliases/syntax sugar: ipAddressRange(), anythingButPrefix() and interval() hide some of the lower level complexity.
  • Validation: you can’t pass an invalid IP address range, or an interval with lower and upper bounds swapped, or empty lists of conditions.

Resolves #20486, resolves #13330.


All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

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

@gitpod-io
Copy link

gitpod-io bot commented Jul 25, 2022

Image

@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p1 labels Jul 25, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team July 25, 2022 10:39
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jul 25, 2022
@otaviomacedo otaviomacedo removed the bug This issue is a bug. label Jul 26, 2022
@github-actions github-actions bot added the feature-request A feature should be added or improved. label Jul 26, 2022
Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

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

Nice! I love this! Just need to find a different way to encode the matchers... via tokens maybe?

* @default - No filtering on version
*/
readonly version?: string[];
readonly version?: string[] | IMatcher;
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using union types in L2 libraries. Even though they work fine in TypeScript, they do not behave well in many of the other languages we target (See Design Guidelines, API Design, Props, Unions).

/**
* A collection of matchers for constructing event patterns
*/
export class Matchers {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd prefer Match as a class name? It'll look nicer in code? As in, Match.anythingBut(...) ?

@mrgrain
Copy link
Contributor

mrgrain commented Jul 27, 2022

@otaviomacedo Is this missing a Matcher for an AND condition? Or is that something the service doesn't support?

@otaviomacedo
Copy link
Contributor Author

@otaviomacedo Is this missing a Matcher for an AND condition? Or is that something the service doesn't support?

There is no general way to represent and AND condition. But there are two special cases:

  1. The list of properties is interpreted as a conjunction: {"foo": ["a"], bar: ["b"]} means that you expect both fields to match.
  2. In numeric patterns, the list of conditions passed to the array is interpreted as conjunction: foo: [{"numeric": [">", 0, "<", 5]}] means that the number should be greater than 0 and less than 5. This is exposed by the Match.allOf() method.

@otaviomacedo otaviomacedo requested a review from rix0rrr August 1, 2022 14:27

public readonly creationStack: string[];

constructor(private readonly matchers: any[],
Copy link
Contributor

Choose a reason for hiding this comment

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

For current safety, can we make this a private constructor? I don't think I want people calling new Match() directly...

@rix0rrr rix0rrr changed the title feat(events): Event pattern matchers feat(events): complex event pattern matching with the Match class Aug 8, 2022
@mergify
Copy link
Contributor

mergify bot commented Aug 8, 2022

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).

1 similar comment
@mergify
Copy link
Contributor

mergify bot commented Aug 8, 2022

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).

@otaviomacedo otaviomacedo added the pr/do-not-merge This PR should not be merged at this time. label Aug 8, 2022
@otaviomacedo otaviomacedo removed the pr/do-not-merge This PR should not be merged at this time. label Aug 8, 2022
@mergify
Copy link
Contributor

mergify bot commented Aug 8, 2022

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: da8199c
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit fe7651f into main Aug 8, 2022
@mergify mergify bot deleted the otaviom/event-pattern-matchers branch August 8, 2022 15:42
@mergify
Copy link
Contributor

mergify bot commented Aug 8, 2022

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).

jmortlock pushed a commit to jmortlock/aws-cdk that referenced this pull request Aug 8, 2022
…ws#21310)

The current API restricts event pattern matchers to arrays of strings, which do not cover all the functionality available for EventBridge patterns.

Add a new matcher API that gets translated to the low-level JSON pattern matchers, to be consumed by EventBridge. This high-level API also adds:

* **Better ergonomics**: users don’t have to remember where to use curly or square brackets; 'OR' and 'AND' conditions (where applicable) are clearly indicated.
* **Aliases/syntax sugar**: `ipAddressRange()`, `anythingButPrefix()` and `interval()` hide some of the lower level complexity.
* **Validation**: you can’t pass an invalid IP address range, or an interval with lower and upper bounds swapped, or empty lists of conditions.

Resolves aws#20486, resolves aws#13330.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
josephedward pushed a commit to josephedward/aws-cdk that referenced this pull request Aug 30, 2022
…ws#21310)

The current API restricts event pattern matchers to arrays of strings, which do not cover all the functionality available for EventBridge patterns.

Add a new matcher API that gets translated to the low-level JSON pattern matchers, to be consumed by EventBridge. This high-level API also adds:

* **Better ergonomics**: users don’t have to remember where to use curly or square brackets; 'OR' and 'AND' conditions (where applicable) are clearly indicated.
* **Aliases/syntax sugar**: `ipAddressRange()`, `anythingButPrefix()` and `interval()` hide some of the lower level complexity.
* **Validation**: you can’t pass an invalid IP address range, or an interval with lower and upper bounds swapped, or empty lists of conditions.

Resolves aws#20486, resolves aws#13330.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution/core This is a PR that came from AWS. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1

Projects

None yet

4 participants