Commit cc058de8 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'pawel/show_empty_page_when_prometheus_metrics_are_disabled-35639' into 'master'

Make Prometheus metrics endpoint return empty response when metrics are disabled

Closes #35639

See merge request gitlab-org/gitlab-ce!14490
parents c76426fc 05f41253
...@@ -3,10 +3,16 @@ class MetricsController < ActionController::Base ...@@ -3,10 +3,16 @@ class MetricsController < ActionController::Base
protect_from_forgery with: :exception protect_from_forgery with: :exception
before_action :validate_prometheus_metrics
def index 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 end
private private
...@@ -14,8 +20,4 @@ class MetricsController < ActionController::Base ...@@ -14,8 +20,4 @@ class MetricsController < ActionController::Base
def metrics_service def metrics_service
@metrics_service ||= MetricsService.new @metrics_service ||= MetricsService.new
end end
def validate_prometheus_metrics
render_404 unless Gitlab::Metrics.prometheus_metrics_enabled?
end
end end
---
title: Make Prometheus metrics endpoint return empty response when metrics are disabled
merge_request: 14490
author:
type: changed
...@@ -67,7 +67,8 @@ describe MetricsController do ...@@ -67,7 +67,8 @@ describe MetricsController do
it 'returns proper response' do it 'returns proper response' do
get :index 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 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