-
Notifications
You must be signed in to change notification settings - Fork 575
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
Add attribute filter transform function #7909
Conversation
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
[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 |
Codecov ReportAttention: Patch coverage is
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. |
Signed-off-by: Calum Murray <cmurray@redhat.com>
Looks like GKE issues /retest-required |
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
There was a problem hiding this 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
Signed-off-by: Calum Murray <cmurray@redhat.com>
/cc @Leo6Leo |
/test upgrade-tests |
/lgtm |
return "attributes-filter" | ||
} | ||
|
||
func buildRegexForAttribute(attribute string) (*regexp.Regexp, error) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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]+") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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(), "$") |
There was a problem hiding this comment.
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}}
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 |
Fixes #7685
Proposed Changes