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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Gitlab::Metrics::LooseForeignKeysSlis do
# This needs to be dynamic because db_config_names depends on
# config/database.yml and the specs need to work for all configurations. That
# means this assertion is a copy of the implementation.
let(:possible_labels) do
::Gitlab::Database.db_config_names.map do |db_config_name|
{
db_config_name: db_config_name,
feature_category: :database
}
end
end
describe '#initialize_slis!' do
it 'initializes Apdex and ErrorRate SLIs for loose_foreign_key_clean_ups' do
expect(::Gitlab::Metrics::Sli::Apdex).to receive(:initialize_sli).with(
:loose_foreign_key_clean_ups,
possible_labels
)
expect(::Gitlab::Metrics::Sli::ErrorRate).to receive(:initialize_sli).with(
:loose_foreign_key_clean_ups,
possible_labels
)
described_class.initialize_slis!
end
end
describe '#record_apdex' do
context 'with success: true' do
it 'increments the loose_foreign_key_clean_ups Apdex as a success' do
expect(Gitlab::Metrics::Sli::Apdex[:loose_foreign_key_clean_ups]).to receive(:increment).with(
labels: { feature_category: :database, db_config_name: 'main' },
success: true
)
described_class.record_apdex(success: true, db_config_name: 'main')
end
end
context 'with success: false' do
it 'increments the loose_foreign_key_clean_ups Apdex as not a success' do
expect(Gitlab::Metrics::Sli::Apdex[:loose_foreign_key_clean_ups]).to receive(:increment).with(
labels: { feature_category: :database, db_config_name: 'main' },
success: false
)
described_class.record_apdex(success: false, db_config_name: 'main')
end
end
end
describe '#record_error_rate' do
context 'with error: true' do
it 'increments the loose_foreign_key_clean_ups ErrorRate as an error' do
expect(Gitlab::Metrics::Sli::ErrorRate[:loose_foreign_key_clean_ups]).to receive(:increment).with(
labels: { feature_category: :database, db_config_name: 'main' },
error: true
)
described_class.record_error_rate(error: true, db_config_name: 'main')
end
end
context 'with error: false' do
it 'increments the loose_foreign_key_clean_ups ErrorRate as not an error' do
expect(Gitlab::Metrics::Sli::ErrorRate[:loose_foreign_key_clean_ups]).to receive(:increment).with(
labels: { feature_category: :database, db_config_name: 'main' },
error: false
)
described_class.record_error_rate(error: false, db_config_name: 'main')
end
end
end
end
|