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

Optimize GlobalTrafficPolicy fetching and endpoint generation time #206

Conversation

aattuluri
Copy link
Contributor

@aattuluri aattuluri commented Apr 19, 2022

Current approach
Deployment/Rollout event
Step 1: Collect all GTPs from all clusters matching this deployment and save them to cache
Step 2: Iterate over all cluster caches to group deployments and generate endpoints with matching GTPs
Step 3: Write to local clusters
Step 4: Write to remote clusters

New approach (in this PR)
GTP cache is managed in the controller itself by identity+env cache key

Deployment/Rollout event
Step 1: Collect GTPs (write matched GTP to global cache for APIs etc.) from only clusters where Deployment/Rollout instances are running
Step 2: Generate mesh endpoints from what is collected in Step 1
Step 3: Write to local clusters
Step 4: Write to remote clusters

Signed-off-by: aattuluri <anil_attuluri@intuit.com>
Signed-off-by: aattuluri <anil_attuluri@intuit.com>
Signed-off-by: aattuluri <anil_attuluri@intuit.com>
Signed-off-by: aattuluri <anil_attuluri@intuit.com>
@aattuluri aattuluri added the WIP Work In Progress label Apr 19, 2022
@aattuluri aattuluri removed the WIP Work In Progress label Apr 19, 2022
@@ -219,6 +233,35 @@ func modifyServiceEntryForNewServiceOrPod(event admiral.EventType, env string, s
return serviceEntries
}

func updateGlobalGtpCache(cache *AdmiralCache, identity, env string, gtps map[string][]*v1.GlobalTrafficPolicy) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add comments for this method

Copy link
Collaborator

@asushanthk asushanthk left a comment

Choose a reason for hiding this comment

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

Approved. Please add more comments

@@ -1331,6 +1335,82 @@ func TestUpdateEndpointsForWeightedServices(t *testing.T) {

}

func TestUpdateGlobalGtpCache(t *testing.T) {

admiralCache := &AdmiralCache{GlobalTrafficCache: &globalTrafficCache{identityCache: make(map[string]*v13.GlobalTrafficPolicy), mutex: &sync.Mutex{}}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can all the variable declaration and definition be added under a

var (
)

block.

t.Run(c.name, func(t *testing.T) {
updateGlobalGtpCache(admiralCache, c.identity, c.env, c.gtps)
gtp := admiralCache.GlobalTrafficCache.GetFromIdentity(c.identity, c.env)
if c.expectedGtp == nil && gtp == nil {
Copy link
Collaborator

@nirvanagit nirvanagit May 2, 2022

Choose a reason for hiding this comment

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

May be use a single condition to condense all conditions.

if !reflect.DeepEqual(c.expectedGtp, gtp) {
  t.Errorf("want: %v, got: %v")
}

t.Errorf("%v", err)
func TestGlobalTrafficController_Updated(t *testing.T) {

gth := test.MockGlobalTrafficHandler{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: Can all the variable definition/declaration be added inside

var (
)

block.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar comment for TestGlobalTrafficController_Added and TestGlobalTrafficController_Deleted

gtpController.Updated(c.gtp, gtp)
gtpKey := common.GetGtpKey(c.gtp)
matchedGtps := gtpController.Cache.Get(gtpKey, c.gtp.Namespace)
if len(matchedGtps) != len(c.expectedGtps) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use !reflect.DeepEqual here ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar comment for TestGlobalTrafficController_Added and TestGlobalTrafficController_Deleted

@aattuluri aattuluri merged commit 573d522 into istio-ecosystem:master May 2, 2022
psikka1 pushed a commit to psikka1/admiral that referenced this pull request Jun 15, 2022
asushanthk pushed a commit that referenced this pull request Jul 21, 2022
itsLucario pushed a commit to itsLucario/admiral that referenced this pull request Aug 9, 2022
* Tune default outlier detection parameters for remote endpoints (istio-ecosystem#207)

* [bug] prevent panic when finding out rollout strategy (istio-ecosystem#210)

* prevent panic when finding out rollout strategy
Co-authored-by: Anubhav Aeron <anubhav_aeron@intuit.com>

* Optimize GlobalTrafficPolicy fetching and endpoint generation time (istio-ecosystem#206)

Co-authored-by: aattuluri <44482891+aattuluri@users.noreply.github.com>
Co-authored-by: Anubhav <anubhavaeron@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants