-
Notifications
You must be signed in to change notification settings - Fork 67
[ML] Better handling of invalid JSON state documents #2895
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
Open
edsavage
wants to merge
6
commits into
elastic:main
Choose a base branch
from
edsavage:improve_parsing_json_state
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e8498cb
[ML] Better handling of invalid JSON state documents
edsavage bff89ce
Formatting
edsavage 75c6624
Update changelog
edsavage 5a5964b
Address code review comments
edsavage ee61c6f
Formatting
edsavage 587ec70
add missing file
edsavage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "job_id": "logs_services_count_logs_categories", | ||
| "analysis_config": { | ||
| "categorization_field_name": "message", | ||
| "per_partition_categorization": { | ||
| "enabled": true, | ||
| "stop_on_warn": false | ||
| }, | ||
| "detectors": [ | ||
| { | ||
| "detector_description": "count by mlcategory partitionfield=\"service.name\"", | ||
| "function": "count", | ||
| "by_field_name": "mlcategory", | ||
| "partition_field_name": "service.name" | ||
| } | ||
| ], | ||
| "influencers": [ | ||
| "mlcategory", | ||
| "service.name" | ||
| ] | ||
| }, | ||
| "data_description": { | ||
| "time_field": "@timestamp", | ||
| "time_format": "epoch_ms" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,9 +108,23 @@ bool CStateDecompressor::CDechunkFilter::parseNext() { | |
| do { | ||
| char c = m_InputStreamWrapper->take(); | ||
| if (c == '\0') { | ||
| std::string message; | ||
| if (m_ParsingStarted == false) { | ||
| message = "Encountered NULL character in stream before parsing has started."; | ||
| ret = false; | ||
| } | ||
| if (m_Reader->handler().s_Type == SBoostJsonHandler::E_TokenObjectEnd) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since both if statements could be true, you would potentially reassign |
||
| if (message.size() > 0) { | ||
| message += "\n"; | ||
| } | ||
| message += "Encountered NULL character in stream after object end."; | ||
| ret = false; | ||
| } | ||
| if (ret == false && message.empty() == false) { | ||
| std::string jsonStr(m_Reader->handler().s_CompressedChunk, | ||
| m_Reader->handler().s_CompressedChunkLength); | ||
| LOG_WARN(<< "Error parsing JSON: \"" << jsonStr << "\". " << message); | ||
valeriy42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| break; | ||
| } | ||
|
|
||
|
|
@@ -160,7 +174,7 @@ bool CStateDecompressor::CDechunkFilter::readHeader() { | |
| } | ||
| // If we are here, we have got an empty document from downstream, | ||
| // so the stream is finished | ||
| LOG_TRACE(<< "Failed to find 'compressed' data array!"); | ||
| LOG_WARN(<< "Failed to find 'compressed' data array!"); | ||
| m_Initialised = false; | ||
| m_IStream.reset(); | ||
| ++m_CurrentDocNum; | ||
|
|
@@ -243,7 +257,7 @@ void CStateDecompressor::CDechunkFilter::handleRead(char* s, | |
| std::streamsize CStateDecompressor::CDechunkFilter::endOfStream(char* s, | ||
| std::streamsize n, | ||
| std::streamsize bytesDone) { | ||
| // return [ ] if not m_Initialised | ||
| // return [ ] if not m_Initialised - i.e. if no valid json could be found | ||
| m_EndOfStream = true; | ||
| if (!m_SentData && bytesDone == 0) { | ||
| std::streamsize toCopy = std::min(std::streamsize(EMPTY_DATA.size()), n); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.