diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-09-26 00:38:34 +0300 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-09-26 00:38:34 +0300 |
commit | 1ea2a85cbe61222765dc3ef50e8c0e4c1b2f5bfa (patch) | |
tree | fef18db56829e19fbfcb3405c4dc1763f9f90062 /app/controllers/metrics_controller.rb | |
parent | b83dcd3a30539f86b13d91ffd24fb708652eae80 (diff) |
Make Prometheus metrics endpoint return empty response when metrics are disabled
Diffstat (limited to 'app/controllers/metrics_controller.rb')
-rw-r--r-- | app/controllers/metrics_controller.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/app/controllers/metrics_controller.rb b/app/controllers/metrics_controller.rb index 37587a52eaf..d81ad135198 100644 --- a/app/controllers/metrics_controller.rb +++ b/app/controllers/metrics_controller.rb @@ -3,10 +3,16 @@ class MetricsController < ActionController::Base protect_from_forgery with: :exception - before_action :validate_prometheus_metrics - def index - render text: metrics_service.metrics_text, content_type: 'text/plain; version=0.0.4' + response = if Gitlab::Metrics.prometheus_metrics_enabled? + metrics_service.metrics_text + else + help_page = help_page_url('administration/monitoring/prometheus/gitlab_metrics', + anchor: 'gitlab-prometheus-metrics' + ) + "# Metrics are disabled, see: #{help_page}\n" + end + render text: response, content_type: 'text/plain; version=0.0.4' end private @@ -14,8 +20,4 @@ class MetricsController < ActionController::Base def metrics_service @metrics_service ||= MetricsService.new end - - def validate_prometheus_metrics - render_404 unless Gitlab::Metrics.prometheus_metrics_enabled? - end end |