BigW Consortium Gitlab

Commit 62fe37e3 by Pawel Chojnacki

move check if metrics are enabled to before action

parent 21561f34
......@@ -3,6 +3,7 @@ require 'prometheus/client/formats/text'
class MetricsController < ActionController::Base
protect_from_forgery with: :exception
include RequiresHealthToken
before_action :ensure_prometheus_metrics_are_enabled
CHECKS = [
Gitlab::HealthChecks::DbCheck,
......@@ -10,9 +11,8 @@ class MetricsController < ActionController::Base
Gitlab::HealthChecks::FsShardsCheck
].freeze
def metrics
return render_404 unless Gitlab::Metrics.prometheus_metrics_enabled?
def metrics
metrics_text = Prometheus::Client::Formats::Text.marshal_multiprocess(multiprocess_metrics_path)
response = health_metrics_text + "\n" + metrics_text
......@@ -21,6 +21,10 @@ class MetricsController < ActionController::Base
private
def ensure_prometheus_metrics_are_enabled
return render_404 unless Gitlab::Metrics.prometheus_metrics_enabled?
end
def multiprocess_metrics_path
Rails.root.join(ENV['prometheus_multiproc_dir'])
end
......
......@@ -48,6 +48,15 @@ describe MetricsController do
expect(response.body).to match(/^filesystem_read_latency{shard="default"} [0-9\.]+$/)
expect(response.body).to match(/^filesystem_readable{shard="default"} 1$/)
end
context 'prometheus metrics are disabled' do
allow(Gitlab::Metrics).to receive(:prometheus_metrics_enabled?).and_return(false)
it 'returns proper response' do
get :metrics
expect(response.status).to eq(404)
end
end
end
context 'without authorization token' do
......@@ -56,5 +65,6 @@ describe MetricsController do
expect(response.status).to eq(404)
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