Commit 638869fa authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'rc/redirect_to_new_metrics_page' into 'master'

Redirect to new metrics dashboard page

See merge request gitlab-org/gitlab!38364
parents bb83206c 28e612cb
...@@ -161,18 +161,14 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -161,18 +161,14 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end end
def metrics_redirect def metrics_redirect
environment = project.default_environment redirect_to project_metrics_dashboard_path(project)
if environment
redirect_to environment_metrics_path(environment)
else
render :empty_metrics
end
end end
def metrics def metrics
respond_to do |format| respond_to do |format|
format.html format.html do
redirect_to project_metrics_dashboard_path(project, environment: environment )
end
format.json do format.json do
# Currently, this acts as a hint to load the metrics details into the cache # Currently, this acts as a hint to load the metrics details into the cache
# if they aren't there already # if they aren't there already
......
...@@ -22,7 +22,7 @@ module Projects ...@@ -22,7 +22,7 @@ module Projects
if environment if environment
render 'projects/environments/metrics' render 'projects/environments/metrics'
else else
render_404 render 'projects/environments/empty_metrics'
end end
end end
......
...@@ -748,6 +748,7 @@ module ProjectsHelper ...@@ -748,6 +748,7 @@ module ProjectsHelper
gcp gcp
logs logs
product_analytics product_analytics
metrics_dashboard
] ]
end end
......
...@@ -223,8 +223,8 @@ ...@@ -223,8 +223,8 @@
%li.divider.fly-out-top-item %li.divider.fly-out-top-item
- if project_nav_tab? :metrics_dashboards - if project_nav_tab? :metrics_dashboards
= nav_link(controller: :environments, action: [:metrics, :metrics_redirect]) do = nav_link(controller: :metrics_dashboard, action: [:show]) do
= link_to metrics_project_environments_path(@project), title: _('Metrics'), class: 'shortcuts-metrics', data: { qa_selector: 'operations_metrics_link' } do = link_to project_metrics_dashboard_path(@project), title: _('Metrics'), class: 'shortcuts-metrics', data: { qa_selector: 'operations_metrics_link' } do
%span %span
= _('Metrics') = _('Metrics')
......
---
title: Redirect to new metrics dashboard page
merge_request: 38364
author:
type: added
...@@ -348,34 +348,10 @@ RSpec.describe Projects::EnvironmentsController do ...@@ -348,34 +348,10 @@ RSpec.describe Projects::EnvironmentsController do
end end
describe 'GET #metrics_redirect' do describe 'GET #metrics_redirect' do
it 'redirects to environment if it exists' do it 'redirects to metrics dashboard page' do
get :metrics_redirect, params: { namespace_id: project.namespace, project_id: project } get :metrics_redirect, params: { namespace_id: project.namespace, project_id: project }
expect(response).to redirect_to(environment_metrics_path(environment)) expect(response).to redirect_to(project_metrics_dashboard_path(project))
end
context 'with anonymous user and public dashboard visibility' do
let(:project) { create(:project, :public) }
let(:user) { create(:user) }
it 'redirects successfully' do
project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::ENABLED)
get :metrics_redirect, params: { namespace_id: project.namespace, project_id: project }
expect(response).to redirect_to(environment_metrics_path(environment))
end
end
context 'when there are no environments' do
let(:environment) { }
it 'redirects to empty metrics page' do
get :metrics_redirect, params: { namespace_id: project.namespace, project_id: project }
expect(response).to be_ok
expect(response).to render_template 'empty_metrics'
end
end end
end end
...@@ -385,12 +361,12 @@ RSpec.describe Projects::EnvironmentsController do ...@@ -385,12 +361,12 @@ RSpec.describe Projects::EnvironmentsController do
end end
context 'when environment has no metrics' do context 'when environment has no metrics' do
it 'returns a metrics page' do it 'redirects to metrics dashboard page' do
expect(environment).not_to receive(:metrics) expect(environment).not_to receive(:metrics)
get :metrics, params: environment_params get :metrics, params: environment_params
expect(response).to be_ok expect(response).to redirect_to(project_metrics_dashboard_path(project, environment: environment))
end end
context 'when requesting metrics as JSON' do context 'when requesting metrics as JSON' do
...@@ -440,12 +416,12 @@ RSpec.describe Projects::EnvironmentsController do ...@@ -440,12 +416,12 @@ RSpec.describe Projects::EnvironmentsController do
let(:project) { create(:project, :public) } let(:project) { create(:project, :public) }
let(:user) { create(:user) } let(:user) { create(:user) }
it 'returns success' do it 'redirects to metrics dashboard page' do
project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::ENABLED) project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::ENABLED)
get :metrics, params: environment_params get :metrics, params: environment_params
expect(response).to have_gitlab_http_status(:ok) expect(response).to redirect_to(project_metrics_dashboard_path(project, environment: environment))
end end
end end
end end
......
...@@ -28,9 +28,8 @@ RSpec.describe 'Environment > Metrics' do ...@@ -28,9 +28,8 @@ RSpec.describe 'Environment > Metrics' do
shared_examples 'has environment selector' do shared_examples 'has environment selector' do
it 'has a working environment selector', :js do it 'has a working environment selector', :js do
click_link('See metrics') click_link('See metrics')
# TODO: See metrics on the sidebar still points to the old metrics URL
# https://gitlab.com/gitlab-org/gitlab/-/issues/229277 expect(page).to have_current_path(project_metrics_dashboard_path(project, environment: environment.id))
expect(page).to have_current_path(metrics_project_environment_path(project, id: environment.id))
expect(page).to have_css('[data-qa-selector="environments_dropdown"]') expect(page).to have_css('[data-qa-selector="environments_dropdown"]')
within('[data-qa-selector="environments_dropdown"]') do within('[data-qa-selector="environments_dropdown"]') do
......
...@@ -23,6 +23,22 @@ RSpec.describe 'metrics dashboard page' do ...@@ -23,6 +23,22 @@ RSpec.describe 'metrics dashboard page' do
send_request send_request
expect(assigns(:environment).id).to eq(environment.id) expect(assigns(:environment).id).to eq(environment.id)
end end
context 'with anonymous user and public dashboard visibility' do
let(:anonymous_user) { create(:user) }
let(:project) do
create(:project, :public, metrics_dashboard_access_level: 'enabled')
end
before do
login_as(anonymous_user)
end
it 'returns 200' do
send_request
expect(response).to have_gitlab_http_status(:ok)
end
end
end end
describe 'GET /:namespace/:project/-/metrics?environment=:environment.id' do describe 'GET /:namespace/:project/-/metrics?environment=:environment.id' do
......
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