gitlab-org--gitlab-foss/app/controllers/metrics_controller.rb
blackst0ne 6fef87f17f [Rails5] Force the protect_from_forgery callback run first
Since Rails 5.0 the `protect_from_forgery` callback doesn't run first by
default anymore. [1]

Instead it gets inserted into callbacks chain where callbacks get
called in order.

This commit forces the callback to run first.

[1]: 3979403781
2018-06-21 21:44:31 +11:00

24 lines
759 B
Ruby

class MetricsController < ActionController::Base
include RequiresWhitelistedMonitoringClient
protect_from_forgery with: :exception, prepend: true
def index
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
def metrics_service
@metrics_service ||= MetricsService.new
end
end