Skip to content

Commit 97a3706

Browse files
authored
fix: AWS Marketplace Integration (#2049)
You can only report usage once per hour which is enforced by the API. As such the only way to guarantee we only send a single usage each hour is to send a report at the end of the sync. Closes: cloudquery/cloudquery-issues#2635
1 parent 0163147 commit 97a3706

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

Diff for: premium/usage.go

+9-12
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,12 +504,6 @@ 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

510508
if err := u.updateUsageWithRetryAndBackoff(ctx, totals, tables); err != nil {
511509
u.logger.Warn().Err(err).Msg("failed to update usage")
@@ -514,6 +512,10 @@ func (u *BatchUpdater) backgroundUpdater() {
514512
u.subtractTableUsage(tables, totals)
515513

516514
case <-u.flushDuration.C:
515+
// If we are using AWS Marketplace, we should only report the usage at the end of the sync
516+
if u.awsMarketplaceClient != nil {
517+
continue
518+
}
517519
if time.Since(u.lastUpdateTime) < u.minTimeBetweenFlushes {
518520
// Not enough time since last update
519521
continue
@@ -524,12 +526,7 @@ func (u *BatchUpdater) backgroundUpdater() {
524526
if totals == 0 {
525527
continue
526528
}
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-
}
529+
533530
if err := u.updateUsageWithRetryAndBackoff(ctx, totals, tables); err != nil {
534531
u.logger.Warn().Err(err).Msg("failed to update usage")
535532
continue

0 commit comments

Comments
 (0)