From 8e978cce37db8d813bcd23f0b89b4ea74b08cc4a Mon Sep 17 00:00:00 2001 From: ashmrtn <3891298+ashmrtn@users.noreply.github.com> Date: Thu, 16 Nov 2023 19:48:53 -0800 Subject: [PATCH] Improve logging/variable grouping for exchange preview backup (#4705) Just shuffling some variables and log statements around. No logic or test changes beyond that --- #### Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No #### Type of change - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [x] :robot: Supportability/Tests - [ ] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup #### Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- .../m365/collection/exchange/backup.go | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/internal/m365/collection/exchange/backup.go b/src/internal/m365/collection/exchange/backup.go index 55386bba2..248964e54 100644 --- a/src/internal/m365/collection/exchange/backup.go +++ b/src/internal/m365/collection/exchange/backup.go @@ -135,24 +135,21 @@ func populateCollections( category = qp.Category // Limits and counters below are currently only used for preview backups - // since they only act on a subset of items. - maxContainers = ctrlOpts.PreviewLimits.MaxContainers - maxItemsPerContainer = ctrlOpts.PreviewLimits.MaxItemsPerContainer - maxItems = ctrlOpts.PreviewLimits.MaxItems + // since they only act on a subset of items. Make a copy of the passed in + // limits so we can log both the passed in options and what they were set to + // if we used default values for some things. + effectiveLimits = ctrlOpts.PreviewLimits addedItems int addedContainers int ) - logger.Ctx(ctx).Infow("filling collections", "len_deltapaths", len(dps)) - counter.Add(count.PrevDeltas, int64(len(dps))) - el := errs.Local() // Preview backups select a reduced set of data. This is managed by ordering // the set of results from the container resolver and reducing the number of // items selected from each container. - if ctrlOpts.PreviewLimits.Enabled { + if effectiveLimits.Enabled { resolver, err = newRankedContainerResolver( ctx, resolver, @@ -169,25 +166,26 @@ func populateCollections( } // Configure limits with reasonable defaults if they're not set. - if maxContainers == 0 { - maxContainers = defaultPreviewContainerLimit + if effectiveLimits.MaxContainers == 0 { + effectiveLimits.MaxContainers = defaultPreviewContainerLimit } - if maxItemsPerContainer == 0 { - maxItemsPerContainer = defaultPreviewItemsPerContainerLimit + if effectiveLimits.MaxItemsPerContainer == 0 { + effectiveLimits.MaxItemsPerContainer = defaultPreviewItemsPerContainerLimit } - if maxItems == 0 { - maxItems = defaultPreviewItemLimit + if effectiveLimits.MaxItems == 0 { + effectiveLimits.MaxItems = defaultPreviewItemLimit } - - logger.Ctx(ctx).Infow( - "running preview backup", - "item_limit", maxItems, - "container_limit", maxContainers, - "items_per_container_limit", maxItemsPerContainer) } + logger.Ctx(ctx).Infow( + "filling collections", + "len_deltapaths", len(dps), + "limits", ctrlOpts.PreviewLimits, + "effective_limits", effectiveLimits) + counter.Add(count.PrevDeltas, int64(len(dps))) + for _, c := range resolver.Items() { if el.Failure() != nil { return nil, el.Failure() @@ -244,15 +242,15 @@ func populateCollections( // Since part of this is about figuring out how many items to get for this // particular container we need to reconfigure for every container we see. - if ctrlOpts.PreviewLimits.Enabled { - toAdd := maxItems - addedItems + if effectiveLimits.Enabled { + toAdd := effectiveLimits.MaxItems - addedItems - if addedContainers >= maxContainers || toAdd <= 0 { + if addedContainers >= effectiveLimits.MaxContainers || toAdd <= 0 { break } - if toAdd > maxItemsPerContainer { - toAdd = maxItemsPerContainer + if toAdd > effectiveLimits.MaxItemsPerContainer { + toAdd = effectiveLimits.MaxItemsPerContainer } // Delta tokens generated with this CallConfig shouldn't be used for