Commit cdcbeacc authored by Pawel Chojnacki's avatar Pawel Chojnacki

Move prometheus middle ware to prometheus initialized.

parent de2400f6
...@@ -283,7 +283,7 @@ group :metrics do ...@@ -283,7 +283,7 @@ group :metrics do
gem 'influxdb', '~> 0.2', require: false gem 'influxdb', '~> 0.2', require: false
# Prometheus # Prometheus
gem 'prometheus-client-mmap', '~> 0.7.0.beta33' gem 'prometheus-client-mmap', '~> 0.7.0.beta36'
gem 'raindrops', '~> 0.18' gem 'raindrops', '~> 0.18'
end end
......
...@@ -625,7 +625,7 @@ GEM ...@@ -625,7 +625,7 @@ GEM
parser parser
unparser unparser
procto (0.0.3) procto (0.0.3)
prometheus-client-mmap (0.7.0.beta33) prometheus-client-mmap (0.7.0.beta36)
mmap2 (~> 2.2, >= 2.2.9) mmap2 (~> 2.2, >= 2.2.9)
pry (0.10.4) pry (0.10.4)
coderay (~> 1.1.0) coderay (~> 1.1.0)
...@@ -1111,7 +1111,7 @@ DEPENDENCIES ...@@ -1111,7 +1111,7 @@ DEPENDENCIES
peek-sidekiq (~> 1.0.3) peek-sidekiq (~> 1.0.3)
pg (~> 0.18.2) pg (~> 0.18.2)
premailer-rails (~> 1.9.7) premailer-rails (~> 1.9.7)
prometheus-client-mmap (~> 0.7.0.beta33) prometheus-client-mmap (~> 0.7.0.beta36)
pry-byebug (~> 3.4.1) pry-byebug (~> 3.4.1)
pry-rails (~> 0.3.4) pry-rails (~> 0.3.4)
rack-attack (~> 4.4.1) rack-attack (~> 4.4.1)
......
...@@ -361,6 +361,14 @@ ...@@ -361,6 +361,14 @@
%code prometheus_multiproc_dir %code prometheus_multiproc_dir
does not exist or is not pointing to a valid directory. does not exist or is not pointing to a valid directory.
= link_to icon('question-circle'), help_page_path('administration/monitoring/prometheus/gitlab_metrics', anchor: 'metrics-shared-directory') = link_to icon('question-circle'), help_page_path('administration/monitoring/prometheus/gitlab_metrics', anchor: 'metrics-shared-directory')
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :prometheus_metrics_method_instrumentation_enabled do
= f.check_box :prometheus_metrics_method_instrumentation_enabled
Track method execution time.
.help-block
Provides method execution metrics. Can adversely impact GitLab's responsiveness.
%fieldset %fieldset
%legend Profiling - Performance Bar %legend Profiling - Performance Bar
......
...@@ -13,7 +13,6 @@ Prometheus::Client.configure do |config| ...@@ -13,7 +13,6 @@ Prometheus::Client.configure do |config|
config.pid_provider = -> do config.pid_provider = -> do
wid = Prometheus::Client::Support::Unicorn.worker_id wid = Prometheus::Client::Support::Unicorn.worker_id
wid = Process.pid if wid.nil?
if wid.nil? if wid.nil?
"process_pid_#{Process.pid}" "process_pid_#{Process.pid}"
else else
...@@ -22,6 +21,11 @@ Prometheus::Client.configure do |config| ...@@ -22,6 +21,11 @@ Prometheus::Client.configure do |config|
end end
end end
Gitlab::Application.configure do |config|
# 0 should be Sentry to catch errors in this middleware
config.middleware.insert(1, Gitlab::Metrics::RequestsRackMiddleware)
end
Sidekiq.configure_server do |config| Sidekiq.configure_server do |config|
config.on(:startup) do config.on(:startup) do
Gitlab::Metrics::SidekiqMetricsExporter.instance.start Gitlab::Metrics::SidekiqMetricsExporter.instance.start
......
...@@ -118,11 +118,6 @@ def instrument_classes(instrumentation) ...@@ -118,11 +118,6 @@ def instrument_classes(instrumentation)
end end
# rubocop:enable Metrics/AbcSize # rubocop:enable Metrics/AbcSize
Gitlab::Application.configure do |config|
# 0 should be Sentry to catch errors in this middleware
config.middleware.insert(1, Gitlab::Metrics::RequestsRackMiddleware)
end
if Gitlab::Metrics.enabled? if Gitlab::Metrics.enabled?
require 'pathname' require 'pathname'
require 'influxdb' require 'influxdb'
......
class AddPrometheusInstrumentationToApplicationSettings < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_column_with_default(:application_settings, :prometheus_metrics_method_instrumentation_enabled, :boolean,
default: false, allow_null: false)
end
def down
remove_column(:application_settings, :prometheus_metrics_method_instrumentation_enabled)
end
end
...@@ -66,6 +66,9 @@ module API ...@@ -66,6 +66,9 @@ module API
optional :max_pages_size, type: Integer, desc: 'Maximum size of pages in MB' optional :max_pages_size, type: Integer, desc: 'Maximum size of pages in MB'
optional :container_registry_token_expire_delay, type: Integer, desc: 'Authorization token duration (minutes)' optional :container_registry_token_expire_delay, type: Integer, desc: 'Authorization token duration (minutes)'
optional :prometheus_metrics_enabled, type: Boolean, desc: 'Enable Prometheus metrics' optional :prometheus_metrics_enabled, type: Boolean, desc: 'Enable Prometheus metrics'
given prometheus_metrics_enabled: ->(val) { val } do
requires :prometheus_metrics_method_instrumentation_enabled, type: Boolean, desc: 'Enable method call instrumentation'
end
optional :metrics_enabled, type: Boolean, desc: 'Enable the InfluxDB metrics' optional :metrics_enabled, type: Boolean, desc: 'Enable the InfluxDB metrics'
given metrics_enabled: ->(val) { val } do given metrics_enabled: ->(val) { val } do
requires :metrics_host, type: String, desc: 'The InfluxDB host' requires :metrics_host, type: String, desc: 'The InfluxDB host'
......
...@@ -59,8 +59,10 @@ module Gitlab ...@@ -59,8 +59,10 @@ module Gitlab
@cpu_time += cpu_time @cpu_time += cpu_time
@call_count += 1 @call_count += 1
self.class.call_real_duration_histogram.observe(@transaction.labels.merge(labels), real_time / 1000.0) if prometheus_enabled?
self.class.call_cpu_duration_histogram.observe(@transaction.labels.merge(labels), cpu_time / 1000.0) self.class.call_real_duration_histogram.observe(@transaction.labels.merge(labels), real_time / 1000.0)
self.class.call_cpu_duration_histogram.observe(@transaction.labels.merge(labels), cpu_time / 1000.0)
end
retval retval
end end
...@@ -83,6 +85,10 @@ module Gitlab ...@@ -83,6 +85,10 @@ module Gitlab
def above_threshold? def above_threshold?
real_time >= Metrics.method_call_threshold real_time >= Metrics.method_call_threshold
end end
def prometheus_enabled?
@prometheus_enabled ||= current_application_settings(:prometheus_metrics_method_instrumentation_enabled)
end
end end
end end
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