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

Gracefully disable favorites if profile is not available #204397

Merged
merged 18 commits into from
Dec 30, 2024

Conversation

Dosant
Copy link
Contributor

@Dosant Dosant commented Dec 16, 2024

Summary

When a user profile is not available, the favorites (starred) service can't be used. On UI user profile can be not available if security is disabled or for an anonymous user.

This PR improves the handling of starred features for rare cases when a profile is missing:

  • No unnecessary GET favorites requests that would fail with error and add noise to console/networks
  • No unhandled errors are thrown
  • Starred tab in esql is hidden
  • The Dashboard Starred tab isn't flickering on each attempt to fetch favorites

For this needed to expose userProfile.enabled$ from core, also created #204570

Testing

node scripts/functional_tests_server.js --config test/functional/apps/dashboard/group4/config.ts

localhost:5620

another way is by configuring an anonymous user https://www.elastic.co/guide/en/elasticsearch/reference/current/anonymous-access.html

@Dosant Dosant changed the title improve Gracefull disable favorites if profile is not available Dec 17, 2024
@Dosant Dosant changed the title Gracefull disable favorites if profile is not available Gracefully disable favorites if profile is not available Dec 17, 2024
@Dosant Dosant added release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) labels Dec 17, 2024
@Dosant Dosant marked this pull request as ready for review December 17, 2024 17:01
@Dosant Dosant requested review from a team as code owners December 17, 2024 17:01
@elasticmachine
Copy link
Contributor

Pinging @elastic/appex-sharedux (Team:SharedUX)

userProfile$: Observable<UserProfileData | null>;
enabled$: Observable<boolean>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exposing enabled$ from core

@@ -470,22 +470,30 @@ export function HistoryAndStarredQueriesTabs({
const kibana = useKibana<ESQLEditorDeps>();
const { core, usageCollection, storage } = kibana.services;

const [starredQueriesService, setStarredQueriesService] = useState<EsqlStarredQueriesService>();
const [starredQueriesService, setStarredQueriesService] = useState<
EsqlStarredQueriesService | null | undefined
Copy link
Contributor Author

Choose a reason for hiding this comment

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

adding null state for tracking when starredQueriesService couldn't initialize and use it to hide the "starred" tab. intentionally showing "starred" tab during undefined (loading) state because it is the most common scenario and we can avoid a content flash

Copy link
Member

@afharo afharo left a comment

Choose a reason for hiding this comment

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

Core changes LGTM. Code review only.

@stratoula
Copy link
Contributor

@Dosant can you provide steps on how to test it?

@Dosant
Copy link
Contributor Author

Dosant commented Dec 18, 2024

@stratoula, imo the simplest would be to run any functional tests server from config from src/ since security is not enabled there.

e.g.

node scripts/functional_tests_server.js --config test/functional/apps/dashboard/group4/config.ts

localhost:5620

another way is by configuring anonymous user https://www.elastic.co/guide/en/elasticsearch/reference/current/anonymous-access.html

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

ES|QL changes LGTM, did a brief testing locally to ensure that it works as expected

Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

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

LGTM from the Platform Security perspective. Tested locally using anonymous access - favorite controls aren’t visible as expected, and the UI isn’t broken. However, I wish we could avoid throwing an exception when the profile isn’t available, as it’s a normal expected flow for certain configurations (adding a warn favorites-specific log line would be much better, as having all user profile consumers throw errors could create a misleading perception).

image

@Dosant
Copy link
Contributor Author

Dosant commented Dec 19, 2024

However, I wish we could avoid throwing an exception when the profile isn’t available, as it’s a normal expected flow for certain configurations (adding a warn favorites-specific log line would be much better, as having all user profile consumers throw errors could create a misleading perception).

@azasypkin, thanks, I'll double-check. I might have missed something when was changing the check to enabled$


Update: so it works without an error in console for ESQL favorites, but it becomes quite a bit large change to fix this in dashboard because logic to hide Starred tab relies on a thrown error and it is default react-query behaviour to log an error even when it is handled.
I'd like to keep it like this

Comment on lines +89 to +90
const isAvailable = await client.isAvailable();
if (!isAvailable) return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

is it worth extending this conditional check here to the dashboard list implementation to determine if favorites is enabled here https://github.com/elastic/kibana/blob/v8.17.0/packages/content-management/table_list_view_table/src/services.tsx#L278, especially that when we navigate to the dashboard listing page at attempt is still made to request favorites?

Copy link
Contributor Author

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 ideal, but that check is async so I wanted to avoid additional changes.
I will take another look

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just changed that isFavoritesEnabled to allow for Promise

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also fixes @azasypkin's suggestion: #204397 (review)

Copy link
Contributor

@eokoneyo eokoneyo left a comment

Choose a reason for hiding this comment

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

Tested this, UI to star entities doesn't get displayed for both ESQL and dashboard listing when the user profile isn't available, however for dashboard listing an request attempt is still being made to fetch the user's favourites.

verified using the following config to kibana.dev.yml,

xpack.security.authc.providers:
  basic.basic1:
    order: 0
  anonymous.anonymous1:
    order: 1
    credentials:
      username: "elastic"
      password: "changeme"

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
eventAnnotationListing 619 622 +3
filesManagement 178 181 +3
graph 290 293 +3
maps 1248 1250 +2
visualizations 473 476 +3
total +14

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/content-management-favorites-public 42 45 +3

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
dashboard 666.3KB 666.6KB +336.0B
esql 202.6KB 203.1KB +529.0B
eventAnnotationListing 229.7KB 231.0KB +1.3KB
filesManagement 121.0KB 122.3KB +1.3KB
graph 413.0KB 414.3KB +1.3KB
maps 3.0MB 3.0MB +1.1KB
visualizations 320.7KB 322.0KB +1.3KB
total +7.2KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
core 443.9KB 444.0KB +53.0B
filesManagement 3.9KB 4.0KB +48.0B
total +101.0B
Unknown metric groups

API count

id before after diff
@kbn/content-management-favorites-public 43 46 +3
@kbn/core-user-profile-browser 29 30 +1
total +4

History

@Dosant Dosant merged commit 70cf414 into elastic:main Dec 30, 2024
9 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/12548645226

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 30, 2024
)

## Summary

When a user profile is not available, the favorites (starred) service
can't be used. On UI user profile can be not available if security is
disabled or for an anonymous user.

This PR improves the handling of starred features for rare cases when a
profile is missing:

- No unnecessary `GET favorites` requests that would fail with error and
add noise to console/networks
- No unhandled errors are thrown
- Starred tab in esql is hidden
- The Dashboard Starred tab isn't flickering on each attempt to fetch
favorites

For this needed to expose `userProfile.enabled$` from core, also created
elastic#204570

### Testing

```
node scripts/functional_tests_server.js --config test/functional/apps/dashboard/group4/config.ts

localhost:5620
```

another way is by configuring an anonymous user
https://www.elastic.co/guide/en/elasticsearch/reference/current/anonymous-access.html

(cherry picked from commit 70cf414)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Dec 30, 2024
…) (#205270)

# Backport

This will backport the following commits from `main` to `8.x`:
- [Gracefully disable favorites if profile is not available
(#204397)](#204397)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Anton
Dosov","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-30T15:35:51Z","message":"Gracefully
disable favorites if profile is not available (#204397)\n\n##
Summary\r\n\r\nWhen a user profile is not available, the favorites
(starred) service\r\ncan't be used. On UI user profile can be not
available if security is\r\ndisabled or for an anonymous
user.\r\n\r\nThis PR improves the handling of starred features for rare
cases when a\r\nprofile is missing:\r\n\r\n- No unnecessary `GET
favorites` requests that would fail with error and\r\nadd noise to
console/networks\r\n- No unhandled errors are thrown\r\n- Starred tab in
esql is hidden\r\n- The Dashboard Starred tab isn't flickering on each
attempt to fetch\r\nfavorites\r\n\r\nFor this needed to expose
`userProfile.enabled# Backport

This will backport the following commits from `main` to `8.x`:
- [Gracefully disable favorites if profile is not available
(#204397)](#204397)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT from core, also
created\r\nhttps://github.com//issues/204570\r\n\r\n\r\n\r\n###
Testing \r\n\r\n```\r\nnode scripts/functional_tests_server.js --config
test/functional/apps/dashboard/group4/config.ts\r\n\r\nlocalhost:5620\r\n```\r\n\r\nanother
way is by configuring an anonymous
user\r\nhttps://www.elastic.co/guide/en/elasticsearch/reference/current/anonymous-access.html","sha":"70cf414f42c3e7b0974cb8a3e508308f4206047e","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:SharedUX","backport:prev-minor"],"title":"Gracefully
disable favorites if profile is not
available","number":204397,"url":"https://github.com/elastic/kibana/pull/204397","mergeCommit":{"message":"Gracefully
disable favorites if profile is not available (#204397)\n\n##
Summary\r\n\r\nWhen a user profile is not available, the favorites
(starred) service\r\ncan't be used. On UI user profile can be not
available if security is\r\ndisabled or for an anonymous
user.\r\n\r\nThis PR improves the handling of starred features for rare
cases when a\r\nprofile is missing:\r\n\r\n- No unnecessary `GET
favorites` requests that would fail with error and\r\nadd noise to
console/networks\r\n- No unhandled errors are thrown\r\n- Starred tab in
esql is hidden\r\n- The Dashboard Starred tab isn't flickering on each
attempt to fetch\r\nfavorites\r\n\r\nFor this needed to expose
`userProfile.enabled# Backport

This will backport the following commits from `main` to `8.x`:
- [Gracefully disable favorites if profile is not available
(#204397)](#204397)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT from core, also
created\r\nhttps://github.com//issues/204570\r\n\r\n\r\n\r\n###
Testing \r\n\r\n```\r\nnode scripts/functional_tests_server.js --config
test/functional/apps/dashboard/group4/config.ts\r\n\r\nlocalhost:5620\r\n```\r\n\r\nanother
way is by configuring an anonymous
user\r\nhttps://www.elastic.co/guide/en/elasticsearch/reference/current/anonymous-access.html","sha":"70cf414f42c3e7b0974cb8a3e508308f4206047e"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204397","number":204397,"mergeCommit":{"message":"Gracefully
disable favorites if profile is not available (#204397)\n\n##
Summary\r\n\r\nWhen a user profile is not available, the favorites
(starred) service\r\ncan't be used. On UI user profile can be not
available if security is\r\ndisabled or for an anonymous
user.\r\n\r\nThis PR improves the handling of starred features for rare
cases when a\r\nprofile is missing:\r\n\r\n- No unnecessary `GET
favorites` requests that would fail with error and\r\nadd noise to
console/networks\r\n- No unhandled errors are thrown\r\n- Starred tab in
esql is hidden\r\n- The Dashboard Starred tab isn't flickering on each
attempt to fetch\r\nfavorites\r\n\r\nFor this needed to expose
`userProfile.enabled# Backport

This will backport the following commits from `main` to `8.x`:
- [Gracefully disable favorites if profile is not available
(#204397)](#204397)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT from core, also
created\r\nhttps://github.com//issues/204570\r\n\r\n\r\n\r\n###
Testing \r\n\r\n```\r\nnode scripts/functional_tests_server.js --config
test/functional/apps/dashboard/group4/config.ts\r\n\r\nlocalhost:5620\r\n```\r\n\r\nanother
way is by configuring an anonymous
user\r\nhttps://www.elastic.co/guide/en/elasticsearch/reference/current/anonymous-access.html","sha":"70cf414f42c3e7b0974cb8a3e508308f4206047e"}}]}]
BACKPORT-->

Co-authored-by: Anton Dosov <[email protected]>
stratoula pushed a commit to stratoula/kibana that referenced this pull request Jan 2, 2025
)

## Summary

When a user profile is not available, the favorites (starred) service
can't be used. On UI user profile can be not available if security is
disabled or for an anonymous user.

This PR improves the handling of starred features for rare cases when a
profile is missing:

- No unnecessary `GET favorites` requests that would fail with error and
add noise to console/networks
- No unhandled errors are thrown
- Starred tab in esql is hidden
- The Dashboard Starred tab isn't flickering on each attempt to fetch
favorites

For this needed to expose `userProfile.enabled$` from core, also created
elastic#204570



### Testing 

```
node scripts/functional_tests_server.js --config test/functional/apps/dashboard/group4/config.ts

localhost:5620
```

another way is by configuring an anonymous user
https://www.elastic.co/guide/en/elasticsearch/reference/current/anonymous-access.html
benakansara pushed a commit to benakansara/kibana that referenced this pull request Jan 2, 2025
)

## Summary

When a user profile is not available, the favorites (starred) service
can't be used. On UI user profile can be not available if security is
disabled or for an anonymous user.

This PR improves the handling of starred features for rare cases when a
profile is missing:

- No unnecessary `GET favorites` requests that would fail with error and
add noise to console/networks
- No unhandled errors are thrown
- Starred tab in esql is hidden
- The Dashboard Starred tab isn't flickering on each attempt to fetch
favorites

For this needed to expose `userProfile.enabled$` from core, also created
elastic#204570



### Testing 

```
node scripts/functional_tests_server.js --config test/functional/apps/dashboard/group4/config.ts

localhost:5620
```

another way is by configuring an anonymous user
https://www.elastic.co/guide/en/elasticsearch/reference/current/anonymous-access.html
cqliu1 pushed a commit to cqliu1/kibana that referenced this pull request Jan 2, 2025
)

## Summary

When a user profile is not available, the favorites (starred) service
can't be used. On UI user profile can be not available if security is
disabled or for an anonymous user.

This PR improves the handling of starred features for rare cases when a
profile is missing:

- No unnecessary `GET favorites` requests that would fail with error and
add noise to console/networks
- No unhandled errors are thrown
- Starred tab in esql is hidden
- The Dashboard Starred tab isn't flickering on each attempt to fetch
favorites

For this needed to expose `userProfile.enabled$` from core, also created
elastic#204570



### Testing 

```
node scripts/functional_tests_server.js --config test/functional/apps/dashboard/group4/config.ts

localhost:5620
```

another way is by configuring an anonymous user
https://www.elastic.co/guide/en/elasticsearch/reference/current/anonymous-access.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Team label for AppEx-SharedUX (formerly Global Experience) v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants