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-405 Add quota units to pipeline quotas #205

Merged
merged 4 commits into from
Feb 26, 2025
Merged

Conversation

mmorgantaylor
Copy link
Collaborator

@mmorgantaylor mmorgantaylor commented Feb 25, 2025

Description

Each pipeline should have its quota unit defined. This PR adds a quota_units field to the pipeline_quotas table in the teaspoons database; the string value of QuotaUnitsEnum is meant to be the plural version of the unit, e.g. "samples" rather than "sample". We include this field in the QuotaWithDetails API response that users receive when they query their quota status for a pipeline.

Jira Ticket

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

Checklist (provide links to changes)

@@ -51,15 +51,17 @@ public ResponseEntity<ApiQuotaWithDetails> getQuotaForPipeline(String pipelineNa
UserQuota userQuota =
quotasService.getOrCreateQuotaForUserAndPipeline(
user.getSubjectId(), validatedPipelineName);
String quotaUnits = quotasService.getPipelineQuota(validatedPipelineName).getQuotaUnits();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

could alternatively make a dedicated method just to retrieve the quota units from the db

Copy link
Collaborator

Choose a reason for hiding this comment

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

yea i like the idea of having a method for that. no need to grab extra info (even if it is little)

Copy link
Collaborator

@jsotobroad jsotobroad left a comment

Choose a reason for hiding this comment

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

clean. just had one comment about possibly using an enum to keep the column values as we expect

@@ -51,15 +51,17 @@ public ResponseEntity<ApiQuotaWithDetails> getQuotaForPipeline(String pipelineNa
UserQuota userQuota =
quotasService.getOrCreateQuotaForUserAndPipeline(
user.getSubjectId(), validatedPipelineName);
String quotaUnits = quotasService.getPipelineQuota(validatedPipelineName).getQuotaUnits();
Copy link
Collaborator

Choose a reason for hiding this comment

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

yea i like the idea of having a method for that. no need to grab extra info (even if it is little)

@@ -28,9 +28,14 @@ public class PipelineQuota {
@Column(name = "min_quota_consumed")
private int minQuotaConsumed;

public PipelineQuota(PipelinesEnum pipelineName, int defaultQuota, int minQuotaConsumed) {
@Column(name = "quota_units")
private String quotaUnits;
Copy link
Collaborator

Choose a reason for hiding this comment

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

because the data from this column is gonna be added through our db migrations only, its probably worth setting this up as an enum like pipeline_name above. It just gives us the extra security (with the related unit test) that we are entering things we expect into the database.

columns:
- column:
name: quota_units
value: 'samples'
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we update the e2e to test for this too? prob not necessary

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we don't currently check all the fields returned from the quota endpoint... i could make the change to ask for all of them, but currently we only check the value of response['quotaConsumed']

@Converter(autoApply = true)
public class QuotaUnitsConverter implements AttributeConverter<QuotaUnitsEnum, String> {
@Override
public String convertToDatabaseColumn(QuotaUnitsEnum quotaUnitsEnum) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is the one place that's not being tested. since we never actually use code to set this value in the db (we use liquibase), i'm ok with that, but i can construct a test if that would be better (we don't have explicit tests of these kinds of classes currently)

Copy link
Collaborator

Choose a reason for hiding this comment

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

yea i think thats more than fine to not test this. We could prob even throw like a "not implemented error dont call me" here and it wouldnt be an issue. that could be the solution :P

@mmorgantaylor mmorgantaylor merged commit 0a482f0 into main Feb 26, 2025
15 checks passed
@mmorgantaylor mmorgantaylor deleted the TSPS-405_quota_units branch February 26, 2025 19:49
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