Fix Array message handling in parser methods#62
Merged
Conversation
Some log formats may have the 'message' field as an Array instead of a String. The parser methods were calling String methods like match?() and include?() directly on the message field, which caused 'undefined method match? for an instance of Array' errors. Changes: - Add normalize_message() helper method to handle String, Array, nil, and other types - Update all message detection methods (sql_message?, cache_message?, call_stack_message?, job_enqueue_message?) to use normalize_message() - Update Entry class to normalize messages when setting content - Update CallLineEntry to use normalized messages - Update extract_job_id_from_enqueue() to handle Array messages - Add comprehensive test coverage for Array message handling Fixes issue where log_bench would crash when encountering log entries with Array messages, particularly affecting job enqueue detection.
Owner
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.
Problem
log_bench was crashing with the following error when encountering log entries where the
messagefield was an Array instead of a String:Root Cause
The parser methods (
sql_message?,cache_message?,call_stack_message?,job_enqueue_message?) were calling String methods likematch?()andinclude?()directly ondata["message"]without checking if it was actually a String. Some logging libraries may output themessagefield as an Array, causing these methods to fail.Solution
Added a
normalize_message()helper method that safely converts various input types to a String:to_sAll message detection methods now use this helper to ensure they always receive a String, preventing the
match?error.Changes
normalize_message()helper method toLogBench::Log::Parsersql_message?()to use normalized messagescache_message?()to use normalized messagescall_stack_message?()to use normalized messagesjob_enqueue_message?()to use normalized messagesextract_job_id_from_enqueue()to handle Array messagesEntry#initializeto normalize messages when setting contentCallLineEntryto use normalized messagesTesting
Added tests covering:
normalize_message()with String, Array, nil, and other typesAll existing tests continue to pass, ensuring backward compatibility.
Impact
This fix ensures log_bench works correctly with log formats that use Array messages. The change is backward compatible - String messages continue to work as before.