Class: Gitlab::QA::SystemLogs::Finders::JsonLogFinder
- Inherits:
-
Object
- Object
- Gitlab::QA::SystemLogs::Finders::JsonLogFinder
- Defined in:
- lib/gitlab/qa/system_logs/finders/json_log_finder.rb
Direct Known Subclasses
Rails::ApiLogFinder, Rails::ApplicationLogFinder, Rails::ExceptionLogFinder, Rails::GraphqlLogFinder
Instance Method Summary collapse
- #find(correlation_id) ⇒ Object
-
#initialize(base_path, file_path) ⇒ JsonLogFinder
constructor
A new instance of JsonLogFinder.
- #new_log(data) ⇒ Object
Constructor Details
#initialize(base_path, file_path) ⇒ JsonLogFinder
Returns a new instance of JsonLogFinder.
10 11 12 13 |
# File 'lib/gitlab/qa/system_logs/finders/json_log_finder.rb', line 10 def initialize(base_path, file_path) @base_path = base_path @file_path = file_path end |
Instance Method Details
#find(correlation_id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gitlab/qa/system_logs/finders/json_log_finder.rb', line 15 def find(correlation_id) log_file_path = "#{@base_path}/#{@file_path}" logs = [] if File.exist?(log_file_path) && !correlation_id.nil? File.foreach(log_file_path) do |line| begin json_line = JSON.parse(line, symbolize_names: true) rescue JSON::ParserError Runtime::Logger.debug("JsonLogFinder#find attempted to parse invalid JSON: #{line}") next end if (json_line[:correlation_id])&.casecmp?(correlation_id) normalized_line = normalize_keys(json_line) logs << new_log(normalized_line) end end end logs end |
#new_log(data) ⇒ Object
39 40 41 |
# File 'lib/gitlab/qa/system_logs/finders/json_log_finder.rb', line 39 def new_log(data) raise 'abstract method new_log must be defined!' end |