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

[enhancement]optimize approver of data filtering framework in yurthub #790

Merged
merged 1 commit into from
Apr 7, 2022

Conversation

rambohe-ch
Copy link
Member

@rambohe-ch rambohe-ch commented Apr 6, 2022

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
/sig storage

/kind enhancement

What this PR does / why we need it:

  1. response should be filtered or not is decided in approve() func by iterating nameToRequests, and the efficiency is N(the length of nameToRequests slice), in this pull request, optimize the efficiency to Log(N) by using a reqKeyToName map to decide need filter or not.
  2. end user can configure the yurt-hub-cfg configmap more freely. for example: no filter setting in yurt-hub-cfg configmap will not effect the default filter setting.

Which issue(s) this PR fixes:

Fixes #

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
/sig storage

/kind enhancement

What this PR does / why we need it:

  1. response should be filtered or not is decided in approve() func by iterating nameToRequests, and the efficiency is N(the length of nameToRequests slice), in this pull request, optimize the efficiency to Log(N) by using a reqKeyToName map to decide need filter or not.
  2. fix the use case: no filter setting in yurt-hub-cfg configmap will effect the default filter setting.

Which issue(s) this PR fixes:

Fixes #

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 openyurt-bot added the kind/enhancement kind/enhancement label Apr 6, 2022
@openyurt-bot openyurt-bot added the approved approved label Apr 6, 2022
@rambohe-ch
Copy link
Member Author

@yingjianjian PTAL

@yingjianjian
Copy link
Member

/lgtm
/approve

@openyurt-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

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

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

@zzguang
Copy link
Member

zzguang commented Apr 6, 2022

/lgtm

@@ -42,7 +42,7 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}
- name: Lint golang code
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
Copy link
Member

Choose a reason for hiding this comment

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

It seems that #792 also works on it. How about letting #792 solve it, and making this pr focus on its own work?

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, i will rebase this pull request after #792 merged.

@openyurt-bot openyurt-bot merged commit d44b6da into openyurtio:master Apr 7, 2022
defer a.Unlock()
// remove current user setting from reqKeyToName and left default setting only
for key := range a.reqKeyToName {
if _, ok := defaultReqKeyToName[key]; !ok {
Copy link
Member

Choose a reason for hiding this comment

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

This code may be som confuse. Delete not default keys mean only use default keys.

	newReqKey := map[string]string{}
	for key, name := range defaultReqKeyToName {
		newReqKey[key] = name
	}
	for key, name := range keyToNameSetting {
		// if filter setting is duplicated, only recognize the first setting.
		if currentName, ok := newReqKey[key]; !ok {
			newReqKey[key] = name
		} else {
			klog.Warningf("request %s has already used filter %s, so skip filter %s setting", key, currentName, name)
		}
	}
	a.Lock()
	defer a.Unlock()
	a.reqKeyToName = newReqKey

defer a.Unlock()
// remove current user setting from reqKeyToName and left default setting only
for key := range a.reqKeyToName {
if _, ok := defaultReqKeyToName[key]; !ok {
Copy link
Member

Choose a reason for hiding this comment

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

This code may be som confuse. Delete not default keys mean only use default keys.

	newReqKey := map[string]string{}
	for key, name := range defaultReqKeyToName {
		newReqKey[key] = name
	}
	for key, name := range keyToNameSetting {
		// if filter setting is duplicated, only recognize the first setting.
		if currentName, ok := newReqKey[key]; !ok {
			newReqKey[key] = name
		} else {
			klog.Warningf("request %s has already used filter %s, so skip filter %s setting", key, currentName, name)
		}
	}
	a.Lock()
	defer a.Unlock()
	a.reqKeyToName = newReqKey

Copy link
Member Author

Choose a reason for hiding this comment

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

@huiwq1990 In order to increase efficiency of golang runtime GC, so i don't want to create a new map every time when yurt-hub-cfg filter setting changed. and the new reqKeyToName is based defaultReqKeyToName plus current filter setting in yurt-hub-cfg configmap.

@rambohe-ch
Copy link
Member Author

Fixes #773

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]About the new field definition of configmap in the filtering framework
6 participants