diff options
Diffstat (limited to 'spec/lib/gitlab/metrics')
-rw-r--r-- | spec/lib/gitlab/metrics/global_search_slis_spec.rb | 129 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/system_spec.rb | 67 |
2 files changed, 114 insertions, 82 deletions
diff --git a/spec/lib/gitlab/metrics/global_search_slis_spec.rb b/spec/lib/gitlab/metrics/global_search_slis_spec.rb index 28496eff2fc..0c09cf6dd71 100644 --- a/spec/lib/gitlab/metrics/global_search_slis_spec.rb +++ b/spec/lib/gitlab/metrics/global_search_slis_spec.rb @@ -5,26 +5,20 @@ require 'spec_helper' RSpec.describe Gitlab::Metrics::GlobalSearchSlis do using RSpec::Parameterized::TableSyntax - let(:apdex_feature_flag_enabled) { true } let(:error_rate_feature_flag_enabled) { true } before do - stub_feature_flags(global_search_custom_slis: apdex_feature_flag_enabled) stub_feature_flags(global_search_error_rate_sli: error_rate_feature_flag_enabled) end describe '#initialize_slis!' do - context 'when global_search_custom_slis feature flag is enabled' do - let(:apdex_feature_flag_enabled) { true } + it 'initializes Apdex SLIs for global_search' do + expect(Gitlab::Metrics::Sli::Apdex).to receive(:initialize_sli).with( + :global_search, + a_kind_of(Array) + ) - it 'initializes Apdex SLIs for global_search' do - expect(Gitlab::Metrics::Sli::Apdex).to receive(:initialize_sli).with( - :global_search, - a_kind_of(Array) - ) - - described_class.initialize_slis! - end + described_class.initialize_slis! end context 'when global_search_error_rate_sli feature flag is enabled' do @@ -40,16 +34,6 @@ RSpec.describe Gitlab::Metrics::GlobalSearchSlis do end end - context 'when global_search_custom_slis feature flag is disabled' do - let(:apdex_feature_flag_enabled) { false } - - it 'does not initialize the Apdex SLIs for global_search' do - expect(Gitlab::Metrics::Sli::Apdex).not_to receive(:initialize_sli) - - described_class.initialize_slis! - end - end - context 'when global_search_error_rate_sli feature flag is disabled' do let(:error_rate_feature_flag_enabled) { false } @@ -62,78 +46,59 @@ RSpec.describe Gitlab::Metrics::GlobalSearchSlis do end describe '#record_apdex' do - context 'when global_search_custom_slis feature flag is enabled' do - let(:apdex_feature_flag_enabled) { true } - - where(:search_type, :code_search, :duration_target) do - 'basic' | false | 7.031 - 'basic' | true | 21.903 - 'advanced' | false | 4.865 - 'advanced' | true | 13.546 - end - - with_them do - before do - allow(::Gitlab::ApplicationContext).to receive(:current_context_attribute).with(:caller_id).and_return('end') - end + where(:search_type, :code_search, :duration_target) do + 'basic' | false | 7.031 + 'basic' | true | 21.903 + 'advanced' | false | 4.865 + 'advanced' | true | 13.546 + end - let(:search_scope) { code_search ? 'blobs' : 'issues' } + with_them do + before do + allow(::Gitlab::ApplicationContext).to receive(:current_context_attribute).with(:caller_id).and_return('end') + end - it 'increments the global_search SLI as a success if the elapsed time is within the target' do - duration = duration_target - 0.1 + let(:search_scope) { code_search ? 'blobs' : 'issues' } - 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: true - ) + it 'increments the global_search SLI as a success if the elapsed time is within the target' do + duration = duration_target - 0.1 - described_class.record_apdex( - elapsed: duration, - search_type: search_type, - search_level: 'global', - search_scope: search_scope - ) - end - - it 'increments the global_search SLI as a failure if the elapsed time is not within the target' do - duration = duration_target + 0.1 - - 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 - ) - - described_class.record_apdex( - elapsed: duration, + expect(Gitlab::Metrics::Sli::Apdex[:global_search]).to receive(:increment).with( + labels: { search_type: search_type, search_level: 'global', - search_scope: search_scope - ) - end + 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 + ) end - end - context 'when global_search_custom_slis feature flag is disabled' do - let(:apdex_feature_flag_enabled) { false } + it 'increments the global_search SLI as a failure if the elapsed time is not within the target' do + duration = duration_target + 0.1 - it 'does not call increment on the apdex SLI' do - expect(Gitlab::Metrics::Sli::Apdex[:global_search]).not_to receive(:increment) + 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 + ) described_class.record_apdex( - elapsed: 1, - search_type: 'basic', + elapsed: duration, + search_type: search_type, search_level: 'global', - search_scope: 'issues' + search_scope: search_scope ) end end diff --git a/spec/lib/gitlab/metrics/system_spec.rb b/spec/lib/gitlab/metrics/system_spec.rb index 7739501dd95..b86469eacd1 100644 --- a/spec/lib/gitlab/metrics/system_spec.rb +++ b/spec/lib/gitlab/metrics/system_spec.rb @@ -71,6 +71,65 @@ RSpec.describe Gitlab::Metrics::System do SNIP end + let(:mem_info) do + # full snapshot + <<~SNIP + MemTotal: 15362536 kB + MemFree: 3403136 kB + MemAvailable: 13044528 kB + Buffers: 272188 kB + Cached: 8171312 kB + SwapCached: 0 kB + Active: 3332084 kB + Inactive: 6981076 kB + Active(anon): 1603868 kB + Inactive(anon): 9044 kB + Active(file): 1728216 kB + Inactive(file): 6972032 kB + Unevictable: 18676 kB + Mlocked: 18676 kB + SwapTotal: 0 kB + SwapFree: 0 kB + Dirty: 6808 kB + Writeback: 0 kB + AnonPages: 1888300 kB + Mapped: 166164 kB + Shmem: 12932 kB + KReclaimable: 1275120 kB + Slab: 1495480 kB + SReclaimable: 1275120 kB + SUnreclaim: 220360 kB + KernelStack: 7072 kB + PageTables: 11936 kB + NFS_Unstable: 0 kB + Bounce: 0 kB + WritebackTmp: 0 kB + CommitLimit: 7681268 kB + Committed_AS: 4976100 kB + VmallocTotal: 34359738367 kB + VmallocUsed: 25532 kB + VmallocChunk: 0 kB + Percpu: 23200 kB + HardwareCorrupted: 0 kB + AnonHugePages: 202752 kB + ShmemHugePages: 0 kB + ShmemPmdMapped: 0 kB + FileHugePages: 0 kB + FilePmdMapped: 0 kB + CmaTotal: 0 kB + CmaFree: 0 kB + HugePages_Total: 0 + HugePages_Free: 0 + HugePages_Rsvd: 0 + HugePages_Surp: 0 + Hugepagesize: 2048 kB + Hugetlb: 0 kB + DirectMap4k: 4637504 kB + DirectMap2M: 11087872 kB + DirectMap1G: 2097152 kB + SNIP + end + describe '.memory_usage_rss' do context 'without PID' do it "returns the current process' resident set size (RSS) in bytes" do @@ -125,6 +184,14 @@ RSpec.describe Gitlab::Metrics::System do end end + describe '.memory_total' do + it "returns the current process' resident set size (RSS) in bytes" do + mock_existing_proc_file('/proc/meminfo', mem_info) + + expect(described_class.memory_total).to eq(15731236864) + end + end + describe '.process_runtime_elapsed_seconds' do it 'returns the seconds elapsed since the process was started' do # sets process starttime ticks to 1000 |