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

Fix label values limits #2272

Merged
merged 1 commit into from
Feb 20, 2025
Merged

Conversation

lampajr
Copy link
Member

@lampajr lampajr commented Feb 19, 2025

Fixes Issue

Fixes #2266

Changes proposed

With #1977 we changed how the labelValues implementation was done, the main change was that we moved the run/datasset aggregation from db logic to Java for performance reasons.

Unfortunately this change introduced the regression described in #2266.

With this change I am proposing to move the limit logic to Java as well, given that it would be quite not possible to do that at db level given that the aggregation is not there anymore.

Check List (Check all the applicable boxes)

  • My code follows the code style of this project.
  • My change requires changes to the documentation.
  • I have updated the documentation accordingly.
  • All new and existing tests passed.

@lampajr lampajr self-assigned this Feb 19, 2025
@lampajr lampajr requested review from stalep and barreiro February 19, 2025 16:07
Copy link
Member

@stalep stalep 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 other than that one comment.

@@ -531,6 +522,13 @@ protected static List<ExportedLabelValues> parse(List<Object[]> nodes) {
return exportedLabelValue;
})));

if (limit != null && limit > 0) {
page = (page == null || page < 0) ? 0 : page;
List<List<ExportedLabelValues>> partitioned = Lists.partition(exportedLabelValues.values().stream().toList(),
Copy link
Member

Choose a reason for hiding this comment

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

Can we use Collectors.partitioning/groupingBy instead of Guava Lists?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good suggestion, let me see if that works since it will avoid to add the new guava dependency only for this

Copy link
Member Author

Choose a reason for hiding this comment

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

@stalep looks like I was able to get rid of guava as I don't actually need to partition the records.. I just need to skip the first limit * page elements and keep the other limit ones:

        if (limit != null && limit > 0) {
            long toSkip = (long) limit * ((page == null || page < 0) ? 0 : page);
            return exportedLabelValues.values().stream().skip(toSkip).limit(limit).collect(Collectors.toList());
        }

wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

Looks good, thanks!

Signed-off-by: Andrea Lamparelli <[email protected]>
@lampajr lampajr force-pushed the fix_label_values_limit branch from 89f9e6d to edf9b9c Compare February 19, 2025 18:12
@stalep stalep merged commit d208817 into Hyperfoil:master Feb 20, 2025
2 checks passed
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.

API call /api/test/372/labelValues?limit=XYZ does not limit number of returned objects
2 participants