-
Notifications
You must be signed in to change notification settings - Fork 170
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
frontend: Introduce react-query and v2 API #2231
Conversation
d665315
to
2f4c544
Compare
7e173d2
to
6cfd7f1
Compare
e07139c
to
d6ade16
Compare
Very nice work. I'm looking forward to these improvements. I don't have time for an in depth review right now... But my general questions of all PRs: are there docs, tests for new code, atomic commits? Can anything be broken out into separate PRs? How does it affect plugins? Adopting a new technology... were alternatives evaluated and is the decision reversable/or leaking to users? ( I guess @reduxjs/toolkit/query is the alternative here ). Is there something broken/deprecated and how is that going to be communicated? |
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.
Test coverage looks good, docs are concise and readable, and big thanks for splitting the commits across the different PRs. Monumental task, great work!
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.
🎉 thanks
(please fix those issues @skoeva mentioned, then we can merge)
I went through and checked the remaining open convos were addressed and resolved them. There's only the two notes left. |
What is the plan for deprecation and migration? How long are we keeping these around? I think users should have a " It would make sense to update the examples/ plugins in this PR so we can more easily test them. Looking at the uses of useListQuery... why does the function signature have to be different? Old use of useList: const [pods, podsFetchError] = Pod.useList({
namespace,
labelSelector: getPodsSelectorFilter(service),
}); New use of useListQuery. const { items: pods, error: podsFetchError } = Pod.useListQuery({
namespace,
queryParams: {
labelSelector: getPodsSelectorFilter(service),
},
});
|
The old functions are probably used a lot, first we can mark them deprecated in the comment, then probably console warning, then removal. But I think we'll keep them for quite a while
There are already more returned values than
I considered it, but the behavior of the functions is slightly different, |
Pushed the suggested changes (marked them as resolved as they're straightforward) and created an issue for updating the plugin examples #2322 |
At the moment I can't see any of the extra pieces of data used. The most common usage is like this: const [pods, podsFetchError] = Pod.useList({
namespace,
labelSelector: getPodsSelectorFilter(service),
}); Which is simpler to use than this: const { items: pods, error: podsFetchError } = Pod.useListQuery({
namespace,
queryParams: {
labelSelector: getPodsSelectorFilter(service),
},
});
The queryParams is redundant here, because "Selector" is already signifying that it's a selector. In the future if users of these functions do use the extra information returned... at that point a different input could allow returning that extra info in an object. Which would keep compatibility with existing call sites.
The major issue with this is that we have to keep maintaining two versions of code. For maintenance it would be better to drop that old code now. The problem with having a cached and non-cached view of the data is that it's inconsistent. This is why I think it's better to have them both use the cached version. I hope that the watches update that cached data more quickly than a new request would make (or at least just as quickly). |
What is the idea with adding /api/ inside lib/k8s?
Could you also please explain the idea and the plan with having a v1 and v2 folder? |
Yes, right now in most places we're just using result and error. For example, now that we have caching, a common feature that improves UX is some kind of loading indicator that appears when data is refetched (while cached data is displayed). There's no way to represent this with just If you look at the current type definition of useList you'll see
which is not always obvious, for example guessing from just the type what the last item does is not clear.
Query parameters is a set of properties that is separate from the other parameters. Just like it is separated in Kubernetes documentation, PodList example. People that are already familiar with Kubernetes API would probably find it easier to work with. Also current
Functions which type definition changes based on parameters passed are usually hard to work with, I'd prefer avoiding doing that.
I could replace old functions completely, preserving function definitions. That would require some additional effort |
that's where apiProxy was, then it was refactored
v1 is what we currently have, v2 is new version of doing requests to the backend and react-query stuff |
Pushed a big change, instead of adding new functions, they're now replacing old useGet and useList. But with some iterator trickery it is now possible to do both |
hi. I’ll leave this to @joaquimrocha to give his sign off and merge, because he was reviewing it before. Looks good to me. The only slight concerns I have left are about the “api” name, and introducing v1/v2, but will leave that up to you both to consider/decide. thanks!! |
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.
Left a comment. I think this PR would be easier to review if we had the move into v1 as a previous, separate commit.
About the versioned folders. I am totally in favor of having them so we can eventually move to a new version that has little to do with the previous one. And I am also happy to drop the previous version of apiProxy that was doing things like sequentially trying different k8s APIs without remembering any. However, in this case, unless I misunderstood it, it looks like we keep using most of the v1 (apply function, scale API, etc.) but we have the v2 being used for replacing the internals of the useGet/useList (and others), but it reads more like we are extending the previous API rather than deprecating it.
So I want to understand better the justification for having the 2 versions. Is v1 going to be deprecated? When do we get a replacement API for things like scale, apply, ...?
Here's the state of v1 and v2. The plan is to have everything in v2 eventually. Getting/watching list/objects is the most impactful for UX and it is now using react-query.
[0] - This is still present in the code and available via apiProxy/index.ts file for compatibility, but it's not used for requests in our codebase anymore Now those API that are not yet in v2 are quite simple and can be included in v2 with minimal changes. |
Pushed an update that moves v1 into a new commit, updates websocket logic |
Signed-off-by: Oleksandr Dubenko <[email protected]>
This commit replaces fetch calls with react-query, and introduces v2 of api client code, simplifying the way we do requests to the backend Signed-off-by: Oleksandr Dubenko <[email protected]>
Signed-off-by: Oleksandr Dubenko <[email protected]>
@sniok Okay. I still think it's a bit weird we are branching the version when we are not marking anything as deprecated and we don't have 100% coverage for what we had in v1, but I can see a way where we add those along the way, so I have merged the changes. |
fixes #1700
This PR introduces react-query as the library to perform and coordinate requests to the backend.
It brings nice quality of life improvements like caching, deduplicating requests, error handling, convenient react hooks.
For KubeObject classes, new methods were added: useQuery (alternative to useGet), useListQuery (alternative to useList). The old methods are left as-is (marked as deprecated) for compatibility with plugins.
Some requests were not converted to limit the scope of this PR. Things like health and config requests for example, where caching might introduce problems, are left to do in next PRs.
Testing done
make app-linux