Commit b933db38 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '216584-drop-ruby-memory-bytes' into 'master'

Drop redundant `memory_bytes` metrics from ruby_sampler

Closes #216584

See merge request gitlab-org/gitlab!31705
parents 745293e9 307ad060
---
title: Remove ruby_memory_bytes metric, duplicate of ruby_process_resident_memory_bytes
merge_request: 31705
author:
type: removed
......@@ -183,7 +183,6 @@ Some basic Ruby runtime metrics are available:
| `ruby_gc_duration_seconds` | Counter | 11.1 | Time spent by Ruby in GC |
| `ruby_gc_stat_...` | Gauge | 11.1 | Various metrics from [GC.stat](https://ruby-doc.org/core-2.6.5/GC.html#method-c-stat) |
| `ruby_file_descriptors` | Gauge | 11.1 | File descriptors per process |
| `ruby_memory_bytes` | Gauge | 11.1 | Memory usage by process |
| `ruby_sampler_duration_seconds` | Counter | 11.1 | Time spent collecting stats |
| `ruby_process_cpu_seconds_total` | Gauge | 12.0 | Total amount of CPU time per process |
| `ruby_process_max_fds` | Gauge | 12.0 | Maximum number of open file descriptors per process |
......
......@@ -31,7 +31,7 @@ module Gitlab
end
def sample_memory_usage
add_metric('memory_usage', value: System.memory_usage)
add_metric('memory_usage', value: System.memory_usage_rss)
end
def sample_file_descriptors
......
......@@ -35,7 +35,6 @@ module Gitlab
def init_metrics
metrics = {
file_descriptors: ::Gitlab::Metrics.gauge(with_prefix(:file, :descriptors), 'File descriptors used', labels),
memory_bytes: ::Gitlab::Metrics.gauge(with_prefix(:memory, :bytes), 'Memory used (RSS)', labels),
process_cpu_seconds_total: ::Gitlab::Metrics.gauge(with_prefix(:process, :cpu_seconds_total), 'Process CPU seconds total'),
process_max_fds: ::Gitlab::Metrics.gauge(with_prefix(:process, :max_fds), 'Process max fds'),
process_resident_memory_bytes: ::Gitlab::Metrics.gauge(with_prefix(:process, :resident_memory_bytes), 'Memory used (RSS)', labels),
......@@ -87,9 +86,7 @@ module Gitlab
end
def set_memory_usage_metrics
memory_rss = System.memory_usage
metrics[:memory_bytes].set(labels, memory_rss)
metrics[:process_resident_memory_bytes].set(labels, memory_rss)
metrics[:process_resident_memory_bytes].set(labels, System.memory_usage_rss)
if Gitlab::Utils.to_boolean(ENV['enable_memory_uss_pss'])
memory_uss_pss = System.memory_usage_uss_pss
......
......@@ -18,7 +18,7 @@ module Gitlab
MAX_OPEN_FILES_PATTERN = /Max open files\s*(?<value>\d+)/.freeze
# Returns the current process' RSS (resident set size) in bytes.
def self.memory_usage
def self.memory_usage_rss
sum_matches(PROC_STATUS_PATH, rss: RSS_PATTERN)[:rss].kilobytes
end
......
......@@ -55,13 +55,13 @@ module Gitlab
def run
Thread.current[THREAD_KEY] = self
@memory_before = System.memory_usage
@memory_before = System.memory_usage_rss
@started_at = System.monotonic_time
@thread_cputime_start = System.thread_cpu_time
yield
ensure
@memory_after = System.memory_usage
@memory_after = System.memory_usage_rss
@finished_at = System.monotonic_time
self.class.gitlab_transaction_cputime_seconds.observe(labels, thread_cpu_duration)
......
......@@ -36,7 +36,7 @@ module Gitlab
gc_stats: gc_stats,
time_to_finish: time_to_finish,
number_of_sql_calls: sql_calls_count,
memory_usage: "#{Gitlab::Metrics::System.memory_usage.to_f / 1024 / 1024} MiB",
memory_usage: "#{Gitlab::Metrics::System.memory_usage_rss.to_f / 1024 / 1024} MiB",
label: ::Prometheus::PidProvider.worker_id
)
......
......@@ -37,7 +37,7 @@ describe Gitlab::Metrics::Samplers::InfluxSampler do
describe '#sample_memory_usage' do
it 'adds a metric containing the memory usage' do
expect(Gitlab::Metrics::System).to receive(:memory_usage)
expect(Gitlab::Metrics::System).to receive(:memory_usage_rss)
.and_return(9000)
expect(sampler).to receive(:add_metric)
......
......@@ -21,7 +21,7 @@ describe Gitlab::Metrics::Samplers::RubySampler do
describe '#sample' do
it 'adds a metric containing the process resident memory bytes' do
expect(Gitlab::Metrics::System).to receive(:memory_usage).and_return(9000)
expect(Gitlab::Metrics::System).to receive(:memory_usage_rss).and_return(9000)
expect(sampler.metrics[:process_resident_memory_bytes]).to receive(:set).with({}, 9000)
......
......@@ -64,11 +64,11 @@ describe Gitlab::Metrics::System do
SNIP
end
describe '.memory_usage' do
describe '.memory_usage_rss' do
it "returns the process' resident set size (RSS) in bytes" do
mock_existing_proc_file('/proc/self/status', proc_status)
expect(described_class.memory_usage).to eq(2527232)
expect(described_class.memory_usage_rss).to eq(2527232)
end
end
......@@ -103,9 +103,9 @@ describe Gitlab::Metrics::System do
mock_missing_proc_file
end
describe '.memory_usage' do
describe '.memory_usage_rss' do
it 'returns 0' do
expect(described_class.memory_usage).to eq(0)
expect(described_class.memory_usage_rss).to eq(0)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment