Skip to content

[8.15] [Automatic Import] Error handling when uploading a file (#191310)#192464

Merged
bhapas merged 1 commit intoelastic:8.15from
bhapas:backport/8.15/pr-191310
Sep 10, 2024
Merged

[8.15] [Automatic Import] Error handling when uploading a file (#191310)#192464
bhapas merged 1 commit intoelastic:8.15from
bhapas:backport/8.15/pr-191310

Conversation

@bhapas
Copy link
Copy Markdown
Contributor

@bhapas bhapas commented Sep 10, 2024

Backport

This will backport the following commits from main to 8.15:

Questions ?

Please refer to the Backport tool documentation

### Release note

Display better error messages for issues with logs sample file upload in
Automatic Import.

## Summary

Previously the user would be told about parse issues that occur after
the file is successfully uploaded. However in the following scenarios
the operation would silently fail without displaying a user-visible
error:

1. When the file fails to upload (e.g. when it is too big).
2. When the upload operation is aborted, e.g. programmatically.

Additionally in the following scenario the generic `CAN_NOT_PARSE`
message was displayed:

3. When the file is uploaded but the browser runs out of memory when
trying to parse it.

Additionally, in the following scenario the `EMPTY` message was
displayed:

4. When the file is too big for the V8 engine (e.g. Chrome) to create a
string so upload process returns an empty string.

Additionally:

5. When the user switches from the invalid file (with an error
displayed) to the valid file, the error from the invalid file was
displayed during the analysis of the new file.

After the changes in this PR, the following error types would be
displayed in these cases, respectively:

1. `CAN_NOT_READ_WITH_REASON`: _An error occurred when reading logs
sample: {reason}_
2. `CAN_NOT_READ_WITH_REASON`: _An error occurred when reading logs
sample: An ongoing operation was aborted, typically with a call to
abort()._ (reason is provided by the browser)
3. `TOO_LARGE_TO_PARSE`: _This logs sample file is too large to parse_
4. `TOO_LARGE_TO_PARSE`: _This logs sample file is too large to parse_
5. No error would be displayed during the analysis.

This covers part of elastic/security-team#9844
though the issues were discovered separately.

Note that the fix in item 3 does not work in Firefox as it throws an
`InternalError` rather than `RangeError`. A generic `CAN_NOT_PARSE`
message will continue to be displayed in that case. The fix in item 4 is
only relevant for Chrome.

On a slightly different note, we provide the following improvements to
the log sampling functionality introduced in
elastic#190407:

- Add documentation for the `parseLogsContents` and its special cases
- Refactor the `parseLogsContent` output fields into protocols that
clearly define their optionality
- Add tests for the functionality of sampling when the format cannot be
determined
- Fix so that the error message is displayed for the case where
`fileContent == null` in `onChangeLogsSample`

### Risk Matrix

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Due to the complexity of browser engines, some of them might produce
unexpected events, or events in unexpected order and we will confuse the
user with an incorrect error message. | Low | Low | Testing. |

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
(cherry picked from commit 16c2bfe)
@bhapas bhapas added the backport This PR is a backport of another PR label Sep 10, 2024
@bhapas bhapas enabled auto-merge (squash) September 10, 2024 12:25
@bhapas bhapas requested a review from haetamoudi September 10, 2024 12:26
@bhapas bhapas added release_note:enhancement enhancement New value added to drive a business result Team:Security-Scalability Security Integrations Scalability Team labels Sep 10, 2024
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/security-scalability (Team:Security-Scalability)

@bhapas bhapas added the v8.15.2 label Sep 10, 2024
@bhapas bhapas requested a review from semd September 10, 2024 12:42
@bhapas bhapas merged commit 4dcda41 into elastic:8.15 Sep 10, 2024
@kibana-ci
Copy link
Copy Markdown

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Async chunks

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

id before after diff
integrationAssistant 938.7KB 939.5KB +772.0B

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

cc @ilyannn @bhapas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR enhancement New value added to drive a business result release_note:enhancement Team:Security-Scalability Security Integrations Scalability Team v8.15.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants