Skip to content

Commit 46388b1

Browse files
author
pchaand
committed
MESH-0000: Add Len() method to caches and log cache lengths in controllers
1 parent 161dfd3 commit 46388b1

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

admiral/pkg/clusters/virtualservice_routing.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,9 @@ func mergeCustomVirtualServices(
12081208
if rc.VirtualServiceController.VirtualServiceCache == nil {
12091209
return nil, fmt.Errorf("virtualServiceController.VirtualServiceCache is nil")
12101210
}
1211+
if rc.VirtualServiceController.HostToRouteDestinationCache == nil {
1212+
return nil, fmt.Errorf("virtualServiceController.HostToRouteDestinationCache is nil")
1213+
}
12111214

12121215
mergedVirtualServices := make([]*v1alpha3.VirtualService, 0)
12131216

@@ -1227,6 +1230,7 @@ func mergeCustomVirtualServices(
12271230
return nil, err
12281231
}
12291232
err = rc.VirtualServiceController.HostToRouteDestinationCache.Put(mergedVirtualService)
1233+
log.Infof("HostToRouteDestinationCache length: %d", rc.VirtualServiceController.HostToRouteDestinationCache.Len())
12301234
if err != nil {
12311235
return nil, err
12321236
}

admiral/pkg/controller/admiral/rollouts.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type IIdentityArgoVSCache interface {
5151
Get(identity string) map[string]bool
5252
Put(newRolloutObj *argo.Rollout, oldRolloutObj *argo.Rollout) error
5353
Delete(rolloutObj *argo.Rollout) error
54+
Len() int
5455
}
5556

5657
type IdentityArgoVSCache struct {
@@ -494,14 +495,18 @@ func (r *RolloutController) populateIdentityArgoVSCache(
494495
return fmt.Errorf("type assertion failed, %v is not of type *argo.Rollout", obj)
495496
}
496497
if oldObj == nil {
497-
return r.IdentityArgoVSCache.Put(rollout, nil)
498+
err := r.IdentityArgoVSCache.Put(rollout, nil)
499+
log.Infof("IdentityArgoVSCache length: %d", r.IdentityArgoVSCache.Len())
500+
return err
498501
}
499502
oldRollout, oldOk := oldObj.(*argo.Rollout)
500503
if !oldOk {
501504
return fmt.Errorf("type assertion failed, %v is not of type *argo.Rollout", oldObj)
502505
}
503506

504-
return r.IdentityArgoVSCache.Put(rollout, oldRollout)
507+
err := r.IdentityArgoVSCache.Put(rollout, oldRollout)
508+
log.Infof("IdentityArgoVSCache length: %d", r.IdentityArgoVSCache.Len())
509+
return err
505510
}
506511

507512
func getArgoVSFromRollout(rollout *argo.Rollout) string {
@@ -566,3 +571,9 @@ func (i *IdentityArgoVSCache) Delete(rolloutObj *argo.Rollout) error {
566571
}
567572
return nil
568573
}
574+
575+
func (i *IdentityArgoVSCache) Len() int {
576+
defer i.mutex.RUnlock()
577+
i.mutex.RLock()
578+
return len(i.cache)
579+
}

admiral/pkg/controller/istio/virtualservice.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type IVirtualServiceCache interface {
3535
Delete(vs *networking.VirtualService)
3636
GetVSProcessStatus(vs *networking.VirtualService) string
3737
UpdateVSProcessStatus(vs *networking.VirtualService, status string) error
38+
Len() int
3839
}
3940

4041
type VirtualServiceController struct {
@@ -81,6 +82,7 @@ type IIdentityVirtualServiceCache interface {
8182
Get(identity string) map[string]*networking.VirtualService
8283
Put(vs *networking.VirtualService) error
8384
Delete(vs *networking.VirtualService) error
85+
Len() int
8486
}
8587

8688
// IdentityVirtualServiceCache holds VS that are in identity's NS
@@ -188,6 +190,12 @@ func (i *IdentityVirtualServiceCache) Delete(vs *networking.VirtualService) erro
188190
return nil
189191
}
190192

193+
func (i *IdentityVirtualServiceCache) Len() int {
194+
defer i.mutex.RUnlock()
195+
i.mutex.RLock()
196+
return len(i.cache)
197+
}
198+
191199
func getIdentitiesFromVSHostName(hostName string) []string {
192200

193201
if hostName == "" {
@@ -299,14 +307,17 @@ func (v *VirtualServiceController) Added(ctx context.Context, obj interface{}) e
299307
return fmt.Errorf("type assertion failed, %v is not of type *v1alpha3.VirtualService", obj)
300308
}
301309
err := v.VirtualServiceCache.Put(vs)
310+
log.Infof("VirtualServiceCache length: %d", v.VirtualServiceCache.Len())
302311
if err != nil {
303312
return err
304313
}
305314
err = v.HostToRouteDestinationCache.Put(vs)
315+
log.Infof("HostToRouteDestinationCache length: %d", v.HostToRouteDestinationCache.Len())
306316
if err != nil {
307317
return err
308318
}
309319
v.IdentityVirtualServiceCache.Put(vs)
320+
log.Infof("IdentityVirtualServiceCache length: %d", v.IdentityVirtualServiceCache.Len())
310321
return v.VirtualServiceHandler.Added(ctx, vs)
311322
}
312323

@@ -316,8 +327,11 @@ func (v *VirtualServiceController) Updated(ctx context.Context, obj interface{},
316327
return fmt.Errorf("type assertion failed, %v is not of type *v1alpha3.VirtualService", obj)
317328
}
318329
v.VirtualServiceCache.Put(vs)
330+
log.Infof("VirtualServiceCache length: %d", v.VirtualServiceCache.Len())
319331
v.HostToRouteDestinationCache.Put(vs)
332+
log.Infof("HostToRouteDestinationCache length: %d", v.HostToRouteDestinationCache.Len())
320333
v.IdentityVirtualServiceCache.Put(vs)
334+
log.Infof("IdentityVirtualServiceCache length: %d", v.IdentityVirtualServiceCache.Len())
321335
return v.VirtualServiceHandler.Updated(ctx, vs)
322336
}
323337

@@ -366,6 +380,12 @@ func (sec *VirtualServiceController) Get(ctx context.Context, isRetry bool, obj
366380
return nil, fmt.Errorf("istio client is not initialized, txId=%s", ctx.Value("txId"))
367381
}
368382

383+
func (vs *VirtualServiceCache) Len() int {
384+
defer vs.mutex.RUnlock()
385+
vs.mutex.RLock()
386+
return len(vs.cache)
387+
}
388+
369389
func (v *VirtualServiceCache) GetVSProcessStatus(vs *networking.VirtualService) string {
370390
if vs == nil {
371391
return common.NotProcessed
@@ -453,3 +473,9 @@ func (h *HostToRouteDestinationCache) Delete(vs *networking.VirtualService) erro
453473
}
454474
return nil
455475
}
476+
477+
func (h *HostToRouteDestinationCache) Len() int {
478+
defer h.mutex.RUnlock()
479+
h.mutex.RLock()
480+
return len(h.cache)
481+
}

0 commit comments

Comments
 (0)