@@ -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
4041type 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+
191199func 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+
369389func (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