From de2400f6404476e82d95f7cc6cd1fc26779c147b Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Tue, 21 Nov 2017 18:59:14 +0100 Subject: Update prometheus-client-gem to 0.7.0.beta33 --- Gemfile | 2 +- Gemfile.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 6034323956c..af8b7287627 100644 --- a/Gemfile +++ b/Gemfile @@ -283,7 +283,7 @@ group :metrics do gem 'influxdb', '~> 0.2', require: false # Prometheus - gem 'prometheus-client-mmap', '~>0.7.0.beta18' + gem 'prometheus-client-mmap', '~> 0.7.0.beta33' gem 'raindrops', '~> 0.18' end diff --git a/Gemfile.lock b/Gemfile.lock index 4787be92365..3d18ee1ba44 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -488,7 +488,7 @@ GEM mini_mime (0.1.4) mini_portile2 (2.3.0) minitest (5.7.0) - mmap2 (2.2.7) + mmap2 (2.2.9) mousetrap-rails (1.4.6) multi_json (1.12.2) multi_xml (0.6.0) @@ -625,8 +625,8 @@ GEM parser unparser procto (0.0.3) - prometheus-client-mmap (0.7.0.beta18) - mmap2 (~> 2.2, >= 2.2.7) + prometheus-client-mmap (0.7.0.beta33) + mmap2 (~> 2.2, >= 2.2.9) pry (0.10.4) coderay (~> 1.1.0) method_source (~> 0.8.1) @@ -1111,7 +1111,7 @@ DEPENDENCIES peek-sidekiq (~> 1.0.3) pg (~> 0.18.2) premailer-rails (~> 1.9.7) - prometheus-client-mmap (~> 0.7.0.beta18) + prometheus-client-mmap (~> 0.7.0.beta33) pry-byebug (~> 3.4.1) pry-rails (~> 0.3.4) rack-attack (~> 4.4.1) -- cgit v1.2.1 From cdcbeaccbec09fefe81b7b90badacf5308751ce9 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Thu, 23 Nov 2017 00:26:50 +0100 Subject: Move prometheus middle ware to prometheus initialized. --- Gemfile | 2 +- Gemfile.lock | 4 ++-- app/views/admin/application_settings/_form.html.haml | 8 ++++++++ config/initializers/7_prometheus_metrics.rb | 6 +++++- config/initializers/8_metrics.rb | 5 ----- ...prometheus_instrumentation_to_application_settings.rb | 16 ++++++++++++++++ lib/api/settings.rb | 3 +++ lib/gitlab/metrics/method_call.rb | 10 ++++++++-- 8 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb diff --git a/Gemfile b/Gemfile index af8b7287627..53820459a16 100644 --- a/Gemfile +++ b/Gemfile @@ -283,7 +283,7 @@ group :metrics do gem 'influxdb', '~> 0.2', require: false # Prometheus - gem 'prometheus-client-mmap', '~> 0.7.0.beta33' + gem 'prometheus-client-mmap', '~> 0.7.0.beta36' gem 'raindrops', '~> 0.18' end diff --git a/Gemfile.lock b/Gemfile.lock index 3d18ee1ba44..69d20bdbbb3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -625,7 +625,7 @@ GEM parser unparser procto (0.0.3) - prometheus-client-mmap (0.7.0.beta33) + prometheus-client-mmap (0.7.0.beta36) mmap2 (~> 2.2, >= 2.2.9) pry (0.10.4) coderay (~> 1.1.0) @@ -1111,7 +1111,7 @@ DEPENDENCIES peek-sidekiq (~> 1.0.3) pg (~> 0.18.2) 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-rails (~> 0.3.4) rack-attack (~> 4.4.1) diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml index 12658dddc06..0037d547855 100644 --- a/app/views/admin/application_settings/_form.html.haml +++ b/app/views/admin/application_settings/_form.html.haml @@ -361,6 +361,14 @@ %code prometheus_multiproc_dir 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') + .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 %legend Profiling - Performance Bar diff --git a/config/initializers/7_prometheus_metrics.rb b/config/initializers/7_prometheus_metrics.rb index e8f33593fe0..a9138db585f 100644 --- a/config/initializers/7_prometheus_metrics.rb +++ b/config/initializers/7_prometheus_metrics.rb @@ -13,7 +13,6 @@ Prometheus::Client.configure do |config| config.pid_provider = -> do wid = Prometheus::Client::Support::Unicorn.worker_id - wid = Process.pid if wid.nil? if wid.nil? "process_pid_#{Process.pid}" else @@ -22,6 +21,11 @@ Prometheus::Client.configure do |config| 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| config.on(:startup) do Gitlab::Metrics::SidekiqMetricsExporter.instance.start diff --git a/config/initializers/8_metrics.rb b/config/initializers/8_metrics.rb index 7ef594836d6..45b39b2a38d 100644 --- a/config/initializers/8_metrics.rb +++ b/config/initializers/8_metrics.rb @@ -118,11 +118,6 @@ def instrument_classes(instrumentation) end # 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? require 'pathname' require 'influxdb' diff --git a/db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb b/db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb new file mode 100644 index 00000000000..9a07d1b281c --- /dev/null +++ b/db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb @@ -0,0 +1,16 @@ +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 + diff --git a/lib/api/settings.rb b/lib/api/settings.rb index 851b226e9e5..a43f8d0497c 100644 --- a/lib/api/settings.rb +++ b/lib/api/settings.rb @@ -66,6 +66,9 @@ module API 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 :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' given metrics_enabled: ->(val) { val } do requires :metrics_host, type: String, desc: 'The InfluxDB host' diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb index 90235095306..5177d953795 100644 --- a/lib/gitlab/metrics/method_call.rb +++ b/lib/gitlab/metrics/method_call.rb @@ -59,8 +59,10 @@ module Gitlab @cpu_time += cpu_time @call_count += 1 - 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) + if prometheus_enabled? + 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 end @@ -83,6 +85,10 @@ module Gitlab def above_threshold? real_time >= Metrics.method_call_threshold end + + def prometheus_enabled? + @prometheus_enabled ||= current_application_settings(:prometheus_metrics_method_instrumentation_enabled) + end end end end -- cgit v1.2.1 From 9884c0f4a0ea634fe08235ef0a0c7f997f19a782 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Thu, 23 Nov 2017 00:37:55 +0100 Subject: Reenable prometheus metrics --- lib/gitlab/metrics/prometheus.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/gitlab/metrics/prometheus.rb b/lib/gitlab/metrics/prometheus.rb index 4f165d12a94..09103b4ca2d 100644 --- a/lib/gitlab/metrics/prometheus.rb +++ b/lib/gitlab/metrics/prometheus.rb @@ -17,9 +17,9 @@ module Gitlab end def prometheus_metrics_enabled? - # force disable prometheus_metrics until - # https://gitlab.com/gitlab-org/prometheus-client-mmap/merge_requests/11 is ready - false + return @prometheus_metrics_enabled if defined?(@prometheus_metrics_enabled) + + @prometheus_metrics_enabled = prometheus_metrics_enabled_unmemoized end def registry -- cgit v1.2.1 From 84c5260f1240ebbe3aa136473324474b0cc0eb8a Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Thu, 23 Nov 2017 00:53:10 +0100 Subject: Add changelog for #15558 --- .../pawel-update_prometheus_gem_to_well_tested_version.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/unreleased/pawel-update_prometheus_gem_to_well_tested_version.yml diff --git a/changelogs/unreleased/pawel-update_prometheus_gem_to_well_tested_version.yml b/changelogs/unreleased/pawel-update_prometheus_gem_to_well_tested_version.yml new file mode 100644 index 00000000000..a4133ae5cec --- /dev/null +++ b/changelogs/unreleased/pawel-update_prometheus_gem_to_well_tested_version.yml @@ -0,0 +1,5 @@ +--- +title: Reenable Prometheus metrics, add more control over Prometheus method instrumentation +merge_request: 15558 +author: +type: fixed -- cgit v1.2.1 From efe4cab92b1c93b2beb75fc6b4c0dbe0787d301e Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Thu, 23 Nov 2017 01:25:45 +0100 Subject: check method timing threshold when observing method performance --- lib/gitlab/metrics/method_call.rb | 4 +- spec/lib/gitlab/metrics/method_call_spec.rb | 65 +++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb index 5177d953795..03bdb5885a8 100644 --- a/lib/gitlab/metrics/method_call.rb +++ b/lib/gitlab/metrics/method_call.rb @@ -59,7 +59,7 @@ module Gitlab @cpu_time += cpu_time @call_count += 1 - if prometheus_enabled? + if prometheus_enabled? && above_threshold? 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 @@ -87,7 +87,7 @@ module Gitlab end def prometheus_enabled? - @prometheus_enabled ||= current_application_settings(:prometheus_metrics_method_instrumentation_enabled) + @prometheus_enabled ||= Gitlab::CurrentSettings.current_application_settings[:prometheus_metrics_method_instrumentation_enabled] end end end diff --git a/spec/lib/gitlab/metrics/method_call_spec.rb b/spec/lib/gitlab/metrics/method_call_spec.rb index f1e9e414e0d..cffd061a54d 100644 --- a/spec/lib/gitlab/metrics/method_call_spec.rb +++ b/spec/lib/gitlab/metrics/method_call_spec.rb @@ -13,16 +13,65 @@ describe Gitlab::Metrics::MethodCall do expect(method_call.call_count).to eq(1) end - it 'observes the performance of the supplied block' do - expect(described_class.call_real_duration_histogram) - .to receive(:observe) - .with({ module: :Foo, method: '#bar' }, be_a_kind_of(Numeric)) + context 'when measurement is above threshold' do + before do + allow(method_call).to receive(:above_threshold?).and_return(true) + end - expect(described_class.call_cpu_duration_histogram) - .to receive(:observe) - .with({ module: :Foo, method: '#bar' }, be_a_kind_of(Numeric)) + context 'prometheus instrumentation is enabled' do + before do + allow(Gitlab::CurrentSettings).to receive(:current_application_settings) + .and_return(prometheus_metrics_method_instrumentation_enabled: true) + end - method_call.measure { 'foo' } + it 'observes the performance of the supplied block' do + expect(described_class.call_real_duration_histogram) + .to receive(:observe) + .with({ module: :Foo, method: '#bar' }, be_a_kind_of(Numeric)) + + expect(described_class.call_cpu_duration_histogram) + .to receive(:observe) + .with({ module: :Foo, method: '#bar' }, be_a_kind_of(Numeric)) + + method_call.measure { 'foo' } + end + end + + context 'prometheus instrumentation is disabled' do + before do + allow(Gitlab::CurrentSettings).to receive(:current_application_settings) + .and_return(prometheus_metrics_method_instrumentation_enabled: false) + end + + it 'does not observe the performance' do + expect(described_class.call_real_duration_histogram) + .not_to receive(:observe) + + expect(described_class.call_cpu_duration_histogram) + .not_to receive(:observe) + + method_call.measure { 'foo' } + end + end + end + + context 'when measurement is below threshold' do + before do + allow(method_call).to receive(:above_threshold?).and_return(false) + + allow(Gitlab::CurrentSettings).to receive(:current_application_settings) + .and_return(prometheus_metrics_method_instrumentation_enabled: true) + end + + it 'does not observe the performance' do + expect(described_class.call_real_duration_histogram) + .not_to receive(:observe) + + expect(described_class.call_cpu_duration_histogram) + .not_to receive(:observe) + + method_call.measure { 'foo' } + end end end -- cgit v1.2.1 From 0051b5fbcc3154dacf20b1e89387b9ea55827266 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Thu, 23 Nov 2017 15:28:37 +0100 Subject: Use only real duration to measure method call performance via Prometheus --- ...heus_instrumentation_to_application_settings.rb | 1 - lib/gitlab/metrics/method_call.rb | 27 +++++----------------- spec/lib/gitlab/metrics/method_call_spec.rb | 22 ++++++++---------- 3 files changed, 15 insertions(+), 35 deletions(-) diff --git a/db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb b/db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb index 9a07d1b281c..c25646ead9d 100644 --- a/db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb +++ b/db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb @@ -13,4 +13,3 @@ class AddPrometheusInstrumentationToApplicationSettings < ActiveRecord::Migratio remove_column(:application_settings, :prometheus_metrics_method_instrumentation_enabled) end end - diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb index 03bdb5885a8..518aefa19ee 100644 --- a/lib/gitlab/metrics/method_call.rb +++ b/lib/gitlab/metrics/method_call.rb @@ -6,29 +6,15 @@ module Gitlab BASE_LABELS = { module: nil, method: nil }.freeze attr_reader :real_time, :cpu_time, :call_count, :labels - def self.call_real_duration_histogram - return @call_real_duration_histogram if @call_real_duration_histogram - - MUTEX.synchronize do - @call_real_duration_histogram ||= Gitlab::Metrics.histogram( - :gitlab_method_call_real_duration_seconds, - 'Method calls real duration', - Transaction::BASE_LABELS.merge(BASE_LABELS), - [0.1, 0.2, 0.5, 1, 2, 5, 10] - ) - end - end - - def self.call_cpu_duration_histogram - return @call_cpu_duration_histogram if @call_cpu_duration_histogram + def self.call_duration_histogram + return @call_duration_histogram if @call_duration_histogram MUTEX.synchronize do @call_duration_histogram ||= Gitlab::Metrics.histogram( - :gitlab_method_call_cpu_duration_seconds, - 'Method calls cpu duration', + :gitlab_method_call_duration_seconds, + 'Method calls real duration', Transaction::BASE_LABELS.merge(BASE_LABELS), - [0.1, 0.2, 0.5, 1, 2, 5, 10] - ) + [0.01, 0.05, 0.1, 0.5, 1]) end end @@ -60,8 +46,7 @@ module Gitlab @call_count += 1 if prometheus_enabled? && above_threshold? - 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) + self.class.call_duration_histogram.observe(@transaction.labels.merge(labels), real_time / 1000.0) end retval diff --git a/spec/lib/gitlab/metrics/method_call_spec.rb b/spec/lib/gitlab/metrics/method_call_spec.rb index cffd061a54d..b20c9e227d6 100644 --- a/spec/lib/gitlab/metrics/method_call_spec.rb +++ b/spec/lib/gitlab/metrics/method_call_spec.rb @@ -25,11 +25,7 @@ describe Gitlab::Metrics::MethodCall do end it 'observes the performance of the supplied block' do - expect(described_class.call_real_duration_histogram) - .to receive(:observe) - .with({ module: :Foo, method: '#bar' }, be_a_kind_of(Numeric)) - - expect(described_class.call_cpu_duration_histogram) + expect(described_class.call_duration_histogram) .to receive(:observe) .with({ module: :Foo, method: '#bar' }, be_a_kind_of(Numeric)) @@ -44,10 +40,7 @@ describe Gitlab::Metrics::MethodCall do end it 'does not observe the performance' do - expect(described_class.call_real_duration_histogram) - .not_to receive(:observe) - - expect(described_class.call_cpu_duration_histogram) + expect(described_class.call_duration_histogram) .not_to receive(:observe) method_call.measure { 'foo' } @@ -64,10 +57,7 @@ describe Gitlab::Metrics::MethodCall do end it 'does not observe the performance' do - expect(described_class.call_real_duration_histogram) - .not_to receive(:observe) - - expect(described_class.call_cpu_duration_histogram) + expect(described_class.call_duration_histogram) .not_to receive(:observe) method_call.measure { 'foo' } @@ -92,7 +82,13 @@ describe Gitlab::Metrics::MethodCall do end describe '#above_threshold?' do + before do + allow(Gitlab::Metrics).to receive(:method_call_threshold).and_return(100) + end + it 'returns false when the total call time is not above the threshold' do + expect(method_call).to receive(:real_time).and_return(9) + expect(method_call.above_threshold?).to eq(false) end -- cgit v1.2.1 From ad185e623b282f622ca3ea983840eed44a664fcb Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Thu, 23 Nov 2017 20:21:51 +0100 Subject: add missing schema entry and application settigns helper --- app/helpers/application_settings_helper.rb | 1 + db/schema.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index e5d2693b01e..f776cd31438 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -211,6 +211,7 @@ module ApplicationSettingsHelper :polling_interval_multiplier, :project_export_enabled, :prometheus_metrics_enabled, + :prometheus_metrics_method_instrumentation_enabled, :recaptcha_enabled, :recaptcha_private_key, :recaptcha_site_key, diff --git a/db/schema.rb b/db/schema.rb index a82270390f1..48afc475209 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171121144800) do +ActiveRecord::Schema.define(version: 20171122211913) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -149,6 +149,7 @@ ActiveRecord::Schema.define(version: 20171121144800) do t.boolean "throttle_authenticated_web_enabled", default: false, null: false t.integer "throttle_authenticated_web_requests_per_period", default: 7200, null: false t.integer "throttle_authenticated_web_period_in_seconds", default: 3600, null: false + t.boolean "prometheus_metrics_method_instrumentation_enabled", default: false, null: false end create_table "audit_events", force: :cascade do |t| -- cgit v1.2.1 From 0ae2d9e68df24f5aeda56e8fb934aa980a3b76c2 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Thu, 23 Nov 2017 23:10:38 +0100 Subject: Rename wip to worker_id --- config/initializers/7_prometheus_metrics.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/initializers/7_prometheus_metrics.rb b/config/initializers/7_prometheus_metrics.rb index a9138db585f..43b1e943897 100644 --- a/config/initializers/7_prometheus_metrics.rb +++ b/config/initializers/7_prometheus_metrics.rb @@ -12,11 +12,11 @@ Prometheus::Client.configure do |config| end config.pid_provider = -> do - wid = Prometheus::Client::Support::Unicorn.worker_id - if wid.nil? + worker_id = Prometheus::Client::Support::Unicorn.worker_id + if worker_id.nil? "process_pid_#{Process.pid}" else - "worker_id_#{wid}" + "worker_id_#{worker_id}" end end end -- cgit v1.2.1 From 46cd2d93bb23807b76bf20bb06e6ef93f1985ad9 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Thu, 23 Nov 2017 23:30:57 +0100 Subject: Use feature flag instead of application settigns to control if method calls should be instrumented --- app/helpers/application_settings_helper.rb | 1 - app/views/admin/application_settings/_form.html.haml | 8 -------- ..._prometheus_instrumentation_to_application_settings.rb | 15 --------------- db/schema.rb | 3 +-- lib/api/settings.rb | 3 --- lib/gitlab/metrics/method_call.rb | 6 +++--- spec/lib/gitlab/metrics/method_call_spec.rb | 9 +++------ 7 files changed, 7 insertions(+), 38 deletions(-) delete mode 100644 db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index f776cd31438..e5d2693b01e 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -211,7 +211,6 @@ module ApplicationSettingsHelper :polling_interval_multiplier, :project_export_enabled, :prometheus_metrics_enabled, - :prometheus_metrics_method_instrumentation_enabled, :recaptcha_enabled, :recaptcha_private_key, :recaptcha_site_key, diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml index 0037d547855..12658dddc06 100644 --- a/app/views/admin/application_settings/_form.html.haml +++ b/app/views/admin/application_settings/_form.html.haml @@ -361,14 +361,6 @@ %code prometheus_multiproc_dir 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') - .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 %legend Profiling - Performance Bar diff --git a/db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb b/db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb deleted file mode 100644 index c25646ead9d..00000000000 --- a/db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb +++ /dev/null @@ -1,15 +0,0 @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 48afc475209..a82270390f1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171122211913) do +ActiveRecord::Schema.define(version: 20171121144800) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -149,7 +149,6 @@ ActiveRecord::Schema.define(version: 20171122211913) do t.boolean "throttle_authenticated_web_enabled", default: false, null: false t.integer "throttle_authenticated_web_requests_per_period", default: 7200, null: false t.integer "throttle_authenticated_web_period_in_seconds", default: 3600, null: false - t.boolean "prometheus_metrics_method_instrumentation_enabled", default: false, null: false end create_table "audit_events", force: :cascade do |t| diff --git a/lib/api/settings.rb b/lib/api/settings.rb index a43f8d0497c..851b226e9e5 100644 --- a/lib/api/settings.rb +++ b/lib/api/settings.rb @@ -66,9 +66,6 @@ module API 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 :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' given metrics_enabled: ->(val) { val } do requires :metrics_host, type: String, desc: 'The InfluxDB host' diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb index 518aefa19ee..65d55576ac2 100644 --- a/lib/gitlab/metrics/method_call.rb +++ b/lib/gitlab/metrics/method_call.rb @@ -45,7 +45,7 @@ module Gitlab @cpu_time += cpu_time @call_count += 1 - if prometheus_enabled? && above_threshold? + if call_measurement_enabled? && above_threshold? self.class.call_duration_histogram.observe(@transaction.labels.merge(labels), real_time / 1000.0) end @@ -71,8 +71,8 @@ module Gitlab real_time >= Metrics.method_call_threshold end - def prometheus_enabled? - @prometheus_enabled ||= Gitlab::CurrentSettings.current_application_settings[:prometheus_metrics_method_instrumentation_enabled] + def call_measurement_enabled? + Feature.get(:prometheus_metrics_method_instrumentation).enabled? end end end diff --git a/spec/lib/gitlab/metrics/method_call_spec.rb b/spec/lib/gitlab/metrics/method_call_spec.rb index b20c9e227d6..5341addf911 100644 --- a/spec/lib/gitlab/metrics/method_call_spec.rb +++ b/spec/lib/gitlab/metrics/method_call_spec.rb @@ -20,8 +20,7 @@ describe Gitlab::Metrics::MethodCall do context 'prometheus instrumentation is enabled' do before do - allow(Gitlab::CurrentSettings).to receive(:current_application_settings) - .and_return(prometheus_metrics_method_instrumentation_enabled: true) + Feature.get(:prometheus_metrics_method_instrumentation).enable end it 'observes the performance of the supplied block' do @@ -35,8 +34,7 @@ describe Gitlab::Metrics::MethodCall do context 'prometheus instrumentation is disabled' do before do - allow(Gitlab::CurrentSettings).to receive(:current_application_settings) - .and_return(prometheus_metrics_method_instrumentation_enabled: false) + Feature.get(:prometheus_metrics_method_instrumentation).disable end it 'does not observe the performance' do @@ -52,8 +50,7 @@ describe Gitlab::Metrics::MethodCall do before do allow(method_call).to receive(:above_threshold?).and_return(false) - allow(Gitlab::CurrentSettings).to receive(:current_application_settings) - .and_return(prometheus_metrics_method_instrumentation_enabled: true) + Feature.get(:prometheus_metrics_method_instrumentation).enable end it 'does not observe the performance' do -- cgit v1.2.1