Skip to content

Commit ee22a47

Browse files
committed
Update prometheus-client-mmap gem to highly optimized version
+ change string concatenation to help with GC pressure. + fix metric producing incompatible label sets
1 parent 83e623f commit ee22a47

File tree

4 files changed

+6
-15
lines changed

4 files changed

+6
-15
lines changed

Gemfile.lock

+1-3
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ GEM
486486
mini_mime (0.1.4)
487487
mini_portile2 (2.3.0)
488488
minitest (5.7.0)
489-
mmap2 (2.2.9)
490489
mousetrap-rails (1.4.6)
491490
multi_json (1.12.2)
492491
multi_xml (0.6.0)
@@ -623,8 +622,7 @@ GEM
623622
parser
624623
unparser
625624
procto (0.0.3)
626-
prometheus-client-mmap (0.7.0.beta39)
627-
mmap2 (~> 2.2, >= 2.2.9)
625+
prometheus-client-mmap (0.7.0.beta43)
628626
pry (0.10.4)
629627
coderay (~> 1.1.0)
630628
method_source (~> 0.8.1)

app/services/metrics_service.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def health_metrics_text
2020
end
2121

2222
def metrics_text
23-
"#{health_metrics_text}#{prometheus_metrics_text}"
23+
prometheus_metrics_text.concat(health_metrics_text)
2424
end
2525

2626
private

config/initializers/7_prometheus_metrics.rb

+1-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@
1111
config.multiprocess_files_dir ||= Rails.root.join('tmp/prometheus_multiproc_dir')
1212
end
1313

14-
config.pid_provider = -> do
15-
worker_id = Prometheus::Client::Support::Unicorn.worker_id
16-
if worker_id.nil?
17-
"process_pid_#{Process.pid}"
18-
else
19-
"worker_id_#{worker_id}"
20-
end
21-
end
14+
config.pid_provider = Prometheus::Client::Support::Unicorn.method(:worker_pid_provider)
2215
end
2316

2417
Gitlab::Application.configure do |config|

lib/gitlab/metrics/samplers/ruby_sampler.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def initialize(interval)
3232

3333
def init_metrics
3434
metrics = {}
35-
metrics[:sampler_duration] = Metrics.histogram(with_prefix(:sampler_duration, :seconds), 'Sampler time', {})
35+
metrics[:sampler_duration] = Metrics.histogram(with_prefix(:sampler_duration, :seconds), 'Sampler time', { worker: nil })
3636
metrics[:total_time] = Metrics.gauge(with_prefix(:gc, :time_total), 'Total GC time', labels, :livesum)
3737
GC.stat.keys.each do |key|
3838
metrics[key] = Metrics.gauge(with_prefix(:gc, key), to_doc_string(key), labels, :livesum)
@@ -100,9 +100,9 @@ def worker_label
100100
worker_no = ::Prometheus::Client::Support::Unicorn.worker_id
101101

102102
if worker_no
103-
{ unicorn: worker_no }
103+
{ worker: worker_no }
104104
else
105-
{ unicorn: 'master' }
105+
{ worker: 'master' }
106106
end
107107
end
108108
end

0 commit comments

Comments
 (0)