From 85532d490fc113a9a10f030948d93b5cb090926e Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Thu, 15 Jun 2017 23:41:47 +0200 Subject: [PATCH] Do not enable prometheus metrics when data folder is not present. + Set defaults correctly only for when not in production or staging + set ENV['prometheus_multiproc_dir'] in config/boot.rb instead of config.ru --- app/views/admin/application_settings/_form.html.haml | 4 ++++ config.ru | 3 --- config/boot.rb | 5 +++++ lib/gitlab/metrics/prometheus.rb | 6 +++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml index d552704df88056..d30ab0c0eaab6a 100644 --- a/app/views/admin/application_settings/_form.html.haml +++ b/app/views/admin/application_settings/_form.html.haml @@ -310,6 +310,10 @@ = f.label :prometheus_metrics_enabled do = f.check_box :prometheus_metrics_enabled Enable Prometheus Metrics + - if !Gitlab::Metrics.metrics_folder_present? + .help-block + %strong.cred WARNING: + Environment variable `prometheus_multiproc_dir` does not exist or is not pointing to a valid directory. %fieldset %legend Background Jobs diff --git a/config.ru b/config.ru index 89aba462f19619..065ce59932f2ff 100644 --- a/config.ru +++ b/config.ru @@ -15,9 +15,6 @@ if defined?(Unicorn) end end -# set default directory for multiproces metrics gathering -ENV['prometheus_multiproc_dir'] ||= 'tmp/prometheus_multiproc_dir' - require ::File.expand_path('../config/environment', __FILE__) map ENV['RAILS_RELATIVE_URL_ROOT'] || "/" do diff --git a/config/boot.rb b/config/boot.rb index 17a7114837028a..7e8de3b6da3e7e 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -5,6 +5,11 @@ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +# set default directory for multiproces metrics gathering +unless ENV['RAILS_ENV'] == 'production' || ENV['RAILS_ENV'] == 'staging' + ENV['prometheus_multiproc_dir'] ||= 'tmp/prometheus_multiproc_dir' +end + # Default Bootsnap configuration from https://github.com/Shopify/bootsnap#usage require 'bootsnap' Bootsnap.setup( diff --git a/lib/gitlab/metrics/prometheus.rb b/lib/gitlab/metrics/prometheus.rb index 606865093324fe..c7a2ae03508a59 100644 --- a/lib/gitlab/metrics/prometheus.rb +++ b/lib/gitlab/metrics/prometheus.rb @@ -5,8 +5,12 @@ module Metrics module Prometheus include Gitlab::CurrentSettings + def metrics_folder_present? + ENV.has_key?('prometheus_multiproc_dir') && ::Dir.exist?(ENV['prometheus_multiproc_dir']) + end + def prometheus_metrics_enabled? - @prometheus_metrics_enabled ||= current_application_settings[:prometheus_metrics_enabled] || false + @prometheus_metrics_enabled ||= metrics_folder_present? || current_application_settings[:prometheus_metrics_enabled] || false end def registry -- GitLab