-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Folders: Migrate getFolder API to app platform #107617
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
base: main
Are you sure you want to change the base?
Conversation
# Conflicts: # packages/grafana-data/src/types/featureToggles.gen.ts # pkg/services/featuremgmt/registry.go # pkg/services/featuremgmt/toggles_gen.csv # pkg/services/featuremgmt/toggles_gen.go
…o aocenas/folders/migrate-api # Conflicts: # packages/grafana-data/src/types/featureToggles.gen.ts # pkg/services/featuremgmt/registry.go # pkg/services/featuremgmt/toggles_gen.csv # pkg/services/featuremgmt/toggles_gen.go
# Conflicts: # packages/grafana-data/src/types/featureToggles.gen.ts # pkg/services/featuremgmt/registry.go # pkg/services/featuremgmt/toggles_gen.csv # pkg/services/featuremgmt/toggles_gen.go # pkg/services/featuremgmt/toggles_gen.json
# Conflicts: # public/app/api/clients/folder/v1beta1/index.ts # public/app/core/components/NestedFolderPicker/useFoldersQueryAppPlatform.ts
# Conflicts: # public/app/features/alerting/unified/hooks/useFolder.ts
const results = needsUserData | ||
? [result, resultParents, resultAccess] | ||
: [result, resultParents, resultAccess, resultUserDisplay]; |
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.
Is this the wrong way round? 🤔
It's reading as "if needs user data, don't check the resultUserDisplay
query". I would have expected it to be the other way round here
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.
Good catch, need to add some tests for this hook to at least check the merging behavior
Not sure if this one is out of scope for the current implementation, but I think its a bug in the new hook? Or an issue with permissions on the new API. Minimal reproduction, using enterprise...:
|
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 access control wise. I feel like we could eventually simplify the returned info a bit (eg, we don't really need both CanEdit
, CanSave
etc and the access control metadata). But this should work for now 🤞
metadata: { | ||
name: 'general', | ||
namespace: 'org-0', | ||
uid: 'DvhY6m059FraHn96xsOKsb8GRtHy2ftVDUPkqZTzP4kX', |
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.
question: where is this UID coming from? On the backend, we use general
for general folder UID.
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 copied what I get if the dualWriterMode == 1
so the backend uses the legacy path. As far as I know this uid
is not grafana uid
but k8s uid
and so will be different from general
.
This one though is generated here
f.UID = gapiutil.CalculateClusterWideUID(f) |
At the same time it's not actually used right now anyway and does not get into the final FolderDTO right now the exact value does not matter.
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.
Gotcha, thanks for the explanation. I still find it hard to tell where the old Grafana style UIDs should be used, and where it's the new k8s UIDs. I agree that it sounds like it'd be a fixed value. And that it's fine to keep it as it is if it's currently not used.
import { | ||
AnnoKeyCreatedBy, | ||
AnnoKeyFolder, | ||
// AnnoKeyFolderUrl, |
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.
(nit: commented code)
const resultAccess = useGetFolderAccessQuery(params); | ||
|
||
// Load users info if needed. | ||
const userKeys = getUserKeys(resultFolder); |
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.
Overall, might it be better to make the user information dependent on a parameter passed to the hook? Then the consumer can decide whether its needed to be fetched, rather than always doing it.
I would imagine that not every consumer of the hook requires the user information for its display, perhaps?
Something for the future, as I get that here we're just trying to move over to the new API
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 reason this is done is that the k8s object has user references (like created by) in different format, like user:1
while in the old folderDTO the references are actual logins of the users so user:1
=> admin
. To resolve that here we need to use the userDisplay API call, but in case the references in the k8s object is empty we don't need to do that. So it's not really something user would decide.
In the future we will just have to change the front end to understand the new data types and deal with it case by case because yeah most time it probably isn't needed.
metadata: { | ||
name: 'sharedwithme', | ||
namespace: 'org-0', | ||
uid: 'DlDSzXw31VwXu6LHMw0JMoFvfVtYzyf3NEPzsOXHtxQX', |
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.
Should this be config.sharedWithMeFolderUID
? Not sure how its best to handle all of these virtual folders 🤔
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.
No, see #107617 (comment) this UID is totally separate thing from the UID we have in grafana. UID we use in grafana == metadata.name
in the k8s objects.
title: 'Shared with me', | ||
description: 'Dashboards and folders shared with me', |
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.
nit: If these are actually being displayed, then we'll need to turn these into get methods (getSharedWithMeFolder
) and add translations
const result = await (config.featureToggles.foldersAppPlatformAPI | ||
? deleteFolderAppPlatform({ name: folder.uid }) | ||
: deleteFolderLegacy(folder)); |
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.
Might be worth moving the feature toggle check/logic into the hook as we've done for the get
case
Changes the getFolder and it's
useGetFolderQueryHook
to use APP latform APIs.This is done by creating a
useGetFolderQueryFacade
that based on thefoldersAppPlatformAPI
either uses the legacy client or the recreates the same FolderDTO from multiple app platform API calls.This should make this change mostly transparent to the front end so no changes to the rendering is needed.