Skip to content

feat: Support AWS usage marketplace#1770

Merged
kodiakhq[bot] merged 30 commits intomainfrom
aws-usage-mktplace
Aug 2, 2024
Merged

feat: Support AWS usage marketplace#1770
kodiakhq[bot] merged 30 commits intomainfrom
aws-usage-mktplace

Conversation

@bbernays
Copy link
Copy Markdown
Contributor

@bbernays bbernays commented Jun 21, 2024

This adds support for using CloudQuery plugins as part of the AWS Marketplace by changing the metering implementation to use the Marketplace instead, if specified via environment variables.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 24, 2024

⏱️ Benchmark results

Comparing with cf5b6b7

  • Glob-8 ns/op: 91.41 ⬇️ 1.06% decrease vs. cf5b6b7

@bbernays bbernays changed the title wip: Support AWS usage marketplace feat: Support AWS usage marketplace Jul 16, 2024
@bbernays bbernays marked this pull request as ready for review July 16, 2024 03:25
@bbernays bbernays requested review from a team and erezrokah July 16, 2024 03:25
@github-actions github-actions Bot added the feat label Jul 16, 2024
Copy link
Copy Markdown
Member

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, added a questions and comments.
How can I test this?

Comment thread premium/usage.go Outdated
}
// If user wants to use the AWS Marketplace for billing, don't even try to communicate with CQ API
if isAWSMarketplace() {
cfg, err := awsConfig.LoadDefaultConfig(context.TODO())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for using context.TODO() in favor of context.Background()? Maybe we should add timeout as well for loading the config?

Also, can we put this logic in a setupAWSMarketplace function as NewUsageClient is getting quite long

Copy link
Copy Markdown
Contributor Author

@bbernays bbernays Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context.TODO() is supposed to be used when the surrounding function doesn't have a context available to use, so that is why I used it here. I am not sure the value of a timeout would add here.

I have moved the logic to setupAWSMarketplace in 566bbc0

Comment thread premium/usage.go Outdated
Comment thread premium/usage.go Outdated
Comment thread premium/usage.go Outdated
Comment thread premium/usage.go Outdated
Comment thread premium/usage.go Outdated
Comment thread premium/usage.go Outdated
Comment thread premium/usage.go
Comment thread premium/usage.go Outdated
u.awsMarketPlaceClient = marketplacemetering.NewFromConfig(cfg)
u.teamName = "AWS_MARKETPLACE"
// This needs to be larger than normal, because we can only send a single usage record per second (from each compute node)
u.batchLimit = 1000000000
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is necessary, but would need to verify. I think how it should work is that there is a minimum flush time that should come into effect (by default this is 10s)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a race condition, if a batch is flushed and within the same second the sync ends then the timestamp will have the same value as timestamps are truncated to the second

Copy link
Copy Markdown
Contributor

@hermanschaaf hermanschaaf Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good catch... ok this should work for now but we should probably try and think of a better solution in the long term, otherwise we won't count any records if the sync is abruptly stopped

Comment thread go.mod Outdated
Copy link
Copy Markdown
Member

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks great, how can I test this?

@github-actions github-actions Bot added feat and removed feat labels Jul 17, 2024
Comment thread premium/usage.go
}

func isAWSMarketplace() bool {
return os.Getenv("CQ_AWS_MARKETPLACE_CONTAINER") == "true"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where these envs are being set? If it's something user settable (and not a published image of some sort) strconv.ParseBool would've been better, but I'm guessing it's an image?

Comment thread premium/usage.go
Comment on lines +48 to +51
//go:generate mockgen -package=mocks -destination=../premium/mocks/marketplacemetering.go -source=usage.go AWSMarketplaceClientInterface
type AWSMarketplaceClientInterface interface {
MeterUsage(ctx context.Context, params *marketplacemetering.MeterUsageInput, optFns ...func(*marketplacemetering.Options)) (*marketplacemetering.MeterUsageOutput, error)
}
Copy link
Copy Markdown
Contributor Author

@bbernays bbernays Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added to ensure that we could mock the AWS API calls like we do the API Server calls

Comment thread premium/usage.go
Comment thread premium/usage.go Outdated
Comment thread premium/usage.go Outdated
Comment thread premium/usage.go
Comment thread premium/usage_test.go
Comment thread premium/usage.go
@bbernays bbernays requested a review from hermanschaaf August 2, 2024 15:11
Copy link
Copy Markdown
Contributor

@hermanschaaf hermanschaaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@kodiakhq kodiakhq Bot merged commit 1eb6d1a into main Aug 2, 2024
@kodiakhq kodiakhq Bot deleted the aws-usage-mktplace branch August 2, 2024 15:29
kodiakhq Bot pushed a commit that referenced this pull request Aug 2, 2024
🤖 I have created a release *beep* *boop*
---


## [4.58.0](v4.57.1...v4.58.0) (2024-08-02)


### Features

* Support AWS usage marketplace ([#1770](#1770)) ([1eb6d1a](1eb6d1a))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants