2021-11-18 22:05:49 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Gitlab::Metrics::RailsSlis do
|
|
|
|
# Limit what routes we'll initialize so we don't have to load the entire thing
|
|
|
|
before do
|
|
|
|
api_route = API::API.routes.find do |route|
|
|
|
|
API::Base.endpoint_id_for_route(route) == "GET /api/:version/version"
|
|
|
|
end
|
|
|
|
|
|
|
|
allow(Gitlab::RequestEndpoints).to receive(:all_api_endpoints).and_return([api_route])
|
|
|
|
allow(Gitlab::RequestEndpoints).to receive(:all_controller_actions).and_return([[ProjectsController, 'show']])
|
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
|
2021-12-11 22:18:48 +05:30
|
|
|
it "initializes the SLI for all possible endpoints if they weren't", :aggregate_failures do
|
2021-11-18 22:05:49 +05:30
|
|
|
possible_labels = [
|
|
|
|
{
|
|
|
|
endpoint_id: "GET /api/:version/version",
|
2021-12-11 22:18:48 +05:30
|
|
|
feature_category: :not_owned,
|
|
|
|
request_urgency: :default
|
2021-11-18 22:05:49 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
endpoint_id: "ProjectsController#show",
|
2021-12-11 22:18:48 +05:30
|
|
|
feature_category: :projects,
|
|
|
|
request_urgency: :default
|
2021-11-18 22:05:49 +05:30
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
possible_graphql_labels = ['graphql:foo', 'graphql:bar', 'graphql:unknown', 'graphql:anonymous'].map do |endpoint_id|
|
|
|
|
{
|
|
|
|
endpoint_id: endpoint_id,
|
|
|
|
feature_category: nil,
|
|
|
|
query_urgency: ::Gitlab::EndpointAttributes::DEFAULT_URGENCY.name
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(Gitlab::Metrics::Sli).to receive(:initialized?).with(:rails_request_apdex) { false }
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(Gitlab::Metrics::Sli).to receive(:initialized?).with(:graphql_query_apdex) { false }
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(Gitlab::Metrics::Sli).to receive(:initialize_sli).with(:rails_request_apdex, array_including(*possible_labels)).and_call_original
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(Gitlab::Metrics::Sli).to receive(:initialize_sli).with(:graphql_query_apdex, array_including(*possible_graphql_labels)).and_call_original
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
described_class.initialize_request_slis!
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it 'does not initialize the SLI if they were initialized already', :aggregate_failures do
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(Gitlab::Metrics::Sli).to receive(:initialized?).with(:rails_request_apdex) { true }
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(Gitlab::Metrics::Sli).to receive(:initialized?).with(:graphql_query_apdex) { true }
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(Gitlab::Metrics::Sli).not_to receive(:initialize_sli)
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
described_class.initialize_request_slis!
|
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
|
|
|
|
|
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
|