debian-mirror-gitlab/qa/spec/support/loglinking_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

124 lines
4.9 KiB
Ruby
Raw Normal View History

2022-05-07 20:08:51 +05:30
# frozen_string_literal: true
RSpec.describe QA::Support::Loglinking do
describe '.failure_metadata' do
2023-03-04 22:38:38 +05:30
context 'when correlation_id does not exist' do
it 'returns nil when correlation_id is empty' do
2022-05-07 20:08:51 +05:30
expect(QA::Support::Loglinking.failure_metadata('')).to eq(nil)
end
2022-08-27 11:52:29 +05:30
2023-03-04 22:38:38 +05:30
it 'returns nil when correlation_id is nil' do
2022-05-07 20:08:51 +05:30
expect(QA::Support::Loglinking.failure_metadata(nil)).to eq(nil)
end
end
2023-03-04 22:38:38 +05:30
context 'when correlation_id exists' do
2023-03-17 16:20:25 +05:30
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
2022-05-07 20:08:51 +05:30
2023-03-17 16:20:25 +05:30
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)
2023-03-04 22:38:38 +05:30
end
2023-03-17 16:20:25 +05:30
it 'returns both Sentry and Kibana URLs' do
expect(QA::Support::Loglinking.failure_metadata(correlation_id)).to eql(<<~ERROR.chomp)
2022-05-07 20:08:51 +05:30
Correlation Id: foo123
2023-03-17 16:20:25 +05:30
Sentry Url: #{sentry_url}
Kibana - Discover Url: #{discover_url}
Kibana - Dashboard Url: #{dashboard_url}
2023-03-04 22:38:38 +05:30
ERROR
end
end
2023-03-17 16:20:25 +05:30
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)
2023-03-04 22:38:38 +05:30
end
2022-05-07 20:08:51 +05:30
2023-03-17 16:20:25 +05:30
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
2022-05-07 20:08:51 +05:30
end
2023-03-17 16:20:25 +05:30
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
2022-05-07 20:08:51 +05:30
2023-03-17 16:20:25 +05:30
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
2023-03-04 22:38:38 +05:30
end
2023-03-17 16:20:25 +05:30
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) }
2022-05-07 20:08:51 +05:30
2023-03-17 16:20:25 +05:30
it 'returns only the correlation ID' do
expect(QA::Support::Loglinking.failure_metadata(correlation_id)).to eql("Correlation Id: #{correlation_id}")
end
2022-05-07 20:08:51 +05:30
end
end
end
2023-03-17 16:20:25 +05:30
describe '.logging_environment' do
2022-05-07 20:08:51 +05:30
let(:staging_address) { 'https://staging.gitlab.com' }
let(:staging_ref_address) { 'https://staging-ref.gitlab.com' }
2022-06-21 17:19:12 +05:30
let(:production_address) { 'https://gitlab.com' }
2022-05-07 20:08:51 +05:30
let(:pre_prod_address) { 'https://pre.gitlab.com' }
let(:logging_env_array) do
[
{
address: staging_address,
expected_env: :staging
},
{
address: staging_ref_address,
expected_env: :staging_ref
},
{
address: production_address,
expected_env: :production
},
{
address: pre_prod_address,
expected_env: :pre
},
{
address: 'https://foo.com',
expected_env: nil
}
]
end
it 'returns logging environment if environment found' do
logging_env_array.each do |logging_env_hash|
allow(QA::Runtime::Scenario).to receive(:attributes).and_return({ gitlab_address: logging_env_hash[:address] })
2023-03-17 16:20:25 +05:30
expect(QA::Support::Loglinking.logging_environment).to eq(logging_env_hash[:expected_env])
2022-05-07 20:08:51 +05:30
end
end
end
end