Sha256: d50bb8f2813ac70d27d76c178a53d1250e586eeaa8351566e94b09d2b82e1a0b

Contents?: true

Size: 1.87 KB

Versions: 80

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

module GitlabQuality
  module TestTooling
    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

80 entries across 80 versions & 1 rubygems

Version Path
gitlab_quality-test_tooling-2.8.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-2.7.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-2.6.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-2.5.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-2.4.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-2.3.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-2.2.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-2.1.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-2.0.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-1.39.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-1.38.1 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-1.38.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-1.37.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-1.36.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-1.35.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-1.34.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-1.33.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-1.32.1 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-1.32.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb
gitlab_quality-test_tooling-1.31.0 lib/gitlab_quality/test_tooling/system_logs/system_logs_formatter.rb