blob: 67d185fd2f104d7eb961fb11644cd728256fff5a (
plain)
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
|
# frozen_string_literal: true
require 'fast_spec_helper'
require 'prometheus/client'
require 'support/shared_examples/lib/gitlab/memory/watchdog/monitor_result_shared_examples'
RSpec.describe Gitlab::Memory::Watchdog::Monitor::RssMemoryLimit, feature_category: :application_performance do
let(:max_rss_limit_gauge) { instance_double(::Prometheus::Client::Gauge) }
let(:memory_limit_bytes) { 2_097_152_000 }
let(:worker_memory_bytes) { 1_048_576_000 }
subject(:monitor) do
described_class.new(memory_limit_bytes: memory_limit_bytes)
end
before do
allow(Gitlab::Metrics).to receive(:gauge)
.with(:gitlab_memwd_max_memory_limit, anything)
.and_return(max_rss_limit_gauge)
allow(max_rss_limit_gauge).to receive(:set)
allow(Gitlab::Metrics::System).to receive(:memory_usage_rss).and_return({ total: worker_memory_bytes })
end
describe '#initialize' do
it 'sets the max rss limit gauge' do
expect(max_rss_limit_gauge).to receive(:set).with({}, memory_limit_bytes)
monitor
end
end
describe '#call' do
context 'when process exceeds threshold' do
let(:worker_memory_bytes) { memory_limit_bytes + 1 }
let(:payload) do
{
message: 'rss memory limit exceeded',
memwd_rss_bytes: worker_memory_bytes,
memwd_max_rss_bytes: memory_limit_bytes
}
end
include_examples 'returns Watchdog Monitor result', threshold_violated: true
end
context 'when process does not exceed threshold' do
let(:worker_memory_bytes) { memory_limit_bytes - 1 }
let(:payload) { {} }
include_examples 'returns Watchdog Monitor result', threshold_violated: false
end
end
end
|