summaryrefslogtreecommitdiff
path: root/qa/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-12-21 03:09:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-12-21 03:09:42 +0000
commit6f2278bd4a548e432b0429a9576ab896460941b2 (patch)
treebde1d0166a3420c820a6a91fdb2fe6258215ce92 /qa/spec
parent7b0db0ccfbec6155d68fc2b7b55a38245f97580c (diff)
downloadgitlab-ce-6f2278bd4a548e432b0429a9576ab896460941b2.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'qa/spec')
-rw-r--r--qa/spec/resource/api_fabricator_spec.rb5
-rw-r--r--qa/spec/support/loglinking_spec.rb129
-rw-r--r--qa/spec/support/system_logs/kibana_spec.rb75
-rw-r--r--qa/spec/support/system_logs/sentry_spec.rb42
4 files changed, 171 insertions, 80 deletions
diff --git a/qa/spec/resource/api_fabricator_spec.rb b/qa/spec/resource/api_fabricator_spec.rb
index 76cc8e0e303..0cec6b2a1ea 100644
--- a/qa/spec/resource/api_fabricator_spec.rb
+++ b/qa/spec/resource/api_fabricator_spec.rb
@@ -125,7 +125,7 @@ RSpec.describe QA::Resource::ApiFabricator do
it 'logs a correlation id' do
response = double('Raw POST response', code: 400, body: post_response.to_json, headers: { x_request_id: 'foobar' })
- allow(QA::Support::Loglinking).to receive(:get_logging_environment).and_return(nil)
+ allow(QA::Support::Loglinking).to receive(:logging_environment).and_return(nil)
expect(api_request).to receive(:new).with(api_client_instance, subject.api_post_path).and_return(double(url: resource_web_url))
expect(subject).to receive(:post).with(resource_web_url, subject.api_post_body).and_return(response)
@@ -157,7 +157,8 @@ RSpec.describe QA::Resource::ApiFabricator do
Fabrication of FooBarResource using the API failed (400) with `#{raw_post}`.
Correlation Id: foobar
Sentry Url: https://sentry.gitlab.net/gitlab/staginggitlabcom/?environment=gstg&query=correlation_id%3A%22foobar%22
- Kibana Url: https://nonprod-log.gitlab.net/app/discover#/?_a=%28index:%27ed942d00-5186-11ea-ad8a-f3610a492295%27%2Cquery%3A%28language%3Akuery%2Cquery%3A%27json.correlation_id%20%3A%20foobar%27%29%29&_g=%28time%3A%28from%3A%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29
+ Kibana - Discover Url: https://nonprod-log.gitlab.net/app/discover#/?_a=%28index:%27ed942d00-5186-11ea-ad8a-f3610a492295%27%2Cquery%3A%28language%3Akuery%2Cquery%3A%27json.correlation_id%20%3A%20foobar%27%29%29&_g=%28time%3A%28from%3A%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29
+ Kibana - Dashboard Url: https://nonprod-log.gitlab.net/app/dashboards#/view/b74dc030-6f56-11ed-9af2-6131f0ee4ce6?_g=%28time%3A%28from:%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29&_a=%28filters%3A%21%28%28query%3A%28match_phrase%3A%28json.correlation_id%3A%27foobar%27%29%29%29%29%29
ERROR
end
end
diff --git a/qa/spec/support/loglinking_spec.rb b/qa/spec/support/loglinking_spec.rb
index 3955d266ef6..79004630253 100644
--- a/qa/spec/support/loglinking_spec.rb
+++ b/qa/spec/support/loglinking_spec.rb
@@ -13,103 +13,76 @@ RSpec.describe QA::Support::Loglinking do
end
context 'when correlation_id exists' do
- context 'and logging environment exists' do
- it 'returns Sentry URL' do
- allow(QA::Support::Loglinking).to receive(:get_logging_environment).and_return(:foo)
- allow(QA::Support::Loglinking).to receive(:get_sentry_base_url).and_return('https://sentry.address/?environment=bar')
- allow(QA::Support::Loglinking).to receive(:get_kibana_base_url).and_return(nil)
- allow(QA::Support::Loglinking).to receive(:get_kibana_index).and_return(nil)
+ let(:correlation_id) { 'foo123' }
+ let(:sentry_url) { "https://sentry.address/?environment=bar&query=correlation_id%3A%22#{correlation_id}%22" }
+ let(:discover_url) { "https://kibana.address/app/discover#/?_a=%28index:%27pubsub-rails-inf-foo%27%2Cquery%3A%28language%3Akuery%2Cquery%3A%27json.correlation_id%20%3A%20#{correlation_id}%27%29%29&_g=%28time%3A%28from%3A%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29" }
+ let(:dashboard_url) { "https://kibana.address/app/dashboards#/view/abc-123-dashboard-id?_g=%28time%3A%28from:%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29&_a=%28filters%3A%21%28%28query%3A%28match_phrase%3A%28json.correlation_id%3A%27#{correlation_id}%27%29%29%29%29%29" }
+
+ before do
+ allow(QA::Support::SystemLogs::Sentry).to receive(:new).and_return(sentry)
+ allow(QA::Support::SystemLogs::Kibana).to receive(:new).and_return(kibana)
+ end
- expect(QA::Support::Loglinking.failure_metadata('foo123')).to eql(<<~ERROR.chomp)
- Correlation Id: foo123
- Sentry Url: https://sentry.address/?environment=bar&query=correlation_id%3A%22foo123%22
- ERROR
+ context 'and both Sentry and Kibana exist for the logging environment' do
+ let(:sentry) { instance_double(QA::Support::SystemLogs::Sentry, url: sentry_url) }
+ let(:kibana) do
+ instance_double(QA::Support::SystemLogs::Kibana,
+ discover_url: discover_url, dashboard_url: dashboard_url)
end
- it 'returns Kibana URL' do
- time = Time.new(2022, 11, 14, 0, 0, 0, '+00:00')
-
- allow(QA::Support::Loglinking).to receive(:get_logging_environment).and_return(:foo)
- allow(QA::Support::Loglinking).to receive(:get_sentry_base_url).and_return(nil)
- allow(QA::Support::Loglinking).to receive(:get_kibana_base_url).and_return('https://kibana.address/')
- allow(QA::Support::Loglinking).to receive(:get_kibana_index).and_return('pubsub-rails-inf-foo')
- allow(Time).to receive(:now).and_return(time)
-
- expect(QA::Support::Loglinking.failure_metadata('foo123')).to eql(<<~ERROR.chomp)
+ it 'returns both Sentry and Kibana URLs' do
+ expect(QA::Support::Loglinking.failure_metadata(correlation_id)).to eql(<<~ERROR.chomp)
Correlation Id: foo123
- Kibana Url: https://kibana.address/app/discover#/?_a=%28index:%27pubsub-rails-inf-foo%27%2Cquery%3A%28language%3Akuery%2Cquery%3A%27json.correlation_id%20%3A%20foo123%27%29%29&_g=%28time%3A%28from%3A%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29
+ Sentry Url: #{sentry_url}
+ Kibana - Discover Url: #{discover_url}
+ Kibana - Dashboard Url: #{dashboard_url}
ERROR
end
end
- context 'and logging environment does not exist' do
- it 'returns only the correlation ID' do
- allow(QA::Support::Loglinking).to receive(:get_logging_environment).and_return(nil)
-
- expect(QA::Support::Loglinking.failure_metadata('foo123')).to eql('Correlation Id: foo123')
+ context 'and only Sentry exists for the logging environment' do
+ let(:sentry) { instance_double(QA::Support::SystemLogs::Sentry, url: sentry_url) }
+ let(:kibana) do
+ instance_double(QA::Support::SystemLogs::Kibana,
+ discover_url: nil, dashboard_url: nil)
end
- end
- end
- end
- describe '.get_sentry_base_url' do
- let(:url_hash) do
- {
- :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',
- :foo => nil,
- nil => nil
- }
- end
-
- it 'returns Sentry base URL based on environment' do
- url_hash.each do |environment, url|
- expect(QA::Support::Loglinking.get_sentry_base_url(environment)).to eq(url)
+ it 'returns only Sentry URL' do
+ expect(QA::Support::Loglinking.failure_metadata(correlation_id)).to eql(<<~ERROR.chomp)
+ Correlation Id: foo123
+ Sentry Url: #{sentry_url}
+ ERROR
+ end
end
- end
- end
- describe '.get_kibana_base_url' do
- let(:url_hash) do
- {
- :staging => 'https://nonprod-log.gitlab.net/',
- :staging_ref => nil,
- :production => 'https://log.gprd.gitlab.net/',
- :pre => 'https://nonprod-log.gitlab.net/',
- :foo => nil,
- nil => nil
- }
- end
+ context 'and only Kibana exists for the logging environment' do
+ let(:sentry) { instance_double(QA::Support::SystemLogs::Sentry, url: nil) }
+ let(:kibana) do
+ instance_double(QA::Support::SystemLogs::Kibana,
+ discover_url: discover_url, dashboard_url: dashboard_url)
+ end
- it 'returns Kibana URL based on environment' do
- url_hash.each do |environment, url|
- expect(QA::Support::Loglinking.get_kibana_base_url(environment)).to eq(url)
+ it 'returns only Kibana Discover and Dashboard URLs' do
+ expect(QA::Support::Loglinking.failure_metadata(correlation_id)).to eql(<<~ERROR.chomp)
+ Correlation Id: foo123
+ Kibana - Discover Url: #{discover_url}
+ Kibana - Dashboard Url: #{dashboard_url}
+ ERROR
+ end
end
- end
- end
- describe '.get_kibana_index' do
- let(:index_hash) do
- {
- :staging => 'ed942d00-5186-11ea-ad8a-f3610a492295',
- :staging_ref => nil,
- :production => '7092c4e2-4eb5-46f2-8305-a7da2edad090',
- :pre => 'pubsub-rails-inf-pre',
- :foo => nil,
- nil => nil
- }
- end
+ context 'and neither Sentry nor Kibana exists for the logging environment' do
+ let(:sentry) { instance_double(QA::Support::SystemLogs::Sentry, url: nil) }
+ let(:kibana) { instance_double(QA::Support::SystemLogs::Kibana, discover_url: nil, dashboard_url: nil) }
- it 'returns Kibana index based on environment' do
- index_hash.each do |environment, index|
- expect(QA::Support::Loglinking.get_kibana_index(environment)).to eq(index)
+ it 'returns only the correlation ID' do
+ expect(QA::Support::Loglinking.failure_metadata(correlation_id)).to eql("Correlation Id: #{correlation_id}")
+ end
end
end
end
- describe '.get_logging_environment' do
+ describe '.logging_environment' do
let(:staging_address) { 'https://staging.gitlab.com' }
let(:staging_ref_address) { 'https://staging-ref.gitlab.com' }
let(:production_address) { 'https://gitlab.com' }
@@ -143,7 +116,7 @@ RSpec.describe QA::Support::Loglinking do
logging_env_array.each do |logging_env_hash|
allow(QA::Runtime::Scenario).to receive(:attributes).and_return({ gitlab_address: logging_env_hash[:address] })
- expect(QA::Support::Loglinking.get_logging_environment).to eq(logging_env_hash[:expected_env])
+ expect(QA::Support::Loglinking.logging_environment).to eq(logging_env_hash[:expected_env])
end
end
end
diff --git a/qa/spec/support/system_logs/kibana_spec.rb b/qa/spec/support/system_logs/kibana_spec.rb
new file mode 100644
index 00000000000..7e13f5a0a06
--- /dev/null
+++ b/qa/spec/support/system_logs/kibana_spec.rb
@@ -0,0 +1,75 @@
+# frozen_string_literal: true
+
+RSpec.describe QA::Support::SystemLogs::Kibana do
+ using RSpec::Parameterized::TableSyntax
+
+ let(:correlation_id) { 'foo123' }
+
+ shared_examples 'returns the expected URL' do
+ where(:env, :expected_url) do
+ :staging | ref(:staging_url)
+ :production | ref(:production_url)
+ :pre | ref(:pre_url)
+ :foo | nil
+ nil | nil
+ end
+
+ with_them do
+ before do
+ allow(Time).to receive(:now).and_return(Time.new(2022, 11, 14, 0, 0, 0, '+00:00'))
+ end
+
+ specify do
+ expect(subject).to eq(expected_url)
+ end
+ end
+ end
+
+ describe '#discover_url' do
+ subject { described_class.new(env, correlation_id).discover_url }
+
+ let(:staging_url) do
+ "https://nonprod-log.gitlab.net/app/discover#/?_a=%28index:%27ed942d00-5186-11ea-ad8a-f3610a492295%27" \
+ "%2Cquery%3A%28language%3Akuery%2Cquery%3A%27json.correlation_id%20%3A%20#{correlation_id}%27%29" \
+ "%29&_g=%28time%3A%28from%3A%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29"
+ end
+
+ let(:production_url) do
+ "https://log.gprd.gitlab.net/app/discover#/?_a=%28index:%277092c4e2-4eb5-46f2-8305-a7da2edad090%27" \
+ "%2Cquery%3A%28language%3Akuery%2Cquery%3A%27json.correlation_id%20%3A%20#{correlation_id}%27%29" \
+ "%29&_g=%28time%3A%28from%3A%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29"
+ end
+
+ let(:pre_url) do
+ "https://nonprod-log.gitlab.net/app/discover#/?_a=%28index:%27pubsub-rails-inf-pre%27" \
+ "%2Cquery%3A%28language%3Akuery%2Cquery%3A%27json.correlation_id%20%3A%20#{correlation_id}%27%29" \
+ "%29&_g=%28time%3A%28from%3A%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29"
+ end
+
+ it_behaves_like 'returns the expected URL'
+ end
+
+ describe '#dashboard_url' do
+ subject { described_class.new(env, correlation_id).dashboard_url }
+
+ let(:staging_url) do
+ "https://nonprod-log.gitlab.net/app/dashboards#/view/b74dc030-6f56-11ed-9af2-6131f0ee4ce6?_g=%28time" \
+ "%3A%28from:%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29&_a=%28filters%3A%21" \
+ "%28%28query%3A%28match_phrase%3A%28json.correlation_id%3A%27#{correlation_id}%27%29%29%29%29%29"
+ end
+
+ let(:production_url) do
+ "https://log.gprd.gitlab.net/app/dashboards#/view/5e6d3440-7597-11ed-9f43-e3784d7fe3ca?_g=%28time" \
+ "%3A%28from:%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29&_a=%28filters%3A%21" \
+ "%28%28query%3A%28match_phrase%3A%28json.correlation_id%3A%27#{correlation_id}%27%29%29%29%29%29"
+ end
+
+ let(:pre_url) do
+ "https://nonprod-log.gitlab.net/app/dashboards#/view/15596340-7570-11ed-9af2-6131f0ee4ce6?_g=%28time" \
+ "%3A%28from:%272022-11-13T00:00:00.000Z%27%2Cto%3A%272022-11-14T00:00:00.000Z%27%29%29&_a=%28filters%3A%21" \
+ "%28%28query%3A%28match_phrase%3A%28json.correlation_id%3A%27#{correlation_id}%27%29%29%29%29%29"
+ end
+
+ it_behaves_like 'returns the expected URL'
+ end
+end
diff --git a/qa/spec/support/system_logs/sentry_spec.rb b/qa/spec/support/system_logs/sentry_spec.rb
new file mode 100644
index 00000000000..6821c527b23
--- /dev/null
+++ b/qa/spec/support/system_logs/sentry_spec.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+RSpec.describe QA::Support::SystemLogs::Sentry do
+ using RSpec::Parameterized::TableSyntax
+
+ let(:correlation_id) { 'foo123' }
+
+ describe '#url' do
+ subject { described_class.new(env, correlation_id).url }
+
+ let(:staging_url) do
+ "https://sentry.gitlab.net/gitlab/staginggitlabcom/?environment=gstg&query=correlation_id%3A%22#{correlation_id}%22"
+ end
+
+ let(:staging_ref_url) do
+ "https://sentry.gitlab.net/gitlab/staging-ref/?environment=all&query=correlation_id%3A%22#{correlation_id}%22"
+ end
+
+ let(:pre_url) do
+ "https://sentry.gitlab.net/gitlab/pregitlabcom/?environment=all&query=correlation_id%3A%22#{correlation_id}%22"
+ end
+
+ let(:production_url) do
+ "https://sentry.gitlab.net/gitlab/gitlabcom/?environment=gprd&query=correlation_id%3A%22#{correlation_id}%22"
+ end
+
+ where(:env, :expected_url) do
+ :staging | ref(:staging_url)
+ :staging_ref | ref(:staging_ref_url)
+ :production | ref(:production_url)
+ :pre | ref(:pre_url)
+ :foo | nil
+ nil | nil
+ end
+
+ with_them do
+ it 'returns the expected URL' do
+ expect(subject).to eq(expected_url)
+ end
+ end
+ end
+end