Implement async grep result bounding and error handling - #778
Merged
Conversation
_MAX_RESULT_BYTES caps the result stored in the database, not the output the daemon buffers to produce it: capture_output=True reads the matcher's entire stdout into this process before the slice is taken. Log files here reach 6.0 GB (panda-DBProxy.log) and 2.3 GB (panda-JediDBProxy.log), so a pattern that matches most lines -- a timestamp, a level, a common tag -- makes the async_request_processor allocate that much and then throw nearly all of it away. The cap costs nothing to add, because everything past the byte limit was already being discarded: no caller can receive more than 1 MB today, so bounding the match count cannot lose a byte anyone could have seen. It applies by default, with the default set high enough that stored results and their truncated flag are unchanged. max_matches passes -m to the matcher, which both grep and rg spell the same way, so it works compressed or not; it stops the scan as well as the output. tail_bytes searches only the end of the file, which is how to ask about recent activity in a log this size. It is ignored for .gz, where an arbitrary offset is not a valid stream. The pipeline is built process to process, never through a shell -- the pattern comes from the caller. The read end is handed to the matcher and closed here, so that a matcher exiting at its cap lets tail stop rather than leaving it blocked on a pipe nobody drains. truncated is now also set when the cap is reached. A caller that reads a capped result as "this never appears in the log" gets the wrong answer, and that is the one mistake this data is used to avoid. A missing log file is reported as failed with "No such file or directory" rather than left to the tool. With a tail window the matcher reads standard input and never sees the path, so it would report no match for a file that is not there -- and "the file does not exist" is a meaningful answer (nothing has ever written it) that must not depend on how the query was built. This turns what was previously done/return_code=2 into failed, consistent with how the handler already reports a timeout.
_MAX_RESULT_BYTES caps the result stored in the database, not the output the daemon buffers to produce it: capture_output=True reads the matcher's entire stdout into this process before the slice is taken. Log files here reach 6.0 GB (panda-DBProxy.log) and 2.3 GB (panda-JediDBProxy.log), so a pattern that matches most lines -- a timestamp, a level, a common tag -- makes the async_request_processor allocate that much and then throw nearly all of it away. The cap costs nothing to add, because everything past the byte limit was already being discarded: no caller can receive more than 1 MB today, so bounding the match count cannot lose a byte anyone could have seen. It applies by default, with the default set high enough that stored results and their truncated flag are unchanged. max_matches passes -m to the matcher, which both grep and rg spell the same way, so it works compressed or not; it stops the scan as well as the output. tail_bytes searches only the end of the file, which is how to ask about recent activity in a log this size. It is ignored for .gz, where an arbitrary offset is not a valid stream. The pipeline is built process to process, never through a shell -- the pattern comes from the caller. The read end is handed to the matcher and closed here, so that a matcher exiting at its cap lets tail stop rather than leaving it blocked on a pipe nobody drains. truncated is now also set when the cap is reached. A caller that reads a capped result as "this never appears in the log" gets the wrong answer, and that is the one mistake this data is used to avoid. A missing log file is reported as failed with "No such file or directory" rather than left to the tool. With a tail window the matcher reads standard input and never sees the path, so it would report no match for a file that is not there -- and "the file does not exist" is a meaningful answer (nothing has ever written it) that must not depend on how the query was built. This turns what was previously done/return_code=2 into failed, consistent with how the handler already reports a timeout.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.