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

support filter chain for filtering response data #1189

Merged
merged 2 commits into from
Feb 8, 2023

Conversation

rambohe-ch
Copy link
Member

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespace from that line:
/kind bug
/kind documentation
/kind enhancement
/kind good-first-issue
/kind feature
/kind question
/kind design
/sig ai
/sig iot
/sig network
/sig storage

/kind feature

What this PR does / why we need it:

improve filter framework in Yurthub in order to support filter chain that multiple filters can be selected for response data.

Which issue(s) this PR fixes:

Fixes #1188

Special notes for your reviewer:

Does this PR introduce a user-facing change?


other Note

@openyurt-bot
Copy link
Collaborator

@rambohe-ch: GitHub didn't allow me to assign the following users: your_reviewer.

Note that only openyurtio members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

In response to this:

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespace from that line:
/kind bug
/kind documentation
/kind enhancement
/kind good-first-issue
/kind feature
/kind question
/kind design
/sig ai
/sig iot
/sig network
/sig storage

/kind feature

What this PR does / why we need it:

improve filter framework in Yurthub in order to support filter chain that multiple filters can be selected for response data.

Which issue(s) this PR fixes:

Fixes #1188

Special notes for your reviewer:

Does this PR introduce a user-facing change?


other Note

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.

@openyurt-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rambohe-ch

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

@codecov
Copy link

codecov bot commented Feb 6, 2023

Codecov Report

Merging #1189 (315e03d) into master (5880dfb) will increase coverage by 0.12%.
The diff coverage is 71.19%.

@@            Coverage Diff             @@
##           master    #1189      +/-   ##
==========================================
+ Coverage   52.20%   52.33%   +0.12%     
==========================================
  Files         110      106       -4     
  Lines       13852    13852              
==========================================
+ Hits         7232     7250      +18     
+ Misses       5973     5953      -20     
- Partials      647      649       +2     
Flag Coverage Δ
unittests 52.33% <71.19%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/yurthub/proxy/remote/loadbalancer.go 12.54% <0.00%> (ø)
pkg/yurthub/filter/filter.go 54.54% <29.16%> (-10.43%) ⬇️
pkg/yurthub/filter/manager/manager.go 68.85% <53.84%> (-7.08%) ⬇️
pkg/yurthub/filter/servicetopology/filter.go 56.29% <70.67%> (+56.29%) ⬆️
pkg/yurthub/filter/masterservice/filter.go 67.39% <89.28%> (+67.39%) ⬆️
pkg/yurthub/filter/discardcloudservice/filter.go 89.47% <90.32%> (+89.47%) ⬆️
pkg/yurthub/filter/inclusterconfig/filter.go 90.47% <91.42%> (+90.47%) ⬆️
pkg/yurthub/filter/approver.go 85.89% <92.85%> (+0.66%) ⬆️
pkg/util/iptables/iptables.go 87.12% <0.00%> (-0.55%) ⬇️
... and 5 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@@ -229,7 +229,7 @@ func (pp *PoolCoordinatorProxy) modifyResponse(resp *http.Response) error {

// filter response data
if pp.filterMgr != nil {
if ok, runner := pp.filterMgr.FindRunner(req); ok {
if runner, ok := pp.filterMgr.FindResponseFilter(req); ok {
Copy link
Member

Choose a reason for hiding this comment

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

We may call it filter instead runner

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@@ -288,7 +288,7 @@ func (lb *loadBalancer) modifyResponse(resp *http.Response) error {

// filter response data
if lb.filterManager != nil {
if ok, runner := lb.filterManager.FindRunner(req); ok {
if runner, ok := lb.filterManager.FindResponseFilter(req); ok {
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

return obj
} else if len(chain) == 1 {
return chain[0].Filter(obj, stopCh)
}
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for such special process for case 0 and case 1?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

return 0, rc, nil
func (stf *serviceTopologyFilter) Filter(obj runtime.Object, stopCh <-chan struct{}) runtime.Object {
if ok := cache.WaitForCacheSync(stopCh, stf.nodeSynced, stf.serviceSynced, stf.nodePoolSynced); !ok {
return obj
Copy link
Member

Choose a reason for hiding this comment

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

If stopCh is closed, it seems to return the unfiltered object to the client. Is it suitable?

Copy link
Member Author

Choose a reason for hiding this comment

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

if stopCh is closed, Yurthub will be exit and restart lately. so it's no problem to return a unfiltered object.

Copy link
Member

@Congrool Congrool left a comment

Choose a reason for hiding this comment

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

/lgtm

@openyurt-bot openyurt-bot added the lgtm lgtm label Feb 8, 2023
@openyurt-bot openyurt-bot merged commit d6c01b3 into openyurtio:master Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request]support filter chain to mutate response data in YurtHub
3 participants