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

Implement Receiver resource filtering with CEL #948

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

Conversation

bigkevmcd
Copy link
Contributor

@bigkevmcd bigkevmcd commented Oct 10, 2024

This implementation allows filtering of wildcarded resources for receivers using CEL expressions.

Closes: #491

Spec: #491 (comment)

@bigkevmcd
Copy link
Contributor Author

bigkevmcd commented Oct 10, 2024

@stefanprodan @matheuscscp I reworked it to filter the resources using CEL.

I'm not quite sure that this is really that valuable, I suspect label filtering is also more efficient?

There's some optimisation of the CEL that could be done within requestReconciliation to reduce the creation of CEL values and I can do that but I thought I'd get this out for comment.

@bigkevmcd bigkevmcd force-pushed the cel-resource-filtering branch 2 times, most recently from 995704b to d87dbfd Compare October 10, 2024 18:41
CEL for Receiver notification filtering

This introduces CEL for filtering CEL resources in a Receiver.

Users can define a CEL expression that is applied as a filter for
resources that are identified for notification.

A CEL expression that returns false means that a resource will not be
annotated.

Signed-off-by: Kevin McDermott <[email protected]>
@stefanprodan stefanprodan changed the title CEL Resource Filtering Implement Receiver resource filtering with CEL Oct 11, 2024
@bigkevmcd bigkevmcd marked this pull request as ready for review October 13, 2024 15:18
@bigkevmcd bigkevmcd marked this pull request as draft October 16, 2024 07:30
This moves the JSON body to request.body from request to allow for
future expansion with the headers.

Add documentation for the CEL functionality to the receivers doc.

Signed-off-by: Kevin McDermott <[email protected]>
@bigkevmcd bigkevmcd marked this pull request as ready for review October 17, 2024 08:54
Copy link
Collaborator

@matheuscscp matheuscscp left a comment

Choose a reason for hiding this comment

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

Thanks again for all the work here, @bigkevmcd! I'm very excited for this feature 😄

This is just a preliminary review. I will try to review this again soon.

w.WriteHeader(http.StatusBadRequest)
return
}
if err := s.validate(ctx, receiver, r); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

As mentioned in the first PR, this line reads the request payload depending on the type of the Receiver. If that happens, newCELEvaluator() further below will not be able to read the payload again. My suggestion is that we read the payload entirely into memory at some point earlier than both function calls and pass the payload to both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhh...yes, I forgot about that, I guess I'm not triggering it because of the specific receiver type I'm using.

I will add a test and see what we can do about fixing it 😄

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also I suggest reading the payload only after the Receiver object has been successfully fetched/identified to reduce the surface for DDoSing the server.

@bigkevmcd bigkevmcd force-pushed the cel-resource-filtering branch 3 times, most recently from 39d85c0 to 5a22c4f Compare October 18, 2024 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filtering for incoming webhooks
2 participants