diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/deployments_controller.rb | 5 | ||||
-rw-r--r-- | app/controllers/projects/prometheus_controller.rb | 18 |
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 |