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

SWATCH-2951: Allow to filter by metrics in the Instances Table API #3834

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Sgitario
Copy link
Contributor

@Sgitario Sgitario commented Oct 8, 2024

Jira issue: SWATCH-2951

Description

The payg and non payg views are aggregating all the metrics into a single row in jsonb format. And the problem is that we can't easily filter and order using these metrics because it is in jsonb.

So, instead of dealing with the metrics jsonb column, we're now adding a left join to the measurements table (for payg is "instance_monthly_totals" and for non payg is "instance_measurements") - note about performance: that these tables are indexed.

Therefore, we're now using this relationship to filter and also to order the result set. These relationships will not be used when mapping the query result set to the DTO.

Changes

  • Removed the distinct in the query since it wasn't necessary (the distinct is done in the view).
  • Implement the order using the Hibernate Criteria API because the Spring Specification API can only order by existing fields in the entity (and we now want to also order by programmatically added columns)
  • Don't use the Spring Pageable API since the sort is not supported anylonger (if provided, then the programmatically order by is ignored)

Testing

Added a JUnit test to mimic the scenario.

@Sgitario Sgitario added QE Pull request should be approved by QE before merge Dev Pull requests that need developer review labels Oct 8, 2024
@Sgitario Sgitario requested a review from mmusil October 8, 2024 11:46
@kflahert kflahert self-requested a review October 10, 2024 18:34
@kflahert kflahert self-assigned this Oct 10, 2024
@kflahert
Copy link
Contributor

/retest

@kflahert kflahert added Dev/approved Pull requests that have been approved by all assigned developers and removed Dev Pull requests that need developer review labels Oct 11, 2024
@mmusil
Copy link

mmusil commented Oct 14, 2024

/retest

The payg and non payg views are aggregating all the metrics into a single row in jsonb format. And the problem is that we can't easily filter and order using these metrics because it is in jsonb.

So, instead of dealing with the metrics jsonb column, we're now adding a left join to the measurements table (for payg is "instance_monthly_totals" and for non payg is "instance_measurements") - note about performance: that these tables are indexed.

Therefore, we're now using this relationship to filter and also to order the result set. These relationships will not be used when mapping the query result set to the DTO.

Changes
- Removed the distinct in the query since it wasn't necessary (the distinct is done in the view).
- Implement the order using the Hibernate Criteria API because the Spring Specification API can only order by existing fields in the entity (and we now want to also order by programmatically added columns)
- Don't use the Spring Pageable API since the sort is not supported anylonger (if provided, then the programmatically order by is ignored)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dev/approved Pull requests that have been approved by all assigned developers QE Pull request should be approved by QE before merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants