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
[Security Solution] Failed getFieldsForIndexPattern calls can result in Exception Flyout getting stuck in loading state #158371
[Security Solution] Failed getFieldsForIndexPattern calls can result in Exception Flyout getting stuck in loading state #158371
Conversation
…in Exception Flyout getting stuck in loading state (elastic#158110)
Pinging @elastic/security-solution (Team: SecuritySolution) |
Closing this PR in favour of #155900 |
These changes are smaller than my PR and we want to get this fix in for the next patch release so I'm re-opening this PR |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
pattern: '', | ||
includeUnmapped: true, | ||
}); | ||
const fields = dv.fields.map((field) => field.toSpec()); |
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.
This is duplication of the code above x-pack/plugins/security_solution/public/common/containers/source/index.tsx
It is refactored in #155900. Left duplication to avoid unnecessary conflicts when we gonna merge that PR, since conflict description code is copied from there.
const fieldNameConflictDescriptionsMap = (await data.dataViews | ||
.getFieldsForIndexPattern(dv, { | ||
pattern: '', | ||
includeUnmapped: true, | ||
}) | ||
.then((fieldsToReduce) => { | ||
return fieldsToReduce.reduce( | ||
(acc, f) => ({ ...acc, [f.name]: f.conflictDescriptions }), | ||
{} as { [x: string]: Record<string, string[]> | undefined } | ||
); | ||
})) as { [x: string]: Record<string, string[]> | undefined }; | ||
|
||
dv.fields.replaceAll([ | ||
...fields.map((field) => ({ | ||
...field, | ||
...(fieldNameConflictDescriptionsMap[field.name] != null | ||
? { conflictDescriptions: fieldNameConflictDescriptionsMap[field.name] } | ||
: {}), | ||
})), | ||
]); |
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.
This is my poor-performing code - sorry I offered it up as a working solution from my other PR.
Anyways, I feel we can reduce this to a single iteration with the below code and it should work:
const fieldNameConflictDescriptionsMap = (await data.dataViews | |
.getFieldsForIndexPattern(dv, { | |
pattern: '', | |
includeUnmapped: true, | |
}) | |
.then((fieldsToReduce) => { | |
return fieldsToReduce.reduce( | |
(acc, f) => ({ ...acc, [f.name]: f.conflictDescriptions }), | |
{} as { [x: string]: Record<string, string[]> | undefined } | |
); | |
})) as { [x: string]: Record<string, string[]> | undefined }; | |
dv.fields.replaceAll([ | |
...fields.map((field) => ({ | |
...field, | |
...(fieldNameConflictDescriptionsMap[field.name] != null | |
? { conflictDescriptions: fieldNameConflictDescriptionsMap[field.name] } | |
: {}), | |
})), | |
]); | |
const fieldNameConflictDescriptionsMap = | |
await data.dataViews.getFieldsForIndexPattern(dv, { | |
pattern: '', | |
includeUnmapped: true, | |
}); | |
fieldNameConflictDescriptionsMap.forEach((field) => { | |
dv.fields.update({ ...field }); | |
}); |
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Async chunks
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @e40pud |
…in Exception Flyout getting stuck in loading state (elastic#158371) ## Summary Original ticket elastic#158110 These changes fixes the issue with the exception flyout which can be stuck in loading state in case `getFieldsForIndexPattern` throws an exception. Fixed by putting the `getFieldsForIndexPattern` call in try/catch. We use this call to fetch extended information about the fields [to show warning to the user in case there are some index issues](elastic#149149). If `getFieldsForIndexPattern` fails and throws an exception we will continue using fields without conflicts/unmapped information. I also, noticed that we do not fetch extended information for the case where user uses index patterns instead of data views. Fixed this issue in `useFetchIndex`. cc @dhurley14 We will need to adjust either of our PRs depending whose changes will go in first :-) --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 1a3cad1)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…esult in Exception Flyout getting stuck in loading state (#158371) (#158681) # Backport This will backport the following commits from `main` to `8.8`: - [[Security Solution] Failed getFieldsForIndexPattern calls can result in Exception Flyout getting stuck in loading state (#158371)](#158371) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Ievgen Sorokopud","email":"ievgen.sorokopud@elastic.co"},"sourceCommit":{"committedDate":"2023-05-30T20:23:17Z","message":"[Security Solution] Failed getFieldsForIndexPattern calls can result in Exception Flyout getting stuck in loading state (#158371)\n\n## Summary\r\n\r\nOriginal ticket #158110 changes fixes the issue with the exception flyout which can be\r\nstuck in loading state in case `getFieldsForIndexPattern` throws an\r\nexception.\r\n\r\nFixed by putting the `getFieldsForIndexPattern` call in try/catch. We\r\nuse this call to fetch extended information about the fields [to show\r\nwarning to the user in case there are some index\r\nissues](#149149). If\r\n`getFieldsForIndexPattern` fails and throws an exception we will\r\ncontinue using fields without conflicts/unmapped information.\r\n\r\nI also, noticed that we do not fetch extended information for the case\r\nwhere user uses index patterns instead of data views. Fixed this issue\r\nin `useFetchIndex`.\r\n\r\ncc @dhurley14 We will need to adjust either of our PRs depending whose\r\nchanges will go in first :-)\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"1a3cad1b2744a2fb4be070bc5e60754bc183682c","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team: SecuritySolution","ci:cloud-deploy","v8.9.0","v8.8.1","Team:Detection Engine"],"number":158371,"url":"#158371 Solution] Failed getFieldsForIndexPattern calls can result in Exception Flyout getting stuck in loading state (#158371)\n\n## Summary\r\n\r\nOriginal ticket #158110 changes fixes the issue with the exception flyout which can be\r\nstuck in loading state in case `getFieldsForIndexPattern` throws an\r\nexception.\r\n\r\nFixed by putting the `getFieldsForIndexPattern` call in try/catch. We\r\nuse this call to fetch extended information about the fields [to show\r\nwarning to the user in case there are some index\r\nissues](#149149). If\r\n`getFieldsForIndexPattern` fails and throws an exception we will\r\ncontinue using fields without conflicts/unmapped information.\r\n\r\nI also, noticed that we do not fetch extended information for the case\r\nwhere user uses index patterns instead of data views. Fixed this issue\r\nin `useFetchIndex`.\r\n\r\ncc @dhurley14 We will need to adjust either of our PRs depending whose\r\nchanges will go in first :-)\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"1a3cad1b2744a2fb4be070bc5e60754bc183682c"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"#158371 Solution] Failed getFieldsForIndexPattern calls can result in Exception Flyout getting stuck in loading state (#158371)\n\n## Summary\r\n\r\nOriginal ticket #158110 changes fixes the issue with the exception flyout which can be\r\nstuck in loading state in case `getFieldsForIndexPattern` throws an\r\nexception.\r\n\r\nFixed by putting the `getFieldsForIndexPattern` call in try/catch. We\r\nuse this call to fetch extended information about the fields [to show\r\nwarning to the user in case there are some index\r\nissues](#149149). If\r\n`getFieldsForIndexPattern` fails and throws an exception we will\r\ncontinue using fields without conflicts/unmapped information.\r\n\r\nI also, noticed that we do not fetch extended information for the case\r\nwhere user uses index patterns instead of data views. Fixed this issue\r\nin `useFetchIndex`.\r\n\r\ncc @dhurley14 We will need to adjust either of our PRs depending whose\r\nchanges will go in first :-)\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>","sha":"1a3cad1b2744a2fb4be070bc5e60754bc183682c"}},{"branch":"8.8","label":"v8.8.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Ievgen Sorokopud <ievgen.sorokopud@elastic.co>
Summary
Original ticket #158110
These changes fixes the issue with the exception flyout which can be stuck in loading state in case
getFieldsForIndexPattern
throws an exception.Fixed by putting the
getFieldsForIndexPattern
call in try/catch. We use this call to fetch extended information about the fields to show warning to the user in case there are some index issues. IfgetFieldsForIndexPattern
fails and throws an exception we will continue using fields without conflicts/unmapped information.I also, noticed that we do not fetch extended information for the case where user uses index patterns instead of data views. Fixed this issue in
useFetchIndex
.cc @dhurley14 We will need to adjust either of our PRs depending whose changes will go in first :-)