Skip to content

Commit

Permalink
Merge pull request #201 from kilosonc/fix/resourcetree
Browse files Browse the repository at this point in the history
fix: add logs on getResourcetree api for troubleshooting
  • Loading branch information
xuzhu-591 authored Nov 27, 2023
2 parents 30ed751 + c29b131 commit 2381d6d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/cd/cd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
32 changes: 31 additions & 1 deletion pkg/regioninformers/regioninformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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
Expand All @@ -77,7 +105,7 @@ type RegionInformers struct {
handlers []Resource

// mu protects factories, lastUpdated and stopChanMap
mu sync.RWMutex
mu LoggingMutext
clients map[uint]*RegionClient
}

Expand Down Expand Up @@ -417,8 +445,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)
}

Expand Down

0 comments on commit 2381d6d

Please sign in to comment.