Commit 4407567a authored by Ryan Cobb's avatar Ryan Cobb

Create new metrics dashboard path

This creates a new project metrics dashboard path. This will be used for
shortening dashboard links for easier sharing.
parent 922f1c42
import monitoringApp from '~/monitoring/monitoring_app';
document.addEventListener('DOMContentLoaded', monitoringApp);
# frozen_string_literal: true
class Projects::MetricsDashboardController < Projects::ApplicationController
before_action :metrics_dashboard_page do
authorize_metrics_dashboard!
push_frontend_feature_flag(:prometheus_computed_alerts)
end
def metrics_dashboard_page
@environment = if metrics_dashboard_page_params[:environment]
project.environments.find(metrics_dashboard_page_params[:environment])
else
project.default_environment
end
if @environment
render 'projects/environments/metrics'
else
render_404
end
end
private
def metrics_dashboard_page_params
params.permit(:environment)
end
end
c4a8f7e42201fe775340d0ace9316657
\ No newline at end of file
......@@ -25,6 +25,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
# Use this scope for all new project routes.
scope '-' do
get 'archive/*id', constraints: { format: Gitlab::PathRegex.archive_formats_regex, id: /.+?/ }, to: 'repositories#archive', as: 'archive'
get 'd', to: 'metrics_dashboard#metrics_dashboard_page', as: :metrics_dashboard_page
resources :artifacts, only: [:index, :destroy]
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::MetricsDashboardController do
let_it_be(:project) { create(:project) }
let_it_be(:maintainer) { create(:user, name: 'main-dos').tap { |u| project.add_maintainer(u) } }
let(:user) { maintainer }
let!(:environment) { create(:environment, name: 'production', project: project) }
let!(:second_environment) { create(:environment, name: 'staging', project: project) }
before do
sign_in(user)
end
describe 'GET d' do
it 'responds with status code 200' do
get :metrics_dashboard_page, params: params
expect(response).to have_gitlab_http_status(:ok)
end
it 'assigns default environment' do
get :metrics_dashboard_page, params: params
expect(assigns(:environment).id).to eq(environment.id)
end
context 'with valid environment parameter' do
let(:valid_environment_params) { params(environment: second_environment.id) }
it 'responds with status code 200' do
get :metrics_dashboard_page, params: valid_environment_params
expect(response).to have_gitlab_http_status(:ok)
end
it 'assigns param environment' do
get :metrics_dashboard_page, params: valid_environment_params
expect(assigns(:environment).id).to eq(second_environment.id)
end
end
context 'with invalid environment parameter' do
let(:invalid_environment_params) { params(environment: 9999)}
it 'responds with 404' do
get :metrics_dashboard_page, params: invalid_environment_params
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'with custom dashboard path' do
it 'responds with status code 200' do
get :metrics_dashboard_page, params: params(dashboard_path: 'custom_dashboard_path.yml')
expect(response).to have_gitlab_http_status(:ok)
end
end
end
def params(opts = {})
opts.reverse_merge({
namespace_id: project.namespace,
project_id: project
})
end
end
# frozen_string_literal: true
require 'spec_helper'
describe 'metrics dashboard page' do
# Further tests can be found at metrics_dashboard_controller_spec.rb
let(:project) { create(:project) }
let!(:environment) { create(:environment, project: project) }
let!(:environment2) { create(:environment, project: project) }
let(:user) { project.owner }
before do
project.add_developer(user)
login_as(user)
end
describe 'GET /:namespace/:project/-/d' do
it 'returns 200' do
send_request
expect(response).to have_gitlab_http_status(:ok)
end
it 'assigns environment' do
send_request
expect(assigns(:environment).id).to eq(environment.id)
end
end
describe 'GET /:namespace/:project/-/d?environment=:environment.id' do
it 'returns 200' do
send_request(environment: environment2.id)
expect(response).to have_gitlab_http_status(:ok)
end
it 'assigns query param environment' do
send_request(environment: environment2.id)
expect(assigns(:environment).id).to eq(environment2.id)
end
context 'when query param environment does not exist' do
it 'responds with 404' do
send_request(environment: 99)
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
describe 'GET /:namespace/:project/-d/:dashboard_path' do
let(:dashboard_path) { '.gitlab/dashboards/dashboard_path.yml' }
it 'returns 200' do
send_request(dashboard: dashboard_path)
expect(response).to have_gitlab_http_status(:ok)
end
it 'assigns environment0' do
send_request(dashboard: dashboard_path)
expect(assigns(:environment).id).to eq(environment.id)
end
end
describe 'GET :/namespace/:project/-d/:dashboard_path?environment=:environment.id' do
let(:dashboard_path) { '.gitlab/dashboards/dashboard_path.yml' }
it 'returns 200' do
send_request(dahboard: dashboard_path, environment: environment.id)
expect(response).to have_gitlab_http_status(:ok)
end
it 'assigns query param environment' do
send_request(dashboard: dashboard_path, environment: environment2.id)
expect(assigns(:environment).id).to eq(environment2.id)
end
context 'when query param environment does not exist' do
it 'responds with 404' do
send_request(dashboard: dashboard_path, environment: 99)
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
def send_request(params = {})
get namespace_project_metrics_dashboard_page_path(namespace_id: project.namespace, project_id: project, **params)
end
end
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