From 1ea2a85cbe61222765dc3ef50e8c0e4c1b2f5bfa Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Mon, 25 Sep 2017 23:38:34 +0200 Subject: [PATCH 1/2] Make Prometheus metrics endpoint return empty response when metrics are disabled --- app/controllers/metrics_controller.rb | 16 +++++++++------- spec/controllers/metrics_controller_spec.rb | 3 ++- 2 files changed, 11 insertions(+), 8 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 diff --git a/spec/controllers/metrics_controller_spec.rb b/spec/controllers/metrics_controller_spec.rb index 7b0976e3e67..d6f68b73428 100644 --- a/spec/controllers/metrics_controller_spec.rb +++ b/spec/controllers/metrics_controller_spec.rb @@ -78,7 +78,8 @@ describe MetricsController do it 'returns proper response' do get :index - expect(response.status).to eq(404) + expect(response.status).to eq(200) + expect(response.body).to eq("# Metrics are disabled, see: http://test.host/help/administration/monitoring/prometheus/gitlab_metrics#gitlab-prometheus-metrics\n") end end end From 05f41253a9fb1ae88ecc53a1ceade780d1cfe0d4 Mon Sep 17 00:00:00 2001 From: Pawel Chojnacki Date: Mon, 6 Nov 2017 15:43:38 +0100 Subject: [PATCH 2/2] Add Changelog --- ...empty_page_when_prometheus_metrics_are_disabled-35639.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/unreleased/pawel-show_empty_page_when_prometheus_metrics_are_disabled-35639.yml diff --git a/changelogs/unreleased/pawel-show_empty_page_when_prometheus_metrics_are_disabled-35639.yml b/changelogs/unreleased/pawel-show_empty_page_when_prometheus_metrics_are_disabled-35639.yml new file mode 100644 index 00000000000..987f7286244 --- /dev/null +++ b/changelogs/unreleased/pawel-show_empty_page_when_prometheus_metrics_are_disabled-35639.yml @@ -0,0 +1,5 @@ +--- +title: Make Prometheus metrics endpoint return empty response when metrics are disabled +merge_request: 14490 +author: +type: changed