Class: Jfrog::Saas::Log::Processor
- Inherits:
-
Object
- Object
- Jfrog::Saas::Log::Processor
- Defined in:
- lib/jfrog/saas/log/collector.rb
Instance Method Summary collapse
- #download_and_extract_logs(solution, logs_map) ⇒ Object
- #execute ⇒ Object
- #execute_in_timer ⇒ Object
-
#initialize(config_path) ⇒ Processor
constructor
A new instance of Processor.
- #process_logs(solution, start_date_str, end_date_str) ⇒ Object
Constructor Details
#initialize(config_path) ⇒ Processor
Returns a new instance of Processor.
23 24 25 26 |
# File 'lib/jfrog/saas/log/collector.rb', line 23 def initialize(config_path) ConfigHandler.file_name(config_path) ConfigHandler.instance end |
Instance Method Details
#download_and_extract_logs(solution, logs_map) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/jfrog/saas/log/collector.rb', line 39 def download_and_extract_logs(solution, logs_map) Parallel.map(logs_map&.keys, in_threads: ConfigHandler.instance.proc_config.parallel_downloads) do |date_detail| date_detail_arr = date_detail.split(CommonUtils::DELIM) mapped_solution = date_detail_arr[0] mapped_date = date_detail_arr[1] file_map = logs_map[date_detail] file_map&.each do |file_name, file_details| url = "#{ConfigHandler.instance.conn_config.end_point_base}/#{file_details["repo"]}/#{file_details["path"]}/#{file_details["name"]}" MessageUtils.instance.(MessageUtils::FILE_DOWNLOAD_URL_AND_SIZE, { "param1": url.to_s, "param2": CommonUtils.instance.get_size_in_mb(file_details['size'].to_i, true).to_s, "#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_INFO, "#{MessageUtils::SOLUTION}": solution }) CommonUtils.instance.download_and_extract_log(solution, mapped_date, ConfigHandler.instance.log_config.target_log_path, file_name, url) end end end |
#execute ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/jfrog/saas/log/collector.rb', line 56 def execute MessageUtils.instance.(MessageUtils::APPLICATION_START, { "#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_INFO, "#{MessageUtils::SOLUTION}": 'START' }) FileManager.new.purge_data log_shipping_enabled = CommonUtils.instance.log_shipping_enabled log_repo_found = CommonUtils.instance.check_if_resource_exists(nil, CommonUtils.instance.log_repo_url) audit_repo_found = CommonUtils.instance.check_and_create_audit_repo if log_shipping_enabled && log_repo_found && audit_repo_found start_date_str = (Date.today - ConfigHandler.instance.proc_config.historical_log_days).to_s end_date_str = Date.today.to_s MessageUtils.instance.(MessageUtils::INIT_VERIFICATION, { "param1": "#{ConfigHandler.instance.conn_config.jpd_url}/#{CommonUtils.instance.log_repo_url}", "param2": "#{ConfigHandler.instance.conn_config.jpd_url}/#{CommonUtils.instance.audit_repo_url}", "#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_INFO, "#{MessageUtils::SOLUTION}": MessageUtils::SOLUTION_OVERRIDE_START }) Parallel.map(ConfigHandler.instance.log_config.solutions_enabled, in_processes: ConfigHandler.instance.proc_config.parallel_process) do |solution| logs_to_process = process_logs(solution, start_date_str, end_date_str) download_and_extract_logs(solution, logs_to_process) end elsif !log_shipping_enabled MessageUtils.instance.(MessageUtils::LOG_SHIPPING_NOT_ENABLED, { "param1": ConfigHandler.instance.conn_config.jpd_url.to_s, "#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_INFO, "#{MessageUtils::SOLUTION}": MessageUtils::SOLUTION_OVERRIDE_INIT }) elsif log_shipping_enabled && !log_repo_found MessageUtils.instance.(MessageUtils::LOG_SHIPPING_ENABLED_LOGS_NOT_COLLECTABLE, { "param1": ConfigHandler.instance.conn_config.jpd_url.to_s, "#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_INFO, "#{MessageUtils::SOLUTION}": MessageUtils::SOLUTION_OVERRIDE_INIT }) elsif !audit_repo_found MessageUtils.instance.(MessageUtils::AUDIT_REPO_NOT_FOUND_APPLICATION_STOP, { "param1": "#{ConfigHandler.instance.conn_config.jpd_url}/#{CommonUtils.instance.audit_repo_url}", "#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_ERROR, "#{MessageUtils::SOLUTION}": MessageUtils::SOLUTION_OVERRIDE_INIT }) else MessageUtils.instance.(MessageUtils::INIT_FAILED_APPLICATION_STOP, { "param1": "#{ConfigHandler.instance.conn_config.jpd_url}/#{CommonUtils.instance.log_repo_url}", "param2": "#{ConfigHandler.instance.conn_config.jpd_url}/#{CommonUtils.instance.audit_repo_url}", "#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_ERROR, "#{MessageUtils::SOLUTION}": MessageUtils::SOLUTION_OVERRIDE_INIT }) end MessageUtils.instance.(MessageUtils::APPLICATION_STOP, { "#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_INFO, "#{MessageUtils::SOLUTION}": MessageUtils::SOLUTION_OVERRIDE_STOP }) end |
#execute_in_timer ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/jfrog/saas/log/collector.rb', line 97 def execute_in_timer scheduler = Rufus::Scheduler.new scheduler.every "#{ConfigHandler.instance.proc_config.minutes_between_runs}m", first_in: 1, overlap: false, name: 'jfrog-saas-log-collector-job' do |job| execute next_execution_time = job.next_time.to_s MessageUtils.instance.(MessageUtils::SCHEDULER_NEXT_RUN, { "param1": next_execution_time, "#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_INFO, "#{MessageUtils::SOLUTION}": MessageUtils::SOLUTION_OVERRIDE_NEXT_RUN }) end scheduler.join rescue Errno::ETIMEDOUT, Timeout::Error, Faraday::TimeoutError, Faraday::SSLError, Faraday::ServerError, Faraday::ConnectionFailed => e MessageUtils.instance.(MessageUtils::SHUT_DOWN_PROCESS, { "param1": "#{Process.pid.to_s} [Reason -> #{e}]", "#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_ERROR, "#{MessageUtils::SOLUTION}": MessageUtils::SOLUTION_OVERRIDE_TERMINATE }) Thread.list.each do |thread| MessageUtils.instance.(MessageUtils::TERMINATING_THREAD, { "param1": thread.object_id.to_s, "#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_ERROR, "#{MessageUtils::SOLUTION}": MessageUtils::SOLUTION_OVERRIDE_TERMINATE }) Thread.kill thread end next_execution_time = (Time.now + (ConfigHandler.instance.proc_config.minutes_between_runs * 60)).strftime('%Y-%m-%d %H:%M').to_s MessageUtils.instance.(MessageUtils::SCHEDULER_NEXT_RUN, { "param1": next_execution_time, "#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_INFO, "#{MessageUtils::SOLUTION}": MessageUtils::SOLUTION_OVERRIDE_NEXT_RUN }) end |
#process_logs(solution, start_date_str, end_date_str) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jfrog/saas/log/collector.rb', line 28 def process_logs(solution, start_date_str, end_date_str) logs = {} dates = CommonUtils.instance.logs_to_process_between(solution, start_date_str, end_date_str) dates.each do |date| CommonUtils.instance.clear_audit_locks(solution, date) logs_to_process = CommonUtils.instance.logs_to_process_hash(solution, date) logs["#{solution}#{CommonUtils::DELIM}#{date}"] = logs_to_process end logs end |