summaryrefslogtreecommitdiff
path: root/qa/qa/support/loglinking.rb
blob: e9202af3965a20acc287dd96aee1f37a525414ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true

module QA
  module Support
    module Loglinking
      # Static address variables declared for mapping environment to logging URLs
      STAGING_ADDRESS     = 'https://staging.gitlab.com'
      STAGING_REF_ADDRESS = 'https://staging-ref.gitlab.com'
      PRODUCTION_ADDRESS  = 'https://gitlab.com'
      PRE_PROD_ADDRESS    = 'https://pre.gitlab.com'

      class << self
        def failure_metadata(correlation_id)
          return if correlation_id.blank?

          errors = ["Correlation Id: #{correlation_id}"]

          env = logging_environment

          sentry = QA::Support::SystemLogs::Sentry.new(env, correlation_id)
          sentry_url = sentry.url

          kibana = QA::Support::SystemLogs::Kibana.new(env, correlation_id)
          kibana_discover_url = kibana.discover_url
          kibana_dashboard_url = kibana.dashboard_url

          errors << "Sentry Url: #{sentry_url}" if sentry_url
          errors << "Kibana - Discover Url: #{kibana_discover_url}" if kibana_discover_url
          errors << "Kibana - Dashboard Url: #{kibana_dashboard_url}" if kibana_dashboard_url

          errors.join("\n")
        end

        def logging_environment
          address = QA::Runtime::Scenario.attributes[:gitlab_address]
          return if address.nil?

          case address
          when STAGING_ADDRESS
            :staging
          when STAGING_REF_ADDRESS
            :staging_ref
          when PRODUCTION_ADDRESS
            :production
          when PRE_PROD_ADDRESS
            :pre
          else
            nil
          end
        end
      end
    end
  end
end