Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Automatic Import] Try parsing samples as both NDJSON and JSON (elast…
…ic#190046) ## Summary Changes the logic for parsing log samples in the Automatic Import plugin. ## Explanation Previously we relied on the `fileType` as reported by the browser to differentiate between JSON and newline-delimited JSON (NDJSON) format. This required the user to save the file with a correct extension and was broken for some combinations of browsers + operating systems. The fix consists in optimistically attempting to parse the sample as NDJSON; if that fails we attempt JSON. We consider separately a case of file that consists of one JSON line, since it's both a valid JSON and a valid NDJSON. This makes `fileType` parameter unused, so we also remove it. We also use the new error message (in the spotlight of the image) when parsing fails: https://github.com/user-attachments/assets/334a6424-21dd-4fb4-8ce9-4536894c396f Note that the "logs sample" is consistent with the existing texts: defaultMessage: 'The logs sample file is not an array', ... defaultMessage: 'The logs sample file is empty', ... defaultMessage: 'The logs sample file contains non-object entries', This will also make it easier to upload multiple files at once, shall we decide to implement such a feature. ### Risk Matrix There are performance considerations, but they are fairly minimal: - Where the file was previously expected to have NDJSON format, we continue to parse it as such, without spending any additional time. - Where the file was previously expected to have JSON format, we now first try to parse it as NDJSON. This requires additional time to fail, but it should be fast (after the first line). - Where the file is actually malformed, previously we tried to parse it once, but now will try to parse it twice. This increases the time to fail, which can be significant if the file is a JSON that is malformed towards the end. However, we expect this to be a rare scenario. | Risk | Probability | Severity | Mitigation/Notes | |---------------------------|-------------|----------|-------------------------| | Longer time to process the log in the UI. | Low | Low | As explained, only likely to be significant for malformed files. | --------- Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Marius Iversen <[email protected]>
- Loading branch information