debian-mirror-gitlab/spec/lib/gitlab/metrics/global_search_slis_spec.rb

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

161 lines
5.1 KiB
Ruby
Raw Normal View History

2022-10-11 01:57:18 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Metrics::GlobalSearchSlis do
using RSpec::Parameterized::TableSyntax
describe '#initialize_slis!' do
2023-04-23 21:23:45 +05:30
let(:api_endpoint_labels) do
[a_hash_including(endpoint_id: 'GET /api/:version/search')]
end
let(:web_endpoint_labels) do
[a_hash_including(endpoint_id: "SearchController#show")]
end
let(:all_endpoint_labels) do
api_endpoint_labels + web_endpoint_labels
end
2022-11-25 23:54:43 +05:30
it 'initializes Apdex SLIs for global_search' do
expect(Gitlab::Metrics::Sli::Apdex).to receive(:initialize_sli).with(
:global_search,
2023-04-23 21:23:45 +05:30
array_including(all_endpoint_labels)
2022-11-25 23:54:43 +05:30
)
2022-10-11 01:57:18 +05:30
2022-11-25 23:54:43 +05:30
described_class.initialize_slis!
2022-10-11 01:57:18 +05:30
end
2023-03-04 22:38:38 +05:30
it 'initializes ErrorRate SLIs for global_search' do
expect(Gitlab::Metrics::Sli::ErrorRate).to receive(:initialize_sli).with(
:global_search,
2023-04-23 21:23:45 +05:30
array_including(all_endpoint_labels)
2023-03-04 22:38:38 +05:30
)
2022-10-11 01:57:18 +05:30
2023-03-04 22:38:38 +05:30
described_class.initialize_slis!
2022-10-11 01:57:18 +05:30
end
2023-04-23 21:23:45 +05:30
context "when initializeing for limited types" do
where(:api, :web) do
[true, false].repeated_permutation(2).to_a
end
with_them do
it 'only initializes for the relevant endpoints', :aggregate_failures do
allow(Gitlab::Metrics::Environment).to receive(:api?).and_return(api)
allow(Gitlab::Metrics::Environment).to receive(:web?).and_return(web)
allow(Gitlab::Metrics::Sli::Apdex).to receive(:initialize_sli)
allow(Gitlab::Metrics::Sli::ErrorRate).to receive(:initialize_sli)
described_class.initialize_slis!
if api
expect(Gitlab::Metrics::Sli::Apdex).to(
have_received(:initialize_sli).with(:global_search, array_including(*api_endpoint_labels))
)
expect(Gitlab::Metrics::Sli::ErrorRate).to(
have_received(:initialize_sli).with(:global_search, array_including(*api_endpoint_labels))
)
else
expect(Gitlab::Metrics::Sli::Apdex).not_to(
have_received(:initialize_sli).with(:global_search, array_including(*api_endpoint_labels))
)
expect(Gitlab::Metrics::Sli::ErrorRate).not_to(
have_received(:initialize_sli).with(:global_search, array_including(*api_endpoint_labels))
)
end
if web
expect(Gitlab::Metrics::Sli::Apdex).to(
have_received(:initialize_sli).with(:global_search, array_including(*web_endpoint_labels))
)
expect(Gitlab::Metrics::Sli::ErrorRate).to(
have_received(:initialize_sli).with(:global_search, array_including(*web_endpoint_labels))
)
else
expect(Gitlab::Metrics::Sli::Apdex).not_to(
have_received(:initialize_sli).with(:global_search, array_including(*web_endpoint_labels))
)
expect(Gitlab::Metrics::Sli::ErrorRate).not_to(
have_received(:initialize_sli).with(:global_search, array_including(*web_endpoint_labels))
)
end
end
end
end
2022-10-11 01:57:18 +05:30
end
describe '#record_apdex' do
2022-11-25 23:54:43 +05:30
where(:search_type, :code_search, :duration_target) do
2023-01-13 00:05:48 +05:30
'basic' | false | 8.812
'basic' | true | 27.538
'advanced' | false | 2.452
'advanced' | true | 15.52
2022-11-25 23:54:43 +05:30
end
2022-10-11 01:57:18 +05:30
2022-11-25 23:54:43 +05:30
with_them do
before do
allow(::Gitlab::ApplicationContext).to receive(:current_context_attribute).with(:caller_id).and_return('end')
end
2022-10-11 01:57:18 +05:30
2022-11-25 23:54:43 +05:30
let(:search_scope) { code_search ? 'blobs' : 'issues' }
2022-10-11 01:57:18 +05:30
2022-11-25 23:54:43 +05:30
it 'increments the global_search SLI as a success if the elapsed time is within the target' do
duration = duration_target - 0.1
2022-10-11 01:57:18 +05:30
2022-11-25 23:54:43 +05:30
expect(Gitlab::Metrics::Sli::Apdex[:global_search]).to receive(:increment).with(
labels: {
2022-10-11 01:57:18 +05:30
search_type: search_type,
search_level: 'global',
2022-11-25 23:54:43 +05:30
search_scope: search_scope,
endpoint_id: 'end'
},
success: true
)
described_class.record_apdex(
elapsed: duration,
search_type: search_type,
search_level: 'global',
search_scope: search_scope
)
2022-10-11 01:57:18 +05:30
end
2022-11-25 23:54:43 +05:30
it 'increments the global_search SLI as a failure if the elapsed time is not within the target' do
duration = duration_target + 0.1
2022-10-11 01:57:18 +05:30
2022-11-25 23:54:43 +05:30
expect(Gitlab::Metrics::Sli::Apdex[:global_search]).to receive(:increment).with(
labels: {
search_type: search_type,
search_level: 'global',
search_scope: search_scope,
endpoint_id: 'end'
},
success: false
)
2022-10-11 01:57:18 +05:30
described_class.record_apdex(
2022-11-25 23:54:43 +05:30
elapsed: duration,
search_type: search_type,
2022-10-11 01:57:18 +05:30
search_level: 'global',
2022-11-25 23:54:43 +05:30
search_scope: search_scope
2022-10-11 01:57:18 +05:30
)
end
end
end
describe '#record_error_rate' do
2023-03-04 22:38:38 +05:30
it 'calls increment on the error rate SLI' do
expect(Gitlab::Metrics::Sli::ErrorRate[:global_search]).to receive(:increment)
described_class.record_error_rate(
error: true,
search_type: 'basic',
search_level: 'global',
search_scope: 'issues'
)
2022-10-11 01:57:18 +05:30
end
end
end