Skip to content

Commit 03677e5

Browse files
committed
Update usage.go
1 parent bde9ba8 commit 03677e5

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

premium/usage.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,10 @@ func (u *BatchUpdater) backgroundUpdater() {
489489
for {
490490
select {
491491
case <-u.triggerUpdate:
492+
// If we are using AWS Marketplace, we should only report the usage at the end of the sync
493+
if u.awsMarketplaceClient != nil {
494+
continue
495+
}
492496
if time.Since(u.lastUpdateTime) < u.minTimeBetweenFlushes {
493497
// Not enough time since last update
494498
continue
@@ -500,20 +504,19 @@ func (u *BatchUpdater) backgroundUpdater() {
500504
// Not enough rows to update
501505
continue
502506
}
503-
// If we are using AWS Marketplace, we need to round down to the nearest 1000
504-
// Only on the last update, will we round up to the nearest 1000
505-
// This will allow us to not overcharge the customer by rounding on each batch
506-
if u.awsMarketplaceClient != nil {
507-
totals = roundDown(totals, 1000)
508-
}
509507

508+
u.logger.Debug().Dur("since_last_update", time.Since(u.lastUpdateTime)).Dur("min_time_between_flushes", u.minTimeBetweenFlushes).Uint32("totals", totals).Uint32("Batch Limit", u.batchLimit).Msg("trigger update")
510509
if err := u.updateUsageWithRetryAndBackoff(ctx, totals, tables); err != nil {
511510
u.logger.Warn().Err(err).Msg("failed to update usage")
512511
continue
513512
}
514513
u.subtractTableUsage(tables, totals)
515514

516515
case <-u.flushDuration.C:
516+
// If we are using AWS Marketplace, we should only report the usage at the end of the sync
517+
if u.awsMarketplaceClient != nil {
518+
continue
519+
}
517520
if time.Since(u.lastUpdateTime) < u.minTimeBetweenFlushes {
518521
// Not enough time since last update
519522
continue
@@ -524,12 +527,8 @@ func (u *BatchUpdater) backgroundUpdater() {
524527
if totals == 0 {
525528
continue
526529
}
527-
// If we are using AWS Marketplace, we need to round down to the nearest 1000
528-
// Only on the last update, will we round up to the nearest 1000
529-
// This will allow us to not overcharge the customer by rounding on each batch
530-
if u.awsMarketplaceClient != nil {
531-
totals = roundDown(totals, 1000)
532-
}
530+
u.logger.Debug().Dur("since_last_update", time.Since(u.lastUpdateTime)).Dur("min_time_between_flushes", u.minTimeBetweenFlushes).Uint32("totals", totals).Uint32("Batch Limit", u.batchLimit).Msg("flush")
531+
533532
if err := u.updateUsageWithRetryAndBackoff(ctx, totals, tables); err != nil {
534533
u.logger.Warn().Err(err).Msg("failed to update usage")
535534
continue
@@ -601,10 +600,6 @@ func (u *BatchUpdater) reportUsageToAWSMarketplace(ctx context.Context, rows uin
601600
}
602601

603602
func (u *BatchUpdater) updateMarketplaceUsage(ctx context.Context, rows uint32) error {
604-
if u.lastUpdateTime.IsZero() {
605-
u.lastUpdateTime = u.timeFunc().UTC()
606-
}
607-
608603
var lastErr error
609604
for retry := 0; retry < u.maxRetries; retry++ {
610605
u.logger.Debug().Int("try", retry).Int("max_retries", u.maxRetries).Uint32("rows", rows).Msg("updating usage")

0 commit comments

Comments
 (0)