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 attribute filter transform function #7909

Merged

Conversation

Cali0707
Copy link
Member

@Cali0707 Cali0707 commented May 8, 2024

Fixes #7685

Proposed Changes

  • Add a transform function for an attributes filter
  • Use the transform function depending on the filter on the trigger in the constructor

Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
@knative-prow knative-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 8, 2024
Copy link

knative-prow bot commented May 8, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Cali0707

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 8, 2024
@Cali0707
Copy link
Member Author

Cali0707 commented May 8, 2024

/cc @Leo6Leo @pierDipi @creydr

This is just WIP until I add unit tests (probably tomorrow), so the actual changes are ready for a review!

@knative-prow knative-prow bot requested review from creydr and pierDipi May 8, 2024 19:24
Copy link

codecov bot commented May 8, 2024

Codecov Report

Attention: Patch coverage is 92.72727% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 69.49%. Comparing base (7e1c082) to head (c0a7e97).
Report is 46 commits behind head on main.

Files Patch % Lines
pkg/graph/constructor.go 84.61% 1 Missing and 1 partial ⚠️
pkg/graph/transforms.go 95.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7909      +/-   ##
==========================================
+ Coverage   69.22%   69.49%   +0.27%     
==========================================
  Files         339      344       +5     
  Lines       19494    15943    -3551     
==========================================
- Hits        13494    11079    -2415     
+ Misses       5337     4187    -1150     
- Partials      663      677      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Calum Murray <cmurray@redhat.com>
@Cali0707
Copy link
Member Author

Cali0707 commented May 8, 2024

rbac.go:40: an error on the server ("Internal Server Error: \"/apis/rbac.authorization.k8s.io/v1/namespaces/test-ngogqfqt/rolebindings/subscriber-walrgdtq\": the server is currently unable to handle the request") has prevented the request from succeeding

Looks like GKE issues

/retest-required

Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
@knative-prow knative-prow bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 10, 2024
@Cali0707 Cali0707 changed the title [WIP]: Add attribute filter transform function Add attribute filter transform function May 10, 2024
@knative-prow knative-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 10, 2024
@Cali0707
Copy link
Member Author

/cc @Leo6Leo @creydr @pierDipi

This is ready for review now

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 10, 2024
Signed-off-by: Calum Murray <cmurray@redhat.com>
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 13, 2024
Copy link
Member

@Leo6Leo Leo6Leo left a comment

Choose a reason for hiding this comment

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

Left few comments, otherwise it looks good! @Cali0707

pkg/graph/constructor.go Show resolved Hide resolved
pkg/graph/transforms_test.go Show resolved Hide resolved
pkg/graph/transforms.go Outdated Show resolved Hide resolved
Signed-off-by: Calum Murray <cmurray@redhat.com>
@Cali0707
Copy link
Member Author

/cc @Leo6Leo

@knative-prow knative-prow bot requested a review from Leo6Leo May 14, 2024 18:28
@Cali0707
Copy link
Member Author

/test upgrade-tests

@Leo6Leo
Copy link
Member

Leo6Leo commented May 15, 2024

/lgtm

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label May 15, 2024
return "attributes-filter"
}

func buildRegexForAttribute(attribute string) (*regexp.Regexp, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a comment on what this is doing ?


var _ Transform = &AttributesFilterTransform{}

func (aft *AttributesFilterTransform) Apply(et *eventingv1beta3.EventType, tfc TransformFunctionContext) (*eventingv1beta3.EventType, TransformFunctionContext) {
Copy link
Member

Choose a reason for hiding this comment

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

Comments would be helpful to describe what is the function doing

var chunk strings.Builder
for i := 0; i < len(attribute); {
if attribute[i] == '{' {
chunks = append(chunks, chunk.String(), "[a-zA-Z]+")
Copy link
Member

Choose a reason for hiding this comment

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

I don't think regex [a-zA-Z]+ matches every possible CE value

https://github.com/cloudevents/spec/blob/main/cloudevents/spec.md#type-system

Copy link
Member

@pierDipi pierDipi May 15, 2024

Choose a reason for hiding this comment

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

Also is the { or } not allowed? because in that case, we're using a possible char as delimiter

Comment on lines +94 to +112
for i := 0; i < len(attribute); {
if attribute[i] == '{' {
chunks = append(chunks, chunk.String(), "[a-zA-Z]+")
chunk.Reset()

offset := strings.Index(attribute[i:], "}")
if offset == -1 {
return nil, fmt.Errorf("no closing bracket for variable")
}

i += offset + 1
continue
}

chunk.WriteByte(attribute[i])
i++
}

chunks = append(chunks, chunk.String(), "$")
Copy link
Member

Choose a reason for hiding this comment

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

are we validating that attributes with variables are well formatted?

I think this would produce wrong results when the value looks like this one {abc}}

@knative-prow knative-prow bot merged commit 3189fc2 into knative:main May 15, 2024
35 of 38 checks passed
@Cali0707
Copy link
Member Author

Whoops @pierDipi looks like this somehow got merged before I could address your feedback. I'll open a follow up PR later today to try and make the changes you asked for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Event Lineage: Create Transform Function for Attributes Filter
4 participants