summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-11-06 17:02:22 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-11-06 17:02:22 +0000
commitcc058de8df718af1f1ed4f61677770d40df676ac (patch)
treea76274c0cb9f71d25eb5f7f28651f5bb59f8a42f
parentc76426fc640d1d214d78e343c463636dcf68fa6c (diff)
parent05f41253a9fb1ae88ecc53a1ceade780d1cfe0d4 (diff)
downloadgitlab-ce-cc058de8df718af1f1ed4f61677770d40df676ac.tar.gz
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
-rw-r--r--app/controllers/metrics_controller.rb16
-rw-r--r--changelogs/unreleased/pawel-show_empty_page_when_prometheus_metrics_are_disabled-35639.yml5
-rw-r--r--spec/controllers/metrics_controller_spec.rb3
3 files changed, 16 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/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
diff --git a/spec/controllers/metrics_controller_spec.rb b/spec/controllers/metrics_controller_spec.rb
index 4aed2a25baa..9e8a37171ec 100644
--- a/spec/controllers/metrics_controller_spec.rb
+++ b/spec/controllers/metrics_controller_spec.rb
@@ -67,7 +67,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