Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[usage] Add a UsageReportService to content-service API #11474

Merged
merged 7 commits into from
Jul 22, 2022

Conversation

andrew-farries
Copy link
Contributor

@andrew-farries andrew-farries commented Jul 19, 2022

Description

As part of the move towards usage based pricing (#9036), we'd like for the usage aggregator (components/usage) to be able to upload its usage reports to cloud storage. This will provide an audit trail of usage reports, allowing us to cross reference usage entries in the database with the usage reports that provided the data. In future, we may also allow access to these reports to users directly.

The usage component:

  • runs multiple times per hour.
  • produces a report (in json format) of all workspace instance credit consumption for all instances that have any runtime in the current billing period (one month).
  • produces reports ~60MB in size.

This PR creates a new UsageReportService gRPC service and registers it with content-service. I've manually tested getting a presigned S3 URL from the GetUploadUrl API and uploaded some content to minio (in a preview environment) using the URL.

Following PRs will make the usage component request this pre-signed upload URL from the content-service and upload usage reports to it.

Related Issue(s)

Part of #9036

How to test

  • Port forward to minio in the preview env:
 kubectl port-forward svc/minio 9000:9000
  • Run the content-service locally using the config.json from the content-service pod in the preview env (with minio.endpoint set to localhost:9000):
cd components/content-service
go run . run --config config.json 
  • Use evans or another gRPC client to invoke the uploadUrl RPC on the new UsageReportService:

image

  • Make an http PUT request to the URL in the response to upload some content to the bucket.

Release Notes

NONE

Werft options:

  • /werft with-preview

Andrew Farries added 3 commits July 19, 2022 10:06
Define an upload RPC to allow usage reports to be uploaded to the
content service.
Regenerate gRPC code.
Create the service and register it when the content-service starts.
@easyCZ
Copy link
Member

easyCZ commented Jul 21, 2022

For the later PRs, we should gzip the report either through upload transcoding, or in the service before we upload it. That should shrink the size to about a tenth

@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-af-store-usage-reports-with-content-service.5 because the annotations in the pull request description changed
(with .werft/ from main)

Andrew Farries added 2 commits July 21, 2022 10:47
Test that usageReportService.UploadURL interacts with PresignedAccess
correctly to produce an upload URL for the correct bucket and filename.
It doesn't make sense for a request to generate an upload URL to return
NotFound after we've already ensured the bucket exists.
@easyCZ easyCZ self-assigned this Jul 21, 2022
@roboquat roboquat merged commit 58ddbf9 into main Jul 22, 2022
@roboquat roboquat deleted the af/store-usage-reports-with-content-service branch July 22, 2022 11:16
@roboquat roboquat added the deployed: webapp Meta team change is running in production label Jul 26, 2022
@roboquat roboquat added deployed: workspace Workspace team change is running in production deployed Change is completely running in production labels Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed: workspace Workspace team change is running in production deployed Change is completely running in production release-note-none size/XXL team: webapp Issue belongs to the WebApp team team: workspace Issue belongs to the Workspace team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants