diff options
Diffstat (limited to 'qa/qa/support/loglinking.rb')
-rw-r--r-- | qa/qa/support/loglinking.rb | 108 |
1 files changed, 69 insertions, 39 deletions
diff --git a/qa/qa/support/loglinking.rb b/qa/qa/support/loglinking.rb index f24577ff313..5a1aad3c7eb 100644 --- a/qa/qa/support/loglinking.rb +++ b/qa/qa/support/loglinking.rb @@ -1,4 +1,7 @@ # frozen_string_literal: true + +require 'active_support/core_ext/integer/time' + module QA module Support module Loglinking @@ -7,63 +10,90 @@ module QA STAGING_REF_ADDRESS = 'https://staging-ref.gitlab.com' PRODUCTION_ADDRESS = 'https://gitlab.com' PRE_PROD_ADDRESS = 'https://pre.gitlab.com' - SENTRY_ENVIRONMENTS = { + SENTRY_BASE_URLS = { staging: 'https://sentry.gitlab.net/gitlab/staginggitlabcom/?environment=gstg', staging_ref: 'https://sentry.gitlab.net/gitlab/staging-ref/?environment=all', pre: 'https://sentry.gitlab.net/gitlab/pregitlabcom/?environment=all', production: 'https://sentry.gitlab.net/gitlab/gitlabcom/?environment=gprd' }.freeze - KIBANA_ENVIRONMENTS = { + KIBANA_BASE_URLS = { staging: 'https://nonprod-log.gitlab.net/', - canary: 'https://log.gprd.gitlab.net/', - production: 'https://log.gprd.gitlab.net/' + production: 'https://log.gprd.gitlab.net/', + pre: 'https://nonprod-log.gitlab.net/' + }.freeze + KIBANA_INDICES = { + staging: 'ed942d00-5186-11ea-ad8a-f3610a492295', + production: '7092c4e2-4eb5-46f2-8305-a7da2edad090', + pre: 'pubsub-rails-inf-pre' }.freeze - def self.failure_metadata(correlation_id) - return if correlation_id.blank? + class << self + def failure_metadata(correlation_id) + return if correlation_id.blank? - sentry_uri = sentry_url - kibana_uri = kibana_url + errors = ["Correlation Id: #{correlation_id}"] - errors = ["Correlation Id: #{correlation_id}"] - errors << "Sentry Url: #{sentry_uri}&query=correlation_id%3A%22#{correlation_id}%22" if sentry_uri - errors << "Kibana Url: #{kibana_uri}app/discover#/?_a=%28query%3A%28language%3Akuery%2Cquery%3A%27json.correlation_id%20%3A%20#{correlation_id}%27%29%29&_g=%28time%3A%28from%3Anow-24h%2Cto%3Anow%29%29" if kibana_uri + env = get_logging_environment - errors.join("\n") - end + unless env.nil? + sentry_base_url = get_sentry_base_url(env) + kibana_base_url = get_kibana_base_url(env) + kibana_index = get_kibana_index(env) - def self.sentry_url - return unless logging_environment? + errors << "Sentry Url: #{get_sentry_url(sentry_base_url, correlation_id)}" if sentry_base_url + errors << "Kibana Url: #{get_kibana_url(kibana_base_url, kibana_index, correlation_id)}" if kibana_base_url + end - SENTRY_ENVIRONMENTS[logging_environment] - end + errors.join("\n") + end - def self.kibana_url - return unless logging_environment? + def get_sentry_base_url(env) + SENTRY_BASE_URLS[env] + end - KIBANA_ENVIRONMENTS[logging_environment] - end + def get_sentry_url(base_url, correlation_id) + "#{base_url}&query=correlation_id%3A%22#{correlation_id}%22" + end - def self.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 + def get_kibana_base_url(env) + KIBANA_BASE_URLS[env] end - end - def self.logging_environment? - !logging_environment.nil? + def get_kibana_index(env) + KIBANA_INDICES[env] + end + + def get_kibana_url(base_url, index, correlation_id) + "#{base_url}app/discover#/?_a=%28index:%27#{index}%27%2Cquery%3A%28language%3Akuery%2C" \ + "query%3A%27json.correlation_id%20%3A%20#{correlation_id}%27%29%29" \ + "&_g=%28time%3A%28from%3A%27#{start_time}%27%2Cto%3A%27#{end_time}%27%29%29" + end + + def get_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 + + def start_time + (Time.now.utc - 24.hours).iso8601(3) + end + + def end_time + Time.now.utc.iso8601(3) + end end end end |