Sha256: 5960451912009896af68e945c55a84394546ea9a4e413bf7b146fe983edee261

Contents?: true

Size: 1.85 KB

Versions: 10

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

module Gitlab
  module QA
    module SystemLogs
      class SystemLogsFormatter
        NUM_OF_LOG_SECTIONS = 4

        def initialize(base_paths, correlation_id)
          @base_paths = base_paths
          @correlation_id = correlation_id
        end

        def system_logs_summary_markdown
          log_sections = Array.new(NUM_OF_LOG_SECTIONS) { [] }

          @base_paths.each do |base_path|
            all_logs = [
              Finders::Rails::ApiLogFinder.new(base_path).find(@correlation_id),
              Finders::Rails::ExceptionLogFinder.new(base_path).find(@correlation_id),
              Finders::Rails::ApplicationLogFinder.new(base_path).find(@correlation_id),
              Finders::Rails::GraphqlLogFinder.new(base_path).find(@correlation_id)
            ]

            create_log_summary_sections!(all_logs, log_sections)
          end

          log_sections.prepend('### System Logs') unless log_sections.all?(&:empty?)
          log_sections.join("\n").rstrip
        end

        private

        def create_log_summary_sections!(all_logs, sections)
          sections.zip(all_logs) do |section, logs|
            unless logs.empty?
              section_title = "\n#### #{logs.first.name}"
              section.append(section_title) unless section.include?(section_title)
              section.append(create_log_summaries(logs))
            end
          end
        end

        def create_log_summaries(logs)
          section = []

          logs.each do |log|
            log_summary = <<~MARKDOWN.chomp
              <details><summary>Click to expand</summary>

              ```json
              #{JSON.pretty_generate(log.summary)}
              ```
              </details>
            MARKDOWN

            section.append(log_summary)
          end

          section.join("\n\n")
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gitlab-qa-10.3.0.1 lib/gitlab/qa/system_logs/system_logs_formatter.rb
gitlab-qa-10.6.0 lib/gitlab/qa/system_logs/system_logs_formatter.rb
gitlab-qa-10.5.0 lib/gitlab/qa/system_logs/system_logs_formatter.rb
gitlab-qa-10.4.1 lib/gitlab/qa/system_logs/system_logs_formatter.rb
gitlab-qa-10.4.0 lib/gitlab/qa/system_logs/system_logs_formatter.rb
gitlab-qa-10.3.0 lib/gitlab/qa/system_logs/system_logs_formatter.rb
gitlab-qa-10.2.2 lib/gitlab/qa/system_logs/system_logs_formatter.rb
gitlab-qa-10.2.1 lib/gitlab/qa/system_logs/system_logs_formatter.rb
gitlab-qa-10.2.0 lib/gitlab/qa/system_logs/system_logs_formatter.rb
gitlab-qa-10.1.0 lib/gitlab/qa/system_logs/system_logs_formatter.rb