Skip to content

Commit

Permalink
Log a maximum of once every 10 seconds for each resource type when sy…
Browse files Browse the repository at this point in the history
…ncing. Use better names for counts.
  • Loading branch information
ggreer committed Dec 19, 2024
1 parent bb0e474 commit 5ee4f43
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions pkg/sync/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,20 @@ type ProgressCounts struct {
ResourceTypes int
Resources map[string]int
EntitlementsProgress map[string]int
LastEntitlementLog time.Time
LastEntitlementLog map[string]time.Time
GrantsProgress map[string]int
LastGrantLog time.Time
LastGrantLog map[string]time.Time
}

// TODO: use a mutex or a syncmap for when this code becomes parallel
func NewProgressCounts() *ProgressCounts {
return &ProgressCounts{
Resources: make(map[string]int),
EntitlementsProgress: make(map[string]int),
LastEntitlementLog: make(map[string]time.Time),
GrantsProgress: make(map[string]int),
LastGrantLog: make(map[string]time.Time),
}
}

func (p *ProgressCounts) LogResourceTypesProgress(ctx context.Context) {
Expand All @@ -73,23 +84,24 @@ func (p *ProgressCounts) LogEntitlementsProgress(ctx context.Context, resourceTy
case entitlementsProgress > resources:
l.Error("more entitlement resources than resources",
zap.String("resource_type_id", resourceType),
zap.Int("entitlement_progress", entitlementsProgress),
zap.Int("resources", resources),
zap.Int("synced", entitlementsProgress),
zap.Int("total", resources),
)
case percentComplete == 100:
l.Info("Synced entitlements",
zap.String("resource_type_id", resourceType),
zap.Int("count", entitlementsProgress),
zap.Int("total", resources),
)
p.LastEntitlementLog = time.Time{}
case time.Since(p.LastEntitlementLog) > 10*time.Second:
p.LastEntitlementLog[resourceType] = time.Time{}
case time.Since(p.LastEntitlementLog[resourceType]) > 10*time.Second:
l.Info("Syncing entitlements",
zap.String("resource_type_id", resourceType),
zap.Int("entitlement_progress", entitlementsProgress),
zap.Int("resources", resources),
zap.Int("synced", entitlementsProgress),
zap.Int("total", resources),
zap.Int("percent_complete", percentComplete),
)
p.LastEntitlementLog = time.Now()
p.LastEntitlementLog[resourceType] = time.Now()
}
}

Expand All @@ -103,23 +115,24 @@ func (p *ProgressCounts) LogGrantsProgress(ctx context.Context, resourceType str
case grantsProgress > resources:
l.Error("more grant resources than resources",
zap.String("resource_type_id", resourceType),
zap.Int("grant_progress", grantsProgress),
zap.Int("resources", resources),
zap.Int("synced", grantsProgress),
zap.Int("total", resources),
)
case percentComplete == 100:
l.Info("Synced grants",
zap.String("resource_type_id", resourceType),
zap.Int("count", grantsProgress),
zap.Int("total", resources),
)
p.LastGrantLog = time.Time{}
case time.Since(p.LastGrantLog) > 10*time.Second:
p.LastGrantLog[resourceType] = time.Time{}
case time.Since(p.LastGrantLog[resourceType]) > 10*time.Second:
l.Info("Syncing grants",
zap.String("resource_type_id", resourceType),
zap.Int("grant_progress", grantsProgress),
zap.Int("resources", resources),
zap.Int("synced", grantsProgress),
zap.Int("total", resources),
zap.Int("percent_complete", percentComplete),
)
p.LastGrantLog = time.Now()
p.LastGrantLog[resourceType] = time.Now()
}
}

Expand All @@ -136,7 +149,7 @@ type syncer struct {
tmpDir string
skipFullSync bool
lastCheckPointTime time.Time
counts ProgressCounts
counts *ProgressCounts

skipEGForResourceType map[string]bool
}
Expand Down Expand Up @@ -1690,12 +1703,7 @@ func NewSyncer(ctx context.Context, c types.ConnectorClient, opts ...SyncOpt) (S
s := &syncer{
connector: c,
skipEGForResourceType: make(map[string]bool),
counts: ProgressCounts{
ResourceTypes: 0,
Resources: make(map[string]int),
GrantsProgress: make(map[string]int),
EntitlementsProgress: make(map[string]int),
},
counts: NewProgressCounts(),
}

for _, o := range opts {
Expand Down

0 comments on commit 5ee4f43

Please sign in to comment.