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

[Cases] User profile hooks #137830

Merged
merged 26 commits into from
Aug 4, 2022
Merged

Conversation

cnasikas
Copy link
Member

@cnasikas cnasikas commented Aug 2, 2022

Summary

This PR created user profile hooks. One for the suggest API and one for the bulk get API.

Depends on: #137346

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@cnasikas cnasikas added release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature labels Aug 2, 2022
@cnasikas cnasikas self-assigned this Aug 2, 2022
@cnasikas cnasikas changed the title Suggestion api query [Cases] User profile hooks Aug 2, 2022
@cnasikas cnasikas added the v8.5.0 label Aug 2, 2022
* User profiles
*/

export const DEFAULT_USER_SIZE = 100;
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about defaulting it to 10? I believe that's what the Elasticsearch default is. 100 seems like it could result in a pretty long list.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok! Sounds good to me.

uids,
}: BulkGetUserProfilesArgs): Promise<UserProfile[]> => {
if (security == null) {
return Promise.resolve([]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it give us an error if we just do return []? I thought async functions would automatically wrap the return value in a promise 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, you are right. I missed that.

});
},
{
enabled: !isEmpty(debouncedName),
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm does this mean we won't show anything if the user hasn't typed anything? I wonder what Elasticsearch will return if we don't send in a name, maybe the most recently logged in users? I can test that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that means that the query will not run if the user hasn't typed anything. You are right. Let's test it together offline and see what the results will be.

Copy link
Member Author

@cnasikas cnasikas Aug 3, 2022

Choose a reason for hiding this comment

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

Ok, I tested it and ES returns a suggestion of users even with an empty string. I removed the enabled to simulate the same behavior.

@@ -215,11 +215,11 @@ export const getManagementFilteredLinks = async (
plugins: StartPlugins
): Promise<LinkItem> => {
try {
const currentUserResponse = await plugins.security.authc.getCurrentUser();
const currentUserResponse = await plugins.security?.authc.getCurrentUser();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: It turns out that the security plugin will always be defined even if security is disabled within Elasticsearch. I think we could probably leave this the way it was.

Copy link
Member Author

Choose a reason for hiding this comment

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

How is that possible? I thought that if you put it in the kibana.json as optional then it maybe not be there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that's what I thought too, but it's no longer the case. I think it's because you can't actually disable the security plugin itself. It is always enabled. You can disable security though, but it is now done within Elasticsearch directly. So for example if you attempt to call the suggestions API, Elasticsearch will throw a 500 I think saying that the API does not exist.

That's why we now have to check for the license to determine if security is disabled: https://github.com/elastic/kibana/blob/main/x-pack/plugins/cases/server/services/user_profiles/index.ts#L109
#137861 -> I still need to clean up the undefined checks we have in cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the explanation. I reverted back.

@cnasikas cnasikas marked this pull request as ready for review August 2, 2022 15:55
@cnasikas cnasikas requested review from a team as code owners August 2, 2022 15:55
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@cnasikas cnasikas requested review from joeypoon and parkiino August 2, 2022 15:55
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops-cases (Feature:Cases)

@jonathan-buttner
Copy link
Contributor

@elasticmachine merge upstream

@cnasikas cnasikas force-pushed the suggestion_api_query branch from daf1989 to a036f26 Compare August 3, 2022 10:34
@cnasikas
Copy link
Member Author

cnasikas commented Aug 3, 2022

@jonathan-buttner I made the security plugin required. I spoke with the security team and since 8.0 you cannot disable the security plugin in Kibana. It is safe to make security a required dependency.

@jonathan-buttner
Copy link
Contributor

@elasticmachine merge upstream

Copy link
Member

@simianhacker simianhacker left a comment

Choose a reason for hiding this comment

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

LGTM

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Security Solution Tests #1 / Alert Flyout Opens a new timeline investigation with alert ids from the process ancestry

Metrics [docs]

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
observability 395 396 +1
Unknown metric groups

API count

id before after diff
observability 398 399 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @cnasikas

@cnasikas cnasikas merged commit c3a55d1 into elastic:main Aug 4, 2022
@cnasikas cnasikas deleted the suggestion_api_query branch August 4, 2022 12:22
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Cases Cases feature release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants