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

TSPS-357 Add admin endpoint to get a user's quota and update their quota #162

Merged
merged 8 commits into from
Nov 20, 2024

Conversation

jsotobroad
Copy link
Collaborator

Description

At some point we may want to increase a users quota above the default. This admin endpoint makes it possible for us to do so if we want to.

Jira Ticket

https://broadworkbench.atlassian.net/browse/TSPS-357

Copy link
Collaborator

@mmorgantaylor mmorgantaylor left a comment

Choose a reason for hiding this comment

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

looking good, some questions and suggestions

@@ -48,6 +48,51 @@ paths:
500:
$ref: '#/components/responses/ServerError'

/api/admin/v1/quota/{pipelineName}/{userId}:
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: for the user-facing endpoint we call it quotas, can we be consistent here?

Suggested change
/api/admin/v1/quota/{pipelineName}/{userId}:
/api/admin/v1/quotas/{pipelineName}/{userId}:

Copy link
Collaborator Author

@jsotobroad jsotobroad Nov 19, 2024

Choose a reason for hiding this comment

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

yea i was following the pattern we made for the admin pipeline path, should i update that to pipelines as well?

(i like the idea of it matching with our user facing apis)

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah thanks for fixing pipelines too!

@@ -859,6 +927,15 @@ components:
wdlMethodVersion:
$ref: "#/components/schemas/PipelineWdlMethodVersion"

UpdateQuotaLimitRequestBody:
description: |
json object containing the admin provided information to update a users quota limit with
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit wording

Suggested change
json object containing the admin provided information to update a users quota limit with
json object containing the admin provided information used to update a user's quota limit

UserId:
name: userId
in: path
description: A string identifier to used to identify a terra user
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
description: A string identifier to used to identify a terra user
description: A string identifier to used to identify a Terra user

500:
$ref: '#/components/responses/ServerError'
patch:
summary: Update attributes for a given pipeline.
Copy link
Collaborator

Choose a reason for hiding this comment

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

update this summary

- $ref: '#/components/parameters/PipelineName'
- $ref: '#/components/parameters/UserId'
get:
summary: Get description for a given pipeline.
Copy link
Collaborator

Choose a reason for hiding this comment

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

update this summary

Suggested change
summary: Get description for a given pipeline.
summary: Get a user's current quota limit for a given pipeline.

@@ -74,6 +91,28 @@ public ResponseEntity<ApiAdminPipeline> updatePipeline(
return new ResponseEntity<>(pipelineToApiAdminPipeline(updatedPipeline), HttpStatus.OK);
}

@Override
public ResponseEntity<ApiAdminQuota> updateQuotaLimit(
Copy link
Collaborator

Choose a reason for hiding this comment

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

similarly could this be updateQuotaLimitForUserAndPipeline or similar?

* @param newQuotaLimit - the new quota limit
* @return - the updated user quota
*/
public UserQuota updateQuotaLimit(UserQuota userQuota, int newQuotaLimit) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

for clarity could we call this adminUpdateUserQuotaLimit ? thank you for mentioning that this is meant to be called from the admin controller.

* @param pipelineName - the pipeline name
* @return - true if the user quota is present, false otherwise
*/
public boolean isUserQuotaPresent(String userId, PipelinesEnum pipelineName) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

since this doesn't do any other authz checking, can we mark this as also must be called by an admin controller? (just in documentation / function name, as above)

Copy link
Collaborator Author

@jsotobroad jsotobroad Nov 19, 2024

Choose a reason for hiding this comment

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

i would say this could be called from wherever cuz its not actually altering the database. The other function is altering the database in a way we dont expect the service to be doing

Copy link
Collaborator

Choose a reason for hiding this comment

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

that's a good point, sounds good 👍


// Check if a row exists for this user + pipeline. Throw an error if it doesn't
// A row should exist if a user has run into a quota issue before.
if (!quotasService.isUserQuotaPresent(userId, validatedPipelineName)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

curious about the thought process behind this approach, versus adding an option to getQuotaForUserAndPipeline that specifies whether to create a new row if the user isn't found and just reusing that method below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmmm well calling the other admin endpoint will actually create that row for the user cuz of how thegetQuotaForUserAndPipeline function works so this is all kind of moot. What scenario do we actually want to catch here? Is it that the user has used our service before? is it that the user_id is an actual terra user_id?

we could write a get function that errors out if the row doesnt exist instead of generating a new one for these admin calls

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah I'm saying we could add an input to getQuotaForUserAndPipeline that's like addRowIfAbsent=True and toggle that functionality so we could reuse it, if that input is False and there's no row for that user then we throw. if that feels too complicated, that's fine, just an idea that I'm not at all tied to

* @return - the updated user quota
*/
public UserQuota updateQuotaLimit(UserQuota userQuota, int newQuotaLimit) {
if (newQuotaLimit < userQuota.getQuotaConsumed()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

so we would allow setting the newQuotaLimit to be equal to the user's current QuotaConsumed, thereby preventing any further activity, is that right? (sounds good to me)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

correct

@@ -4,7 +4,7 @@ info:
version: 1.0.0
paths:
# Admin APIs
/api/admin/v1/pipeline/{pipelineName}:
/api/admin/v1/pipelines/{pipelineName}:
Copy link
Collaborator

Choose a reason for hiding this comment

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

ah nice catch, thanks!

Copy link
Collaborator

@mmorgantaylor mmorgantaylor 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 to me, if you want to refactor the quotasService.getQuotaForUserAndPipeline to add an option to error if the user doesn't exist, cool, but I'm good with what we have here.

Copy link

sonarcloud bot commented Nov 20, 2024

Copy link
Collaborator

@mmorgantaylor mmorgantaylor left a comment

Choose a reason for hiding this comment

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

love the updates!

@jsotobroad jsotobroad merged commit 04ac01d into main Nov 20, 2024
14 checks passed
@jsotobroad jsotobroad deleted the js_TSPS-357 branch November 20, 2024 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants