2021-11-18 22:05:49 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
RSpec.describe Gitlab::Metrics::RailsSlis, feature_category: :error_budgets do
|
2021-11-18 22:05:49 +05:30
|
|
|
before do
|
2021-12-11 22:18:48 +05:30
|
|
|
allow(Gitlab::Graphql::KnownOperations).to receive(:default).and_return(Gitlab::Graphql::KnownOperations.new(%w(foo bar)))
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
describe '.initialize_request_slis!' do
|
2023-04-23 21:23:45 +05:30
|
|
|
let(:web_possible_labels) do
|
2023-03-04 22:38:38 +05:30
|
|
|
[
|
2021-11-18 22:05:49 +05:30
|
|
|
{
|
2022-06-21 17:19:12 +05:30
|
|
|
endpoint_id: "ProjectsController#index",
|
2021-12-11 22:18:48 +05:30
|
|
|
feature_category: :projects,
|
|
|
|
request_urgency: :default
|
2021-11-18 22:05:49 +05:30
|
|
|
}
|
|
|
|
]
|
2023-03-04 22:38:38 +05:30
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
# using the actual `#known_git_endpoints` here makes sure that we keep the
|
|
|
|
# list up to date as endpoints get removed
|
|
|
|
let(:git_possible_labels) do
|
|
|
|
described_class.__send__(:known_git_endpoints).map do |endpoint_id|
|
|
|
|
a_hash_including({
|
|
|
|
endpoint_id: endpoint_id
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:api_possible_labels) do
|
|
|
|
[{
|
|
|
|
endpoint_id: "GET /api/:version/version",
|
|
|
|
feature_category: :not_owned,
|
|
|
|
request_urgency: :default
|
|
|
|
}]
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:possible_request_labels) do
|
|
|
|
web_possible_labels + git_possible_labels + api_possible_labels
|
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
let(:possible_graphql_labels) do
|
|
|
|
['graphql:foo', 'graphql:bar', 'graphql:unknown'].map do |endpoint_id|
|
2021-12-11 22:18:48 +05:30
|
|
|
{
|
|
|
|
endpoint_id: endpoint_id,
|
|
|
|
feature_category: nil,
|
|
|
|
query_urgency: ::Gitlab::EndpointAttributes::DEFAULT_URGENCY.name
|
|
|
|
}
|
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "initializes the SLI for all possible endpoints if they weren't", :aggregate_failures do
|
2023-04-23 21:23:45 +05:30
|
|
|
expect(Gitlab::Metrics::Sli::Apdex).to receive(:initialize_sli).with(:rails_request, array_including(*possible_request_labels)).and_call_original
|
2023-03-04 22:38:38 +05:30
|
|
|
expect(Gitlab::Metrics::Sli::Apdex).to receive(:initialize_sli).with(:graphql_query, array_including(*possible_graphql_labels)).and_call_original
|
2023-04-23 21:23:45 +05:30
|
|
|
expect(Gitlab::Metrics::Sli::ErrorRate).to receive(:initialize_sli).with(:rails_request, array_including(*possible_request_labels)).and_call_original
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
described_class.initialize_request_slis!
|
|
|
|
end
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
context "when initializeing for limited types" do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
where(:git, :api, :web) do
|
|
|
|
[true, false].repeated_permutation(3).to_a
|
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
with_them do
|
|
|
|
it 'initializes only with the expected labels', :aggregate_failures do
|
|
|
|
allow(Gitlab::Metrics::Environment).to receive(:git?).and_return(git)
|
|
|
|
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_request_slis!
|
|
|
|
|
|
|
|
if git
|
|
|
|
expect(Gitlab::Metrics::Sli::Apdex).to have_received(:initialize_sli).with(:rails_request, array_including(*git_possible_labels))
|
|
|
|
expect(Gitlab::Metrics::Sli::ErrorRate).to have_received(:initialize_sli).with(:rails_request, array_including(*git_possible_labels))
|
|
|
|
else
|
|
|
|
expect(Gitlab::Metrics::Sli::Apdex).not_to have_received(:initialize_sli).with(:rails_request, array_including(*git_possible_labels))
|
|
|
|
expect(Gitlab::Metrics::Sli::ErrorRate).not_to have_received(:initialize_sli).with(:rails_request, array_including(*git_possible_labels))
|
|
|
|
end
|
|
|
|
|
|
|
|
if api
|
|
|
|
expect(Gitlab::Metrics::Sli::Apdex).to have_received(:initialize_sli).with(:rails_request, array_including(*api_possible_labels))
|
|
|
|
expect(Gitlab::Metrics::Sli::ErrorRate).to have_received(:initialize_sli).with(:rails_request, array_including(*api_possible_labels))
|
|
|
|
expect(Gitlab::Metrics::Sli::Apdex).to have_received(:initialize_sli).with(:graphql_query, array_including(*possible_graphql_labels))
|
|
|
|
else
|
|
|
|
expect(Gitlab::Metrics::Sli::Apdex).not_to have_received(:initialize_sli).with(:rails_request, array_including(*api_possible_labels))
|
|
|
|
expect(Gitlab::Metrics::Sli::ErrorRate).not_to have_received(:initialize_sli).with(:rails_request, array_including(*api_possible_labels))
|
|
|
|
expect(Gitlab::Metrics::Sli::Apdex).to have_received(:initialize_sli).with(:graphql_query, [])
|
|
|
|
end
|
|
|
|
|
|
|
|
if web
|
|
|
|
expect(Gitlab::Metrics::Sli::Apdex).to have_received(:initialize_sli).with(:rails_request, array_including(*web_possible_labels))
|
|
|
|
expect(Gitlab::Metrics::Sli::ErrorRate).to have_received(:initialize_sli).with(:rails_request, array_including(*web_possible_labels))
|
|
|
|
else
|
|
|
|
expect(Gitlab::Metrics::Sli::Apdex).not_to have_received(:initialize_sli).with(:rails_request, array_including(*web_possible_labels))
|
|
|
|
expect(Gitlab::Metrics::Sli::ErrorRate).not_to have_received(:initialize_sli).with(:rails_request, array_including(*web_possible_labels))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
2021-12-11 22:18:48 +05:30
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
describe '.request_apdex' do
|
|
|
|
it 'returns the initialized request apdex SLI object' do
|
2022-04-04 11:22:00 +05:30
|
|
|
described_class.initialize_request_slis!
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
expect(described_class.request_apdex).to be_initialized
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
describe '.request_error' do
|
|
|
|
it 'returns the initialized request error rate SLI object' do
|
|
|
|
described_class.initialize_request_slis!
|
|
|
|
|
|
|
|
expect(described_class.request_error_rate).to be_initialized
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
describe '.graphql_query_apdex' do
|
2021-11-18 22:05:49 +05:30
|
|
|
it 'returns the initialized request apdex SLI object' do
|
2022-04-04 11:22:00 +05:30
|
|
|
described_class.initialize_request_slis!
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(described_class.graphql_query_apdex).to be_initialized
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|