diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-05-25 17:19:54 +0300 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-05-25 17:19:54 +0300 |
commit | 4d8f3978a254f33d959de65dbf7b20a1d41a058d (patch) | |
tree | 246c4f498edecb71fb6c3a6a879844aa91456ce9 /app/controllers | |
parent | 61d7b7f117ff090f34f882918d55691575d76e55 (diff) |
Use before action to respond with 404 if prometheus metrics are missing
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/projects/prometheus_controller.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/app/controllers/projects/prometheus_controller.rb b/app/controllers/projects/prometheus_controller.rb index 74e247535d5..0402be6f85c 100644 --- a/app/controllers/projects/prometheus_controller.rb +++ b/app/controllers/projects/prometheus_controller.rb @@ -1,8 +1,8 @@ class Projects::PrometheusController < Projects::ApplicationController before_action :authorize_read_project! + before_action :require_prometheus_metrics! def active_metrics - return render_404 unless has_prometheus_metrics? matched_metrics = prometheus_service.reactive_query(Gitlab::Prometheus::Queries::MatchedMetricsQuery.name, &:itself) if matched_metrics @@ -12,6 +12,8 @@ class Projects::PrometheusController < Projects::ApplicationController end end + private + def prometheus_service project.monitoring_service end @@ -19,4 +21,8 @@ class Projects::PrometheusController < Projects::ApplicationController def has_prometheus_metrics? prometheus_service&.respond_to?(:reactive_query) end + + def require_prometheus_metrics! + render_404 unless has_prometheus_metrics? + end end |