summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-06-06 14:40:03 +0200
committerPawel Chojnacki <pawel@chojnacki.ws>2017-06-06 14:40:03 +0200
commitc7a1da800ff6fa16db5de796a8f8d715ddd3b582 (patch)
tree3db1bd3488130c4fe3eacc9ce947dc7898c9f92f /app
parentc0a66dbd2dd8b716e809938d20e7655d84595176 (diff)
downloadgitlab-ce-c7a1da800ff6fa16db5de796a8f8d715ddd3b582.tar.gz
Explicitly require format.json in prometheus_controller
+ add missing prometheus_controller tests!
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/deployments_controller.rb5
-rw-r--r--app/controllers/projects/prometheus_controller.rb18
2 files changed, 16 insertions, 7 deletions
diff --git a/app/controllers/projects/deployments_controller.rb b/app/controllers/projects/deployments_controller.rb
index 29d94e2760a..acf5573935a 100644
--- a/app/controllers/projects/deployments_controller.rb
+++ b/app/controllers/projects/deployments_controller.rb
@@ -24,10 +24,11 @@ class Projects::DeploymentsController < Projects::ApplicationController
def additional_metrics
return render_404 unless deployment.has_additional_metrics?
+
metrics = deployment.additional_metrics
- if metrics&.any?
- render json: metrics, status: :ok
+ if metrics.any?
+ render json: metrics
else
head :no_content
end
diff --git a/app/controllers/projects/prometheus_controller.rb b/app/controllers/projects/prometheus_controller.rb
index 0402be6f85c..4a39d13881e 100644
--- a/app/controllers/projects/prometheus_controller.rb
+++ b/app/controllers/projects/prometheus_controller.rb
@@ -3,17 +3,25 @@ class Projects::PrometheusController < Projects::ApplicationController
before_action :require_prometheus_metrics!
def active_metrics
- matched_metrics = prometheus_service.reactive_query(Gitlab::Prometheus::Queries::MatchedMetricsQuery.name, &:itself)
+ matched_metrics = prometheus_service.reactive_query(Gitlab::Prometheus::Queries::MatchedMetricsQuery.name, &:itself) || {}
- if matched_metrics
- render json: matched_metrics, status: :ok
- else
- head :no_content
+ respond_to do |format|
+ format.json do
+ if matched_metrics.any?
+ render json: matched_metrics
+ else
+ head :no_content
+ end
+ end
end
end
private
+ rescue_from(ActionController::UnknownFormat) do |e|
+ render_404
+ end
+
def prometheus_service
project.monitoring_service
end