-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
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.
looking good, some questions and suggestions
common/openapi.yml
Outdated
@@ -48,6 +48,51 @@ paths: | |||
500: | |||
$ref: '#/components/responses/ServerError' | |||
|
|||
/api/admin/v1/quota/{pipelineName}/{userId}: |
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.
nit: for the user-facing endpoint we call it quotas
, can we be consistent here?
/api/admin/v1/quota/{pipelineName}/{userId}: | |
/api/admin/v1/quotas/{pipelineName}/{userId}: |
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.
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)
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.
yeah thanks for fixing pipelines too!
common/openapi.yml
Outdated
@@ -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 |
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.
nit wording
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 |
common/openapi.yml
Outdated
UserId: | ||
name: userId | ||
in: path | ||
description: A string identifier to used to identify a terra user |
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.
description: A string identifier to used to identify a terra user | |
description: A string identifier to used to identify a Terra user |
common/openapi.yml
Outdated
500: | ||
$ref: '#/components/responses/ServerError' | ||
patch: | ||
summary: Update attributes for a given pipeline. |
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.
update this summary
common/openapi.yml
Outdated
- $ref: '#/components/parameters/PipelineName' | ||
- $ref: '#/components/parameters/UserId' | ||
get: | ||
summary: Get description for a given pipeline. |
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.
update this summary
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( |
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.
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) { |
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.
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) { |
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.
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)
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 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
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.
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)) { |
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.
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?
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.
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
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.
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()) { |
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.
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)
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.
correct
@@ -4,7 +4,7 @@ info: | |||
version: 1.0.0 | |||
paths: | |||
# Admin APIs | |||
/api/admin/v1/pipeline/{pipelineName}: | |||
/api/admin/v1/pipelines/{pipelineName}: |
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.
ah nice catch, thanks!
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.
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.
Quality Gate passedIssues Measures |
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.
love the updates!
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