-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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-based] Attribute workspace instances to a Team on start #10574
Conversation
c154ca0
to
c50cd4e
Compare
This comment was marked as outdated.
This comment was marked as outdated.
…ytics / billing purposes)
…efault to the workspace owner
c50cd4e
to
b1ac08a
Compare
* @param user | ||
* @param projectId | ||
*/ | ||
async getWorkspaceUsageAttributionTeamId(user: User, projectId?: string): Promise<string | undefined> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Placing this method in UserService
is debatable. For example, this logic could be in-lined in workspace-starter.ts
(which already has projectDb
injected).
My reason for placing it here was to allow an extension point where ee/UserService could detect if payment is enabled, and use a different logic (i.e. attribute all usage to a "cost center" team, instead of the project's team).
I don't have any opinion on this -- feedback most appreciated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not strongly opinionated here either but your reasoning here makes sense; the subject of cost center vs team has already come up in discussions.
started the job as gitpod-build-jx-attributed-team.3 because the annotations in the pull request description changed |
started the job as gitpod-build-jx-attributed-team.4 because the annotations in the pull request description changed |
started the job as gitpod-build-jx-attributed-team.5 because the annotations in the pull request description changed |
started the job as gitpod-build-jx-attributed-team.6 because the annotations in the pull request description changed |
started the job as gitpod-build-jx-attributed-team.7 because the annotations in the pull request description changed |
started the job as gitpod-build-jx-attributed-team.8 because the annotations in the pull request description changed |
* If unset, the usage should be attributed to the workspace's owner (ws.ownerId). | ||
*/ | ||
attributedTeamId?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than leaving this unset in this case, should we explicitly fill in the ownerId?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe leaving it unset for user attribution makes more sense:
- It can only be a
teamId
(the billing is either delegated to a specific team, or it falls back to the natural owner -- delegating to a different specific user would not make sense, right? 🤔) - Setting it to possibly a
userId
makes the design more complex (need a second columnattributedUserId
, or maybe a prefix to the ID e.g.team-1324
vsuser-1234
) - The team attribution chain goes through instance > workspace > project > team (some of the links can change over time so persisting the endpoint makes sense). User attribution is more direct (instance > workspace > owner) -- I don't think we can even get to a state where we don't know which user an instance belongs to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delegating to a different user would not make sense, right?
Yes, that's my understanding too.
Tested this myself and saw the expected teamIds 👍 |
Hmm, I just realized how similar this is to #10632 🤔 My initial reflex was to revert my PR again -- but then I realized my PR will allow to re-attribute usage to a different team (e.g. if you have a team with usage-based billing that wants to handle all your workspace usage regardless of project/team). So, maybe the two are actually complementary (and when we re-attribute, we might have to update the workspace metadata too 💡) |
Description
When a workspace instance starts, we want to determine and persist which "cost center" that instance's usage should be attributed to:
wsi.attributedTeamId
is set to a specific Team ID, then that Team "owns" the instance's usagewsi.attributedTeamId
is not set, then it's the workspace owner (User) who owns the instance's usageReminder: We need to do this on instance start, because the usual attribution links can change over time.
Related Issue(s)
Fixes #10533
How to test
d_b_workspace_instance
should have aattributedTeamId
column that defaults to empty string (''
)attributedTeamId
should be empty (i.e. usage is attributed to you)attributedTeamId
should also be empty (i.e. usage still attributed to you)attributedTeamId
should now be set to the Team's ID (i.e. usage is attributed to the team)Release Notes
Documentation