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

MGMT-16307: Optimize GraphQL search using filters #41

Merged
merged 1 commit into from
Dec 18, 2023

Conversation

danielerez
Copy link
Collaborator

Optimized the filtering of search results in the resource server. I.e. instead of filtering the items after fetching a response, used the filter functionality of GraphQL search query API. This change includes the required mapping from 'filter' query param (as defined in the NFV spec) into SearchFilter as used in GraphQL.
Note: for any unsupported search operator by GraphQL, we fallback to the regular selector filtering.

@openshift-ci-robot
Copy link
Collaborator

openshift-ci-robot commented Dec 13, 2023

@danielerez: This pull request references MGMT-16307 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.16.0" version, but no target version was set.

In response to this:

Optimized the filtering of search results in the resource server. I.e. instead of filtering the items after fetching a response, used the filter functionality of GraphQL search query API. This change includes the required mapping from 'filter' query param (as defined in the NFV spec) into SearchFilter as used in GraphQL.
Note: for any unsupported search operator by GraphQL, we fallback to the regular selector filtering.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

[]*model.SearchFilter{
{
Property: "cluster",
Values: []*string{swag.String("=spoke0")},
Copy link
Collaborator

Choose a reason for hiding this comment

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

In other tests we are using the k8s.io/utils/ptr. It is not very different, but has the advantage of generics, so you can use the same ptr.To function for all types:

Values: []*string{ptr.To("=spoke0")},

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh, nice:) changed.

@@ -31,6 +31,9 @@ type ListRequest struct {

// ParentID is the identifier of the parent collection.
ParentID string

// Filter is the expression for filtering the results.
Filters []string
Copy link
Collaborator

Choose a reason for hiding this comment

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

The request already contains a Selector field with the result of parsing the filters parameter. Can you use that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea, looks much cleaner.

@@ -52,6 +53,7 @@ type ResourceHandler struct {
backendClient *http.Client
jsonAPI jsoniter.API
selectorEvaluator *search.SelectorEvaluator
selectorParser *search.SelectorParser
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not completely sure, but I think that if you use the Selector field of the request you will not need this additional parser because the selector is already parser.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, removed.

License.
*/

package search
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be good to keep in the "search" package only the code related to search mechanisms defined in the specification, independent of the implementation of the backend. Can we move this code to a separate package? For example internal/graphql?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. Moved.

Optimized the filtering of search results in the resource server.
I.e. instead of filtering the items after fetching a response,
used the filter functionality of GraphQL search query API.
This change includes the required mapping from 'filter' query param
(as defined in the NFV spec) into SearchFilter as used in GraphQL.
For any unsupported search operator by GraphQL, we fallback to
the regular selector filtering.
Copy link
Collaborator

@jhernand jhernand 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, thanks @danielerez.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 18, 2023
Copy link

openshift-ci bot commented Dec 18, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jhernand

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 18, 2023
@openshift-merge-bot openshift-merge-bot bot merged commit 844b93d into openshift-kni:main Dec 18, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants