Make Prometheus metrics endpoint return empty response when metrics are disabled
This commit is contained in:
parent
b83dcd3a30
commit
1ea2a85cbe
2 changed files with 11 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue