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

Add filters to the trigger CRD #7879

Open
Cali0707 opened this issue Apr 29, 2024 · 9 comments · May be fixed by #7930
Open

Add filters to the trigger CRD #7879

Cali0707 opened this issue Apr 29, 2024 · 9 comments · May be fixed by #7930
Assignees
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature-request triage/accepted Issues which should be fixed (post-triage)

Comments

@Cali0707
Copy link
Member

Problem
As trigger filters are an experimental feature, up until now they have not been included directly in the CRD as the API may have changed. However, with the feature relatively stable and in beta, we should start including the filters field in the CRD for triggers.

Persona:
Which persona is this feature for?

Exit Criteria
The trigger CRD has the filters field included by default.

Time Estimate (optional):
How many developer-days do you think this may take to resolve? 1

Additional context (optional)

  • The trigger CRD is here
  • The filters types are here
@Cali0707
Copy link
Member Author

/help
/triage accepted

Copy link

knative-prow bot commented Apr 29, 2024

@Cali0707:
This request has been marked as needing help from a contributor.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-help command.

In response to this:

/help
/triage accepted

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@knative-prow knative-prow bot added triage/accepted Issues which should be fixed (post-triage) help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Apr 29, 2024
@erharjotsingh
Copy link

/assign erharjotsingh
Hello @Cali0707
I can take this up. It will be great if you can kindly help with little more details about current and expected results example

@Cali0707
Copy link
Member Author

Hi @erharjotsingh what we are looking to do is map the golang types that I linked above for the SubscriptionsApi Filters into a filters field in the trigger CRD (also linked above). This would look similar to how the attribute filter maps into the filter field in the trigger CRD. Let me know if you have any other questions!

@erharjotsingh
Copy link

Thanks @Cali0707 for clarifying. I am trying to look into it further. I will get back on this. Thanks!

@erharjotsingh
Copy link

erharjotsingh commented May 14, 2024

hello @Cali0707
As per my understanding, we need to update file trigger.yaml like below:
filter:
type: object
properties:
attributes:
type: object
x-kubernetes-preserve-unknown-fields: true
new filter:
type: object
x-kubernetes-preserve-unknown-fields: true

Please help me understand if this understanding is correct and kindly help to identify what all new fields new to be mapped. Thanks!

@pierDipi
Copy link
Member

pierDipi commented May 15, 2024

@erharjotsingh we need to add another filters field alongside the filter

filter:
description: 'Filter is the filter to apply against all events from the Broker. Only events that pass this filter will be sent to the Subscriber. If not specified, will default to allowing all events. '
type: object
properties:
attributes:
description: 'Attributes filters events by exact match on event context attributes. Each key in the map is compared with the equivalent key in the event context. An event passes the filter if all values are equal to the specified values. Nested context attributes are not supported as keys. Only string values are supported. '
type: object
x-kubernetes-preserve-unknown-fields: true

the filters field is a JSON object with these fields

// SubscriptionsAPIFilter allows defining a filter expression using CloudEvents
// Subscriptions API. If multiple filters are specified, then the same semantics
// of SubscriptionsAPIFilter.All is applied. If no filter dialect or empty
// object is specified, then the filter always accept the events.
type SubscriptionsAPIFilter struct {
// All evaluates to true if all the nested expressions evaluate to true.
// It must contain at least one filter expression.
//
// +optional
All []SubscriptionsAPIFilter `json:"all,omitempty"`
// Any evaluates to true if at least one of the nested expressions evaluates
// to true. It must contain at least one filter expression.
//
// +optional
Any []SubscriptionsAPIFilter `json:"any,omitempty"`
// Not evaluates to true if the nested expression evaluates to false.
//
// +optional
Not *SubscriptionsAPIFilter `json:"not,omitempty"`
// Exact evaluates to true if the values of the matching CloudEvents attributes MUST
// all exactly match with the associated value String specified (case-sensitive).
// The keys are the names of the CloudEvents attributes to be matched,
// and their values are the String values to use in the comparison.
// The attribute name and value specified in the filter express MUST NOT be
// empty strings.
//
// +optional
Exact map[string]string `json:"exact,omitempty"`
// Prefix evaluates to true if the values of the matching CloudEvents attributes MUST
// all start with the associated value String specified (case sensitive).
// The keys are the names of the CloudEvents attributes to be matched,
// and their values are the String values to use in the comparison.
// The attribute name and value specified in the filter express MUST NOT be
// empty strings.
//
// +optional
Prefix map[string]string `json:"prefix,omitempty"`
// Suffix evaluates to true if the values of the matching CloudEvents attributes MUST
// all end with the associated value String specified (case sensitive).
// The keys are the names of the CloudEvents attributes to be matched,
// and their values are the String values to use in the comparison.
// The attribute name and value specified in the filter express MUST NOT be
// empty strings.
//
// +optional
Suffix map[string]string `json:"suffix,omitempty"`
// CESQL is a CloudEvents SQL expression that will be evaluated to true or false against each CloudEvent.
//
// +optional
CESQL string `json:"cesql,omitempty"`
}

For example (more details needs to be added for objects types):

      filters:
        description: 'Filters is an experimental field that conforms to the CNCF CloudEvents Subscriptions API. It''s an array of filter expressions that evaluate to true or false. If any filter expression in the array evaluates to false, the event MUST NOT be sent to the Subscriber. If all the filter expressions in the array evaluate to true, the event MUST be attempted to be delivered. Absence of a filter or empty array implies a value of true. In the event of users specifying both Filter and Filters, then the latter will override the former. This will allow users to try out the effect of the new Filters field without compromising the existing attribute-based Filter and try it out on existing Trigger objects. '
        type: array
        items:
          type: object
          properties:
            all:
              description: 'All evaluates to true if all the nested expressions evaluate to true. It must contain at least one filter expression. '
              type: array
              items:
                type: object
            any:
              description: 'Any evaluates to true if at least one of the nested expressions evaluates to true. It must contain at least one filter expression. '
              type: array
              items:
                type: object
            cesql:
              description: 'CESQL is a CloudEvents SQL expression that will be evaluated to true or false against each CloudEvent. '
              type: string
            exact:
              description: 'Exact evaluates to true if the values of the matching CloudEvents attributes MUST all exactly match with the associated value String specified (case-sensitive). The keys are the names of the CloudEvents attributes to be matched, and their values are the String values to use in the comparison. The attribute name and value specified in the filter express MUST NOT be empty strings. '
              type: object
              x-kubernetes-preserve-unknown-fields: true
            not:
              description: 'Not evaluates to true if the nested expression evaluates to false. '
              type: object
            prefix:
              description: 'Prefix evaluates to true if the values of the matching CloudEvents attributes MUST all start with the associated value String specified (case sensitive). The keys are the names of the CloudEvents attributes to be matched, and their values are the String values to use in the comparison. The attribute name and value specified in the filter express MUST NOT be empty strings. '
              type: object
              x-kubernetes-preserve-unknown-fields: true
            suffix:
              description: 'Suffix evaluates to true if the values of the matching CloudEvents attributes MUST all end with the associated value String specified (case sensitive). The keys are the names of the CloudEvents attributes to be matched, and their values are the String values to use in the comparison. The attribute name and value specified in the filter express MUST NOT be empty strings. '
              type: object
              x-kubernetes-preserve-unknown-fields: true

erharjotsingh added a commit to erharjotsingh/eventing that referenced this issue May 20, 2024
erharjotsingh added a commit to erharjotsingh/eventing that referenced this issue May 20, 2024
erharjotsingh added a commit to erharjotsingh/eventing that referenced this issue May 20, 2024
@erharjotsingh erharjotsingh linked a pull request May 20, 2024 that will close this issue
5 tasks
@erharjotsingh
Copy link

hello @Cali0707
I have submitted a PR for this. Kindly let me know if we need to also update some docs. I can do that. Thanks!
#7930

@erharjotsingh
Copy link

hello @pierDipi
There seem to be some missing labels, due to which a few tests failed. Could you please guide me: https://prow.knative.dev/pr?query=is%3Apr%20state%3Aopen%20author%3Aerharjotsingh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature-request triage/accepted Issues which should be fixed (post-triage)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants