Commit c18be444 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'sy-correct-alert-id' into 'master'

Swap AlertsController#metrics_dashboard to use metric_id and env_id

See merge request gitlab-org/gitlab!24888
parents 75d757fe b178dceb
...@@ -14,7 +14,7 @@ module Projects ...@@ -14,7 +14,7 @@ module Projects
prepend_before_action :repository, :project_without_auth, only: [:notify] prepend_before_action :repository, :project_without_auth, only: [:notify]
before_action :authorize_read_prometheus_alerts!, except: [:notify] before_action :authorize_read_prometheus_alerts!, except: [:notify]
before_action :alert, only: [:update, :show, :destroy] before_action :alert, only: [:update, :show, :destroy, :metrics_dashboard]
def index def index
render json: serialize_as_json(alerts) render json: serialize_as_json(alerts)
...@@ -140,7 +140,7 @@ module Projects ...@@ -140,7 +140,7 @@ module Projects
def metrics_dashboard_params def metrics_dashboard_params
{ {
embedded: true, embedded: true,
prometheus_alert_id: params[:id].to_i prometheus_alert_id: alert.id
} }
end end
end end
......
...@@ -364,19 +364,33 @@ describe Projects::Prometheus::AlertsController do ...@@ -364,19 +364,33 @@ describe Projects::Prometheus::AlertsController do
end end
it 'returns a json object with the correct keys' do it 'returns a json object with the correct keys' do
get :metrics_dashboard, params: request_params(id: alert.id), format: :json get :metrics_dashboard, params: request_params(id: metric.id, environment_id: alert.environment.id), format: :json
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.keys).to contain_exactly('dashboard', 'status') expect(json_response.keys).to contain_exactly('dashboard', 'status')
end end
it 'is the correct embed' do it 'is the correct embed' do
get :metrics_dashboard, params: request_params(id: alert.id), format: :json get :metrics_dashboard, params: request_params(id: metric.id, environment_id: alert.environment.id), format: :json
title = json_response['dashboard']['panel_groups'][0]['panels'][0]['title'] title = json_response['dashboard']['panel_groups'][0]['panels'][0]['title']
expect(title).to eq(metric.title) expect(title).to eq(metric.title)
end end
it 'finds the first alert embed without environment_id' do
get :metrics_dashboard, params: request_params(id: metric.id), format: :json
title = json_response['dashboard']['panel_groups'][0]['panels'][0]['title']
expect(title).to eq(metric.title)
end
it 'returns 404 for non-existant alerts' do
get :metrics_dashboard, params: request_params(id: 0), format: :json
expect(response).to have_gitlab_http_status(:not_found)
end
end end
def project_params(opts = {}) def project_params(opts = {})
......
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