-
Notifications
You must be signed in to change notification settings - Fork 80
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
Pagination fixes #127
base: master
Are you sure you want to change the base?
Pagination fixes #127
Conversation
go.mod
Outdated
@@ -6,6 +6,7 @@ replace ( | |||
github.com/crewjam/saml => github.com/rancher/saml v0.2.0 | |||
github.com/knative/pkg => github.com/rancher/pkg v0.0.0-20181214184433-b04c0947ad2f | |||
github.com/matryer/moq => github.com/rancher/moq v0.0.0-20190404221404-ee5226d43009 | |||
github.com/rancher/wrangler => github.com/cmurphy/wrangler v0.8.1-0.20230918211505-408ec3feeca5 |
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.
Fix this before merging
@@ -260,17 +260,15 @@ func getLimit(apiOp *types.APIRequest) int { | |||
|
|||
// FilterList accepts a channel of unstructured objects and a slice of filters and returns the filtered list. |
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.
This is no longer a channel
// FilterList accepts a channel of unstructured objects and a slice of filters and returns the filtered list. | |
// FilterList accepts a slice of unstructured objects and a slice of filters and returns the filtered list. |
result = append(result, item) | ||
} | ||
for _, item := range list { | ||
if len(filters) == 0 { |
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 filters never changes in size, this could be moved out of the for loop
if len(filters) == 0 {
return list
}
@@ -124,7 +124,7 @@ func (s *Store) ByID(apiOp *types.APIRequest, schema *types.APISchema, id string | |||
if err != nil { | |||
return types.APIObject{}, err | |||
} | |||
return toAPI(schema, obj, warnings), nil | |||
return toAPI(schema, moveToUnderscore(obj), warnings), nil |
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.
If this looks up a single object, do we need to do moveToUnderscore
? I noticed we don't for List
and Watch
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.
The single object could contain a reserved key, so it needs to be moved. For List, moveToUnderscore
was moved out of toAPI
and into preprocessList
. for Watch, it's under toAPIEvent
.
a915db5
to
9376bdd
Compare
9376bdd
to
0fd93e0
Compare
For an object like ``` "status": { "podIPs": [ "10.0.0.1", "10.0.0.2", "10.0.0.3", ] } ``` add the ability to filter or sort by a single element in the array list: ``` GET /pods?filter=status.podIPs.2=10.0.0.2 GET /pods?sort=status.podIPs.2 ```
Certain fields like "type" in an object are reserved by rancher/apiserver and so are transmuted to an underscore-prefixed version of the field name, e.g. "_type", which is what appears in the HTTP response output. Objects like Secrets, which have a built-in Type field, are subject to this. Without this patch, filtering and sorting are done on the object prior to the field renaming, so filtering by "_type" would result in no filtering happening even though the output returned to the user does contain "_type". This change ensures that the field name changes happen before filtering and sorting is started.
0fd93e0
to
1b0c8fa
Compare
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.
LGTM
if len(filters) == 0 { | ||
return list | ||
} |
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.
Observation: The behavior is slightly different than before because here we're returning the same list (with the same storage behind) whereas before we were returning a new list (different storage).
This doesn't seem to be an issue in this case, and we're doing the same in other places (eg: FilterByProjectsAndNamespaces)
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.
Before I think we had a difference in return vs input type, so that wasn't really possible there. Ordinarily I would fix a small inconsistency like this to avoid difficult-to-locate bugs (like someone changing the original list in a go-routine and not realizing that it affected other values down-the-line), but I think there's a performance impact here to consider - copying the items to another list would have a non-zero performance impact. I would also expect the "no filters" case to be the default for the time being, so I'd like to keep this as-is and avoid a costly copy operation.
WDYT?
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'm okay as is. I think consistency would be better from my POV. The costly copy was already there, so adding it back wouldn't make rancher perform worse than it already is. We could benchmark it and see how much optimizing this improves the performance in the grand scheme of things but I'd rather do that as a separate issue and as a need basis.
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.
Without benchmark, it's usually difficult to know if an optimization improves or not. For example, the compiler could already be optimizing this part of the code. It's hard to tell without benchmarks.
1b0c8fa
to
6ab1b12
Compare
Also adds a new test for a nested array/map filter.
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.
Refreshing my approval. Needs a rebase but otherwise LGTM
Allow for filtering/sorting by reserved fields
Certain fields like "type" in an object are reserved by
rancher/apiserver and so are transmuted to an underscore-prefixed
version of the field name, e.g. "_type", which is what appears in the
HTTP response output. Objects like Secrets, which have a built-in Type
field, are subject to this.
Without this patch, filtering and sorting are done on the object prior
to the field renaming, so filtering by "_type" would result in no
filtering happening even though the output returned to the user does
contain "_type". This change ensures that the field name changes happen
before filtering and sorting is started.
Add support for filtering/sorting by array index
For an object like
add the ability to filter or sort by a single element in the array list:
rancher/rancher#42767
Depends on rancher/wrangler#321