From c29b1310470aa97838e02dba7a09b879e32f625c Mon Sep 17 00:00:00 2001 From: Kiloson <4closetool3@gmail.com> Date: Wed, 22 Nov 2023 14:02:50 +0800 Subject: [PATCH] fix: add log for get resource tree Signed-off-by: Kiloson <4closetool3@gmail.com> --- pkg/cd/cd.go | 3 +++ pkg/regioninformers/regioninformers.go | 32 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/pkg/cd/cd.go b/pkg/cd/cd.go index 45cfc8c5f..b47f4d45a 100644 --- a/pkg/cd/cd.go +++ b/pkg/cd/cd.go @@ -214,10 +214,13 @@ func (c *cd) GetResourceTree(ctx context.Context, var podDetail corev1.Pod err = c.informerFactories.GetDynamicFactory(params.RegionEntity.ID, func(factory dynamicinformer.DynamicSharedInformerFactory) error { + log.Debugf(ctx, "get pod detail: %v", node.Name) pods, err := gt.ListPods(&node, factory) if err != nil { + log.Debugf(ctx, "failed to get pod detail: %v", err) return err } + log.Debugf(ctx, "get pod detail success: %v", node.Name) podDetail = pods[0] return nil }) diff --git a/pkg/regioninformers/regioninformers.go b/pkg/regioninformers/regioninformers.go index 5a291c1d3..c05dc1da0 100644 --- a/pkg/regioninformers/regioninformers.go +++ b/pkg/regioninformers/regioninformers.go @@ -67,6 +67,34 @@ type Target struct { Regions map[uint]struct{} } +type LoggingMutext struct { + sync.RWMutex +} + +func (m *LoggingMutext) Lock() { + log.Debugf(context.Background(), "Lock") + m.RWMutex.Lock() + log.Debugf(context.Background(), "Locked") +} + +func (m *LoggingMutext) Unlock() { + log.Debugf(context.Background(), "Unlock") + m.RWMutex.Unlock() + log.Debugf(context.Background(), "Unlocked") +} + +func (m *LoggingMutext) RLock() { + log.Debugf(context.Background(), "RLock") + m.RWMutex.RLock() + log.Debugf(context.Background(), "RLocked") +} + +func (m *LoggingMutext) RUnlock() { + log.Debugf(context.Background(), "RUnlock") + m.RWMutex.RUnlock() + log.Debugf(context.Background(), "RUnlocked") +} + // RegionInformers is a collection of informer factories for each region type RegionInformers struct { regionMgr manager.Manager @@ -76,7 +104,7 @@ type RegionInformers struct { handlers []Resource // mu protects factories, lastUpdated and stopChanMap - mu sync.RWMutex + mu LoggingMutext clients map[uint]*RegionClient } @@ -414,8 +442,10 @@ func (f *RegionInformers) GetDynamicFactory(regionID uint, operation DynamicFact return err } + log.Debugf(context.Background(), "get dynamic factory: %d", regionID) f.mu.RLock() defer f.mu.RUnlock() + log.Debugf(context.Background(), "got dynamic factory: %d", regionID) return operation(f.clients[regionID].dynamicFactory) }