Skip to content

Include Pinned Resources in User Preferences#32009

Merged
avatus merged 2 commits intomasterfrom
avatus/pinned_user_prefs
Oct 10, 2023
Merged

Include Pinned Resources in User Preferences#32009
avatus merged 2 commits intomasterfrom
avatus/pinned_user_prefs

Conversation

@avatus
Copy link
Copy Markdown
Contributor

@avatus avatus commented Sep 16, 2023

Closes #32008
In support of #30418
This will add Pinned Resources to the user preferences object. The shape on web is:

const pinnedResources = {
    "clustername1": ["node1", "node2", "node3"],
    "clustername2": ["node4", "node5", "node6"],
}

We will use this to get a list of resource IDs to display which resources are pinned in the unified resource view.
Screenshot 2023-09-14 at 5 20 09 PM

node: two PRs will be be opened that rely on this. The fetching of the actual resource based on the users preferences, and updating which resources are saved via the Pin button. Both of those will be opened shortly after this one.

It can be tested by inspecting the user preferences local storage object after logging in (it will be empty but there!)

Comment thread lib/services/local/userpreferences_test.go Outdated
Comment thread web/packages/teleport/src/services/userPreferences/types.ts Outdated
Comment thread lib/web/userpreferences.go Outdated
Comment thread lib/web/userpreferences.go Outdated
Comment thread lib/web/userpreferences.go Outdated
Comment thread lib/services/local/userpreferences.go Outdated
// displayed in the user's pinned resources tab in the Web UI
message PinnedResourcesUserPreferences {
// pinned_resources is a map of resource IDs pinned per cluster
map<string, ClusterPinnedResources> pinned_resources = 1;
Copy link
Copy Markdown
Contributor

@rosstimothy rosstimothy Sep 20, 2023

Choose a reason for hiding this comment

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

I've got a few questions around pinned resources that I couldn't find answers to by poking around. If there is a RFD or some other documentation where these decisions have been made please point me to them.

  • Should pinned resources be stored per cluster rather than having them all in the root cluster?
  • Is there an upper bound to the number of pinned resources? Is it per cluster or total?
  • How do pinned resources get cleaned up? Is it manual? What happens if a leaf cluster is removed entirely?
  • What will be displayed to a user if a pinned resource is removed? Is the resource id enough information for a user to discern which resource they pinned?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should pinned resources be stored per cluster rather than having them all in the root cluster?

I'm not sure yet. It seems reasonable enough to allow it but I haven't done any super thinking on it yet.

Is there an upper bound to the number of pinned resources? Is it per cluster or total?

There isn't an upperbound programmed in yet, but we'd want to stay under the max size of an item, lets say in dynamodb, which is 400kb. if we have a node id like "123123-123123123-123123123/node", well over 10k could fit and still have plenty of room for more (and other user preferences).

I don't think 10k pinned resources across all clusters is a realistic outcome in terms of what people actually pin, but we should put some safeguards up regardless. and also it comes into play with my next point.

How do pinned resources get cleaned up? Is it manual? What happens if a leaf cluster is removed entirely?

This will require some extra thinking. My first inclination is that when a pinned resources request is made, we can track how many resources "couldn't be found" from their pinned list, and then just remove them. But I don't think thats a good place to do it as I wouldn't want to add extra latency to the request. there should be some way to clean them up however, because if that was left to grow unbounded then we could run into the issue above.

What will be displayed to a user if a pinned resource is removed?

If they pinned something that gets removed or they lose access to it, it just wouldn't be in shown. a "pinned resource" is really just an extra filter with specific IDs. you can do the same with an advanced query, so the same UX if they opened the normal tab and a resource was gone. it just wouldn't be there.

Is the resource id enough information for a user to discern which resource they pinned?

This isn't super relevant yet since they won't see something that doesn't exist. However, I could envision a future where there is a 'user preferences' page that could show the IDs they have pinned (existing and not) and be able to edit it there. Then maybe ID wouldn't be enough, but ID + if it exists or not (with info from existing resources surrounding it) might be enough. That bridge is very far down the road tho.

To summarize, the main points that should probably be solved now-ish or at least documented are the cleanup phase and the max size. I will try to get something written up about this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Based on the above, I'd lean toward storing the pins per-cluster rather than storing all pins in root as is currently done. If we store pins per cluster, doing automatic cleanup as a periodic won't be too difficult. If, on the other hand, we do all pinning in the root that makes things very complicated. Cross-cluster communication is non-trivial.

Also note that a resource disappearing temporarily doesn't necessarily mean that it's gone. An automatic cleanup routine should probably track timestamps and only clean up resource that remain missing for some minimum amount of time + number of checks.

IMO wether or not this PR includes a cleanup mechanism, we should have a reasonably clear idea of how the cleanup mechanism will function prior to merging it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think it's a bad idea to put an upper limit on the number of pinned resources. Pinning resources becomes less helpful the more you pin, so I'd expect people won't pin too many. Maybe we set a hard cap to something like 300 or 500?

As far as cleanup goes, I think for now it's okay if your preferences reference a resource that no longer exists - they just won't show up in the listing.

We can work with @roraback to get some designs for how you might remove them.

@avatus
Copy link
Copy Markdown
Contributor Author

avatus commented Sep 26, 2023

Updated to store cluster preferences per cluster

@michellescripts michellescripts removed their request for review September 28, 2023 19:30
Comment on lines -86 to +84
}

item, err := createBackendItem(username, preferences)
item, err := createBackendItem(username, prefs)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was removed because originally, we'd only be sending small chunks of the user preferences to update. Now we send the entire thing (before this PR) so we can just completely overwrite the prefs. Using a range to go through what was sent in the protomessage would skip empty values and therefor not allow us to "empty" our pinned resources. Now that we send the entire thing, it works as expected.

@avatus avatus requested a review from rosstimothy October 5, 2023 18:50
Comment thread api/proto/teleport/userpreferences/v1/cluster_preferences.proto Outdated
Comment thread api/proto/teleport/userpreferences/v1/cluster_preferences.proto
Comment thread lib/auth/userpreferences/userpreferencesv1/service_test.go Outdated
Comment thread lib/services/local/userpreferences.go Outdated
Comment thread lib/services/local/userpreferences_test.go Outdated
Comment thread lib/web/userpreferences.go
Comment thread lib/web/userpreferences.go Outdated
Comment thread lib/web/userpreferences.go Outdated
@avatus avatus requested a review from rosstimothy October 7, 2023 01:19
Comment thread lib/web/userpreferences.go Outdated
Comment on lines 170 to 174
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: this is only called in one place and this function has become simple enough it might be worthwhile to just instantiate the response struct inline.

Comment on lines 21 to 22
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: only the comments in the .ts files end with punctuation.

Suggested change
// PinnedResourcesUserPreferences is a collection of resource IDs that will be
// displayed in the user's pinned resources tab in the Web UI
// PinnedResourcesUserPreferences is a collection of resource IDs that will be
// displayed in the user's pinned resources tab in the Web UI.

@avatus avatus force-pushed the avatus/pinned_user_prefs branch from d2d0b55 to dceb604 Compare October 10, 2023 15:30
@avatus avatus temporarily deployed to vercel October 10, 2023 15:31 — with GitHub Actions Inactive
@avatus avatus enabled auto-merge October 10, 2023 15:33
@github-actions
Copy link
Copy Markdown
Contributor

🤖 Vercel preview here: https://docs-5j32kwuz0-goteleport.vercel.app/docs/ver/preview

@avatus avatus added this pull request to the merge queue Oct 10, 2023
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 10, 2023
@avatus avatus added this pull request to the merge queue Oct 10, 2023
Merged via the queue into master with commit af6dd45 Oct 10, 2023
@avatus avatus deleted the avatus/pinned_user_prefs branch October 10, 2023 18:30
github-merge-queue Bot pushed a commit that referenced this pull request Oct 12, 2023
* Include Pinned Resources in User Preferences (#32009)

* Cherry-pick b905eaf

* Fix merge conflict

* Properly check for SAMLIdPServiceProvider access (#33190)

* Properly check for SAMLIdPServiceProvider access

* Remove unneeded debug log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pinned resource IDs to user prefernces

5 participants