1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Metrics::RailsSlis, feature_category: :error_budgets do
before do
allow(Gitlab::Graphql::KnownOperations).to receive(:default).and_return(Gitlab::Graphql::KnownOperations.new(%w[foo bar]))
end
describe '.initialize_request_slis!' do
let(:web_possible_labels) do
[
{
endpoint_id: "ProjectsController#index",
feature_category: :groups_and_projects,
request_urgency: :default
}
]
end
# 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
let(:possible_graphql_labels) do
['graphql:foo', 'graphql:bar', 'graphql:unknown'].map do |endpoint_id|
{
endpoint_id: endpoint_id,
feature_category: nil,
query_urgency: ::Gitlab::EndpointAttributes::DEFAULT_URGENCY.name
}
end
end
it "initializes the SLI for all possible endpoints if they weren't", :aggregate_failures do
expect(Gitlab::Metrics::Sli::Apdex).to receive(:initialize_sli).with(:rails_request, array_including(*possible_request_labels)).and_call_original
expect(Gitlab::Metrics::Sli::Apdex).to receive(:initialize_sli).with(:graphql_query, array_including(*possible_graphql_labels)).and_call_original
expect(Gitlab::Metrics::Sli::ErrorRate).to receive(:initialize_sli).with(:rails_request, array_including(*possible_request_labels)).and_call_original
described_class.initialize_request_slis!
end
context "when initializeing for limited types" do
using RSpec::Parameterized::TableSyntax
where(:git, :api, :web) do
[true, false].repeated_permutation(3).to_a
end
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
end
end
describe '.request_apdex' do
it 'returns the initialized request apdex SLI object' do
described_class.initialize_request_slis!
expect(described_class.request_apdex).to be_initialized
end
end
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
describe '.graphql_query_apdex' do
it 'returns the initialized request apdex SLI object' do
described_class.initialize_request_slis!
expect(described_class.graphql_query_apdex).to be_initialized
end
end
end
|